1 4 package org.jfox.jms; 5 6 import javax.jms.Connection ; 7 import javax.jms.Message ; 8 import javax.jms.MessageListener ; 9 import javax.jms.Queue ; 10 import javax.jms.QueueReceiver ; 11 import javax.jms.Session ; 12 import javax.naming.InitialContext ; 13 14 17 18 public class JMSAsyncConsumerTest{ 19 JMSConnectionFactory jmsConnectionFactory; 20 Connection conn; 21 Session session; 22 Queue queue; 23 QueueReceiver queueReceiver; 24 25 26 27 public void setUp() throws Exception { 28 InitialContext ctx = new InitialContext (); 29 Object cf = ctx.lookup("jms/defaultcf"); 30 jmsConnectionFactory = (JMSConnectionFactory) javax.rmi.PortableRemoteObject.narrow(cf, JMSConnectionFactory.class); 31 queue = (Queue )javax.rmi.PortableRemoteObject.narrow(ctx.lookup("jms/defaultQ1"),Queue .class); 32 33 conn = jmsConnectionFactory.createConnection(); 34 session = conn.createSession(false,Session.AUTO_ACKNOWLEDGE); 35 queueReceiver = (QueueReceiver )session.createConsumer(queue); 36 queueReceiver.setMessageListener(new MessageListener (){ 37 public void onMessage(Message message) { 38 System.out.println("QueueReceive Message: " + message); 39 } 40 }); 41 conn.start(); 42 } 43 44 45 46 public static void main(String [] args) throws Exception { 47 JMSAsyncConsumerTest test = new JMSAsyncConsumerTest(); 48 test.setUp(); 49 } 50 } 51 52 | Popular Tags |