1 24 package archi; 25 26 import javax.jms.*; 27 import javax.naming.*; 28 29 public class Receiver 30 { 31 static Context ictx = null; 32 33 public static void main (String argv[]) throws Exception 34 { 35 System.out.println(); 36 System.out.println("Requests to receive messages..."); 37 38 ictx = new InitialContext(); 39 ConnectionFactory cnxF = (ConnectionFactory) ictx.lookup("cf2"); 40 Queue dest = (Queue) ictx.lookup("queue"); 41 ictx.close(); 42 43 Connection cnx = cnxF.createConnection(); 44 Session session = cnx.createSession(true, 0); 45 MessageConsumer rec = session.createConsumer(dest); 46 47 cnx.start(); 48 49 Message msg; 50 int i; 51 for (i = 0; i < 10; i++) { 52 msg = rec.receive(); 53 54 if (msg instanceof TextMessage) 55 System.out.println("Msg: " + ((TextMessage) msg).getText()); 56 } 57 58 System.out.println(); 59 System.out.println(i + " messages received."); 60 61 session.commit(); 62 cnx.close(); 63 } 64 } 65 | Popular Tags |