1 24 package classic; 25 26 import javax.jms.*; 27 import javax.naming.*; 28 29 32 public class Browser 33 { 34 static Context ictx = null; 35 36 public static void main(String [] args) throws Exception 37 { 38 System.out.println(); 39 System.out.println("Browses the queue: "); 40 41 ictx = new InitialContext(); 42 Queue queue = (Queue) ictx.lookup("queue"); 43 QueueConnectionFactory qcf = (QueueConnectionFactory) ictx.lookup("qcf"); 44 ictx.close(); 45 46 QueueConnection qc = qcf.createQueueConnection(); 47 QueueSession qs = qc.createQueueSession(true, 0); 48 QueueBrowser browser = qs.createBrowser(queue); 49 50 java.util.Enumeration messages = browser.getEnumeration(); 51 52 Message msg; 53 54 while (messages.hasMoreElements()) { 55 msg = (Message) messages.nextElement(); 56 57 if (msg instanceof TextMessage) 58 System.out.println(((TextMessage) msg).getText()); 59 } 60 61 System.out.println(); 62 System.out.println("Queue browsed."); 63 64 qc.close(); 65 } 66 } 67 | Popular Tags |