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.MessageProducer ; 32 import javax.jms.TextMessage ; 33 34 public class Publisher { 35 36 public static void main(String [] arg) throws Exception { 37 System.out.println(); 38 System.out.println("Publishes messages on topic..."); 39 40 javax.jms.TopicConnectionFactory tcf = 42 TopicHATcpConnectionFactory.create("hajoram://localhost:2560,localhost:2561,localhost:2562"); 43 ((ConnectionFactory) tcf).getParameters().connectingTimer = 30; 44 45 AdminModule.connect(tcf, "root", "root"); 46 47 Topic topic = Topic.create(0,"topic"); 48 49 AdminModule.disconnect(); 50 51 52 Connection cnx = tcf.createConnection("anonymous", "anonymous"); 53 Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE); 54 MessageProducer pub = sess.createProducer(topic); 55 56 TextMessage msg = sess.createTextMessage(); 57 58 int i; 59 for (i = 0; i < 1000; i++) { 60 msg.setText("Msg " + i); 61 pub.send(msg); 62 Thread.sleep(250L); 63 System.out.println("publish message " + i); 64 } 65 } 66 } 67 | Popular Tags |