KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bridge > ForeignPublisher


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 ForeignPublisher {
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 foreignDest = (Destination JavaDoc) jndiCtx.lookup("foreignTopic");
39     ConnectionFactory JavaDoc foreignCF = (ConnectionFactory JavaDoc) jndiCtx.lookup("foreignCF");
40     jndiCtx.close();
41
42     Connection JavaDoc foreignCnx = foreignCF.createConnection();
43     Session JavaDoc foreignSess = foreignCnx.createSession(true, 0);
44     MessageProducer JavaDoc foreignSender = foreignSess.createProducer(foreignDest);
45
46     TextMessage JavaDoc foreignMsg = foreignSess.createTextMessage();
47
48     for (int i = 1; i < 11; i++) {
49       foreignMsg.setText("topic Foreign message number " + i);
50       System.out.println("send msg = " + foreignMsg.getText());
51       foreignSender.send(foreignMsg);
52     }
53
54     foreignSess.commit();
55     
56     
57     foreignCnx.close();
58   }
59 }
60
Popular Tags