1 9 package org.jboss.resource.adapter.jms; 10 11 import javax.jms.Session ; 12 import javax.jms.TextMessage ; 13 import javax.jms.Topic ; 14 import javax.jms.TopicConnection ; 15 import javax.jms.TopicPublisher ; 16 import javax.jms.TopicSession ; 17 import javax.naming.InitialContext ; 18 19 import org.jboss.jms.jndi.JNDIProviderAdapter; 20 21 29 public class TestClient 30 { 31 public TestClient() 32 { 33 } 35 36 public static void main(String [] args) 37 { 38 try 39 { 40 JmsManagedConnectionFactory f = new JmsManagedConnectionFactory(); 41 f.setJmsProviderAdapter(new JNDIProviderAdapter()); 42 JmsConnectionFactory cf = (JmsConnectionFactory) f.createConnectionFactory(); 44 TopicConnection con = cf.createTopicConnection(); 46 TopicSession ses = con.createTopicSession(true, Session.AUTO_ACKNOWLEDGE); 47 Topic topic = (Topic ) new InitialContext ().lookup("topic/testTopic"); 48 TopicPublisher pub = ses.createPublisher(topic); 49 TextMessage m = ses.createTextMessage("Hello world!"); 50 pub.publish(m); 51 ses.commit(); 52 ses.close(); 53 } 54 catch (Exception ex) 55 { 56 System.err.println("Error: " + ex); 57 ex.printStackTrace(); 58 } 59 } 60 } | Popular Tags |