KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > adapter > jms > TestClient


1 /***************************************
2  * *
3  * JBoss: The OpenSource J2EE WebOS *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  ***************************************/

9 package org.jboss.resource.adapter.jms;
10
11 import javax.jms.Session JavaDoc;
12 import javax.jms.TextMessage JavaDoc;
13 import javax.jms.Topic JavaDoc;
14 import javax.jms.TopicConnection JavaDoc;
15 import javax.jms.TopicPublisher JavaDoc;
16 import javax.jms.TopicSession JavaDoc;
17 import javax.naming.InitialContext JavaDoc;
18
19 import org.jboss.jms.jndi.JNDIProviderAdapter;
20
21 /**
22  * TestClient for stand alone use. Basically verry uninteresting.
23  *
24  * Created: Sun Apr 22 19:10:27 2001
25  *
26  * @author <a HREF="mailto:peter.antman@tim.se">Peter Antman</a>.
27  * @version $Revision: 1.4 $
28  */

29 public class TestClient
30 {
31    public TestClient()
32    {
33       // empty
34
}
35
36    public static void main(String JavaDoc[] args)
37    {
38       try
39       {
40          JmsManagedConnectionFactory f = new JmsManagedConnectionFactory();
41          f.setJmsProviderAdapter(new JNDIProviderAdapter());
42          //f.setLogging("true");
43
JmsConnectionFactory cf = (JmsConnectionFactory) f.createConnectionFactory();
44          //FIXME - how to get LocalTransaction for standalone usage?
45
TopicConnection JavaDoc con = cf.createTopicConnection();
46          TopicSession JavaDoc ses = con.createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
47          Topic JavaDoc topic = (Topic JavaDoc) new InitialContext JavaDoc().lookup("topic/testTopic");
48          TopicPublisher JavaDoc pub = ses.createPublisher(topic);
49          TextMessage JavaDoc m = ses.createTextMessage("Hello world!");
50          pub.publish(m);
51          ses.commit();
52          ses.close();
53       }
54       catch (Exception JavaDoc ex)
55       {
56          System.err.println("Error: " + ex);
57          ex.printStackTrace();
58       }
59    }
60 }
Popular Tags