KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ha > Subscriber


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.MessageConsumer JavaDoc;
32 import javax.jms.TextMessage JavaDoc;
33 import javax.jms.TopicConnectionFactory JavaDoc;
34
35 public class Subscriber {
36
37   public static void main(String JavaDoc[] args)
38     throws Exception JavaDoc {
39     System.out.println();
40     System.out.println("Subscribes and listens to topic...");
41
42     // use joram Admin insteadof Jndi.
43
TopicConnectionFactory JavaDoc 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 JavaDoc cnx = tcf.createConnection("anonymous", "anonymous");
54     Session JavaDoc sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
55     MessageConsumer JavaDoc 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