KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ha > Publisher


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2005 - ScalAgent Distributed Technologies
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): Nicolas Tachker (ScalAgent)
21  * Contributor(s):
22  */

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 JavaDoc;
30 import javax.jms.Session JavaDoc;
31 import javax.jms.MessageProducer JavaDoc;
32 import javax.jms.TextMessage JavaDoc;
33
34 public class Publisher {
35
36   public static void main(String JavaDoc[] arg) throws Exception JavaDoc {
37     System.out.println();
38     System.out.println("Publishes messages on topic...");
39
40     // use joram Admin insteadof Jndi.
41
javax.jms.TopicConnectionFactory JavaDoc 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 JavaDoc cnx = tcf.createConnection("anonymous", "anonymous");
53     Session JavaDoc sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
54     MessageProducer JavaDoc pub = sess.createProducer(topic);
55
56     TextMessage JavaDoc 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