KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > deadMQueue > DMQClient


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - Dyade
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): Frederic Maistre (INRIA)
22  * Contributor(s):
23  */

24 package deadMQueue;
25
26 import org.objectweb.joram.client.jms.admin.*;
27
28 import javax.jms.*;
29 import javax.naming.*;
30
31 /**
32  * Producer/Consumer generating dead messages.
33  */

34 public class DMQClient
35 {
36   static Context ictx = null;
37
38   public static void main(String JavaDoc[] args) throws Exception JavaDoc
39   {
40     ictx = new InitialContext();
41     Queue queue = (Queue) ictx.lookup("queue");
42     Topic topic = (Topic) ictx.lookup("topic");
43     ConnectionFactory cf = (ConnectionFactory) ictx.lookup("cnxFact");
44     ictx.close();
45
46     Connection cnx = cf.createConnection();
47     Session prodSession = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
48     Session consSession = cnx.createSession(true, 0);
49     MessageProducer qProducer = prodSession.createProducer(queue);
50     MessageProducer tProducer = prodSession.createProducer(topic);
51     
52     MessageConsumer qConsumer = consSession.createConsumer(queue);
53     MessageConsumer tConsumer = consSession.createConsumer(topic);
54
55     cnx.start();
56
57     TextMessage msg = prodSession.createTextMessage();
58
59     // Producing expired messages:
60
msg.setText("Expiry test");
61     qProducer.send(msg, javax.jms.DeliveryMode.NON_PERSISTENT, 4, 1);
62     tProducer.send(msg, javax.jms.DeliveryMode.NON_PERSISTENT, 4, 1);
63
64     qConsumer.receiveNoWait();
65     tConsumer.receiveNoWait();
66
67     // Producing "undeliverable" messages:
68
msg.setText("Undeliverability test");
69     qProducer.send(msg);
70     tProducer.send(msg);
71     qConsumer.receive();
72     tConsumer.receive();
73     consSession.rollback();
74     qConsumer.receive();
75     tConsumer.receive();
76     consSession.rollback();
77
78     cnx.close();
79   }
80 }
81
Popular Tags