KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bridge > BridgeProducer


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

23 package bridge;
24
25 import javax.jms.Connection JavaDoc;
26 import javax.jms.ConnectionFactory JavaDoc;
27 import javax.jms.Destination JavaDoc;
28 import javax.jms.MessageProducer JavaDoc;
29 import javax.jms.Session JavaDoc;
30 import javax.jms.TextMessage JavaDoc;
31
32 /**
33  * Produces messages on the foreign destination.
34  */

35 public class BridgeProducer {
36   public static void main(String JavaDoc[] args) throws Exception JavaDoc {
37     javax.naming.Context JavaDoc jndiCtx = new javax.naming.InitialContext JavaDoc();
38     Destination JavaDoc joramDest = (Destination JavaDoc) jndiCtx.lookup("joramTopic");
39     ConnectionFactory JavaDoc joramCF = (ConnectionFactory JavaDoc) jndiCtx.lookup("joramCF");
40     jndiCtx.close();
41
42     Connection JavaDoc joramCnx = joramCF.createConnection();
43     Session JavaDoc joramSess = joramCnx.createSession(true, 0);
44     MessageProducer JavaDoc joramSender = joramSess.createProducer(joramDest);
45
46     TextMessage JavaDoc msg = joramSess.createTextMessage();
47
48     for (int i = 1; i < 11; i++) {
49       msg.setText("Joram message number " + i);
50       System.out.println("send msg = " + msg.getText());
51       joramSender.send(msg);
52     }
53
54     joramSess.commit();
55
56     joramCnx.close();
57   }
58 }
59
Popular Tags