01: /*
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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): ____________________________________.
22: * Contributor(s): ______________________________________.
23: *
24: * --------------------------------------------------------------------------
25: * $Id: MdbClient.java 8313 2006-05-02 12:40:35Z braeuney $
26: * --------------------------------------------------------------------------
27: */
28:
29: // MdbClient.java
30: // mini Client for accessing bean Mdb
31: package newsamplemdb2;
32:
33: import javax.naming.Context;
34: import javax.naming.InitialContext;
35: import javax.naming.*;
36: import javax.jms.*;
37:
38: /**
39: *
40: */
41: public class MdbClient {
42:
43: static Context ictx = null;
44: static QueueConnectionFactory qcf = null;
45: static QueueSender qp = null;
46: static Queue queue = null;
47: // JNDI name of the Queue
48: static String queueName = "mdbQueue";
49: // JNDI name of the default connection factory
50: static String conFactName = "JQCF";
51:
52: public static void main(String[] arg) {
53: // Get InitialContext
54: try {
55: ictx = new InitialContext();
56: // lookup the QueueConnectionFactory through its JNDI name
57: qcf = (QueueConnectionFactory) ictx.lookup(conFactName);
58: System.out.println("JMS client: qcf = " + qcf);
59: // lookup the Queue through its JNDI name
60: queue = (Queue) ictx.lookup(queueName);
61: System.out.println("JMS client: queue = " + queue);
62: } catch (NamingException e) {
63: e.printStackTrace();
64: System.exit(2);
65: }
66:
67: QueueConnection qc = null;
68: QueueSession session = null;
69: try {
70: qc = qcf.createQueueConnection();
71: System.out.println("JMS client: qc = " + qc.toString());
72: session = qc.createQueueSession(false,
73: Session.AUTO_ACKNOWLEDGE);
74: qp = session.createSender(queue);
75: } catch (Exception e) {
76: e.printStackTrace();
77: System.exit(2);
78: }
79:
80: // publish 10 messages to the queue
81: int nbmess = 10;
82: try {
83: TextMessage message;
84: for (int i = 0; i < nbmess; i++) {
85: message = session.createTextMessage();
86: message.setText("Message" + i);
87: qp.send(message);
88:
89: }
90: session.close();
91: qc.close();
92: } catch (Exception e) {
93: e.printStackTrace();
94: System.exit(2);
95: }
96: System.out.println("MDBsample is Ok");
97: }
98: }
|