1 4 package org.jfox.jms; 5 6 import javax.jms.Connection ; 7 import javax.jms.Queue ; 8 import javax.jms.QueueReceiver ; 9 import javax.jms.Session ; 10 import javax.jms.TextMessage ; 11 import javax.naming.InitialContext ; 12 13 import junit.framework.TestCase; 14 15 18 19 public class JMSConsumerTest extends TestCase { 20 JMSConnectionFactory jmsConnectionFactory; 21 Connection conn; 22 Session session; 23 Queue queue; 24 QueueReceiver queueReceiver; 25 26 public void setUp() throws Exception { 27 super.setUp(); 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 conn.start(); 35 session = conn.createSession(false,Session.AUTO_ACKNOWLEDGE); 36 queueReceiver = (QueueReceiver )session.createConsumer(queue); 37 } 38 39 public void testQueueReceive(){ 40 try { 41 TextMessage message = (TextMessage )queueReceiver.receive(); 42 System.out.println("QueueReceive Message: " + message); 43 } 44 catch(Exception e){ 45 e.printStackTrace(); 46 fail(e.getMessage()); 47 } 48 } 49 50 public static void main(String [] args) { 51 52 } 53 } 54 55 | Popular Tags |