1 24 package cluster.topic; 25 26 import javax.jms.*; 27 import javax.naming.*; 28 29 public class Subscriber21 30 { 31 static Context ictx = null; 32 33 public static void main(String [] args) throws Exception 34 { 35 System.out.println(); 36 System.out.println("Subscribes and listens to topic on server2..."); 37 38 ictx = new InitialContext(); 39 ConnectionFactory cnxF = (ConnectionFactory) ictx.lookup("cf2"); 40 Topic dest = (Topic) ictx.lookup("top2"); 41 ictx.close(); 42 43 Connection cnx = cnxF.createConnection("subscriber21", "subscriber21"); 44 Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE); 45 MessageConsumer sub = sess.createConsumer(dest); 46 47 sub.setMessageListener(new Listener()); 48 49 cnx.start(); 50 51 System.in.read(); 52 cnx.close(); 53 54 System.out.println(); 55 System.out.println("Subscriber closed."); 56 } 57 } 58 | Popular Tags |