KickJava   Java API By Example, From Geeks To Geeks.

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


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.Message JavaDoc;
8 import javax.jms.MessageListener JavaDoc;
9 import javax.jms.Queue JavaDoc;
10 import javax.jms.QueueReceiver JavaDoc;
11 import javax.jms.Session JavaDoc;
12 import javax.naming.InitialContext JavaDoc;
13
14 /**
15  * @author <a HREF="mailto:yy.young@gmail.com">Young Yang</a>
16  */

17
18 public class JMSAsyncConsumerTest{
19     JMSConnectionFactory jmsConnectionFactory;
20     Connection JavaDoc conn;
21     Session JavaDoc session;
22     Queue JavaDoc queue;
23     QueueReceiver JavaDoc queueReceiver;
24
25
26
27     public void setUp() throws Exception JavaDoc {
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         session = conn.createSession(false,Session.AUTO_ACKNOWLEDGE);
35         queueReceiver = (QueueReceiver JavaDoc)session.createConsumer(queue);
36         queueReceiver.setMessageListener(new MessageListener JavaDoc(){
37             public void onMessage(Message JavaDoc message) {
38                 System.out.println("QueueReceive Message: " + message);
39             }
40         });
41         conn.start();
42     }
43
44
45
46     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
47         JMSAsyncConsumerTest test = new JMSAsyncConsumerTest();
48         test.setUp();
49     }
50 }
51
52
Popular Tags