KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > jms > JMSConsumerTest


1 /*
2  * Copyright (c) 2004 Your Corporation. All Rights Reserved.
3  */

4 package org.jfox.jms;
5
6 import javax.jms.Connection JavaDoc;
7 import javax.jms.Queue JavaDoc;
8 import javax.jms.QueueReceiver JavaDoc;
9 import javax.jms.Session JavaDoc;
10 import javax.jms.TextMessage JavaDoc;
11 import javax.naming.InitialContext JavaDoc;
12
13 import junit.framework.TestCase;
14
15 /**
16  * @author <a HREF="mailto:yy.young@gmail.com">Young Yang</a>
17  */

18
19 public class JMSConsumerTest extends TestCase {
20     JMSConnectionFactory jmsConnectionFactory;
21     Connection JavaDoc conn;
22     Session JavaDoc session;
23     Queue JavaDoc queue;
24     QueueReceiver JavaDoc queueReceiver;
25
26     public void setUp() throws Exception JavaDoc {
27         super.setUp();
28         InitialContext JavaDoc ctx = new InitialContext JavaDoc();
29         Object JavaDoc cf = ctx.lookup("jms/defaultcf");
30         jmsConnectionFactory = (JMSConnectionFactory) javax.rmi.PortableRemoteObject.narrow(cf, JMSConnectionFactory.class);
31         queue = (Queue JavaDoc)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("jms/defaultQ1"),Queue JavaDoc.class);
32
33         conn = jmsConnectionFactory.createConnection();
34         conn.start();
35         session = conn.createSession(false,Session.AUTO_ACKNOWLEDGE);
36         queueReceiver = (QueueReceiver JavaDoc)session.createConsumer(queue);
37     }
38
39     public void testQueueReceive(){
40         try {
41             TextMessage JavaDoc message = (TextMessage JavaDoc)queueReceiver.receive();
42             System.out.println("QueueReceive Message: " + message);
43         }
44         catch(Exception JavaDoc e){
45             e.printStackTrace();
46             fail(e.getMessage());
47         }
48     }
49
50     public static void main(String JavaDoc[] args) {
51
52     }
53 }
54
55
Popular Tags