1 23 package ha; 24 25 import org.objectweb.joram.client.jms.admin.*; 26 import org.objectweb.joram.client.jms.ha.tcp.TopicHATcpConnectionFactory; 27 import org.objectweb.joram.client.jms.ConnectionFactory; 28 import org.objectweb.joram.client.jms.Topic; 29 import javax.jms.Connection ; 30 import javax.jms.Session ; 31 import javax.jms.MessageConsumer ; 32 import javax.jms.TextMessage ; 33 import javax.jms.TopicConnectionFactory ; 34 35 public class Subscriber { 36 37 public static void main(String [] args) 38 throws Exception { 39 System.out.println(); 40 System.out.println("Subscribes and listens to topic..."); 41 42 TopicConnectionFactory tcf = 44 TopicHATcpConnectionFactory.create("hajoram://localhost:2560,localhost:2561,localhost:2562"); 45 ((ConnectionFactory)tcf).getParameters().connectingTimer = 30; 46 47 AdminModule.connect(tcf, "root", "root"); 48 49 Topic topic = Topic.create(0,"topic"); 50 51 AdminModule.disconnect(); 52 53 Connection cnx = tcf.createConnection("anonymous", "anonymous"); 54 Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE); 55 MessageConsumer sub = sess.createConsumer(topic); 56 57 sub.setMessageListener(new Listener()); 58 59 cnx.start(); 60 61 System.in.read(); 62 63 System.out.println(); 64 System.out.println("Subscriber closed."); 65 } 66 } 67 | Popular Tags |