Commit d26f9843 authored by afreyssin's avatar afreyssin
Browse files

Now the JMS bridge sample use the classic sample as foreign JMS provider.

No longer use XA mode in this sample.
parent 24b8105d
......@@ -24,6 +24,8 @@ package bridge;
import java.util.Properties;
import javax.jms.ConnectionFactory;
import org.objectweb.joram.client.jms.Queue;
import org.objectweb.joram.client.jms.Topic;
import org.objectweb.joram.client.jms.admin.AdminModule;
......@@ -39,69 +41,46 @@ public class BridgeAdmin {
System.out.println();
System.out.println("Bridge administration...");
AdminModule.connect("root", "root", 60);
javax.naming.Context jndiCtx = new javax.naming.InitialContext();
User.create("anonymous", "anonymous", 0);
User.create("anonymous", "anonymous", 1);
// create The foreign destination and connectionFactory
Queue foreignQueue = Queue.create(1, "foreignQueue");
foreignQueue.setFreeReading();
foreignQueue.setFreeWriting();
System.out.println("foreign queue = " + foreignQueue);
Topic foreignTopic = Topic.create(1, "foreignTopic");
foreignTopic.setFreeReading();
foreignTopic.setFreeWriting();
System.out.println("foreign topic = " + foreignTopic);
javax.jms.ConnectionFactory foreignCF = TcpConnectionFactory.create("localhost", 16011);
// bind foreign destination and connectionFactory
jndiCtx.rebind("foreignQueue", foreignQueue);
jndiCtx.rebind("foreignTopic", foreignTopic);
jndiCtx.rebind("foreignCF", foreignCF);
ConnectionFactory bridgeCF = TcpConnectionFactory.create("localhost", 16011);
AdminModule.connect(bridgeCF, "root", "root");
// Setting the bridge properties
Properties prop = new Properties();
// Foreign QueueConnectionFactory JNDI name: foreignCF
prop.setProperty("connectionFactoryName", "foreignCF");
// Foreign Queue JNDI name: foreignDest
prop.setProperty("destinationName", "foreignQueue");
// automaticRequest
prop.setProperty("automaticRequest", "false");
User.create("anonymous", "anonymous");
// Setting the bridge queue properties
Properties prop = new Properties();
prop.setProperty("jndiFactory", "fr.dyade.aaa.jndi2.client.NamingContextFactory");
prop.setProperty("jndiUrl", "scn://localhost:16400");
prop.setProperty("connectionFactoryName", "cf"); // Foreign QueueConnectionFactory JNDI name
prop.setProperty("destinationName", "queue"); // Foreign Queue JNDI name: foreignDest
prop.setProperty("automaticRequest", "false"); // automaticRequest
// Creating a Queue bridge on server 0:
Queue joramQueue = Queue.create(0,
Queue bridgeQueue = Queue.create(1,
"org.objectweb.joram.mom.dest.jmsbridge.JMSBridgeQueue",
prop);
joramQueue.setFreeReading();
joramQueue.setFreeWriting();
System.out.println("joram queue = " + joramQueue);
bridgeQueue.setFreeReading();
bridgeQueue.setFreeWriting();
System.out.println("joram queue = " + bridgeQueue);
// Setting the bridge properties
// Setting the bridge topic properties
prop = new Properties();
// Foreign QueueConnectionFactory JNDI name: foreignCF
prop.setProperty("connectionFactoryName", "foreignCF");
// Foreign Queue JNDI name: foreignDest
prop.setProperty("destinationName", "foreignTopic");
prop.setProperty("jndiFactory", "fr.dyade.aaa.jndi2.client.NamingContextFactory");
prop.setProperty("jndiUrl", "scn://localhost:16400");
prop.setProperty("connectionFactoryName", "cf"); // Foreign QueueConnectionFactory JNDI name
prop.setProperty("destinationName", "topic"); // Foreign Queue JNDI name: foreignDest
// Creating a Topic bridge on server 0:
Topic joramTopic = Topic.create(0,
Topic bridgeTopic = Topic.create(1,
"org.objectweb.joram.mom.dest.jmsbridge.JMSBridgeTopic",
prop);
joramTopic.setFreeReading();
joramTopic.setFreeWriting();
System.out.println("joram topic = " + joramTopic);
javax.jms.ConnectionFactory joramCF = TcpConnectionFactory.create();
jndiCtx.rebind("joramQueue", joramQueue);
jndiCtx.rebind("joramTopic", joramTopic);
jndiCtx.rebind("joramCF", joramCF);
bridgeTopic.setFreeReading();
bridgeTopic.setFreeWriting();
System.out.println("joram topic = " + bridgeTopic);
// bind foreign destination and connectionFactory
javax.naming.Context jndiCtx = new javax.naming.InitialContext();
jndiCtx.rebind("bridgeQueue", bridgeQueue);
jndiCtx.rebind("bridgeTopic", bridgeTopic);
jndiCtx.rebind("bridgeCF", bridgeCF);
jndiCtx.close();
AdminModule.disconnect();
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2007 - ScalAgent DT
* Copyright (C) 2007 - 2010 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): Nicolas Tachker (ScalAgent)
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package bridge;
......@@ -34,18 +34,18 @@ import javax.jms.Session;
public class BridgeConsumer {
public static void main(String[] args) throws Exception {
javax.naming.Context jndiCtx = new javax.naming.InitialContext();
Destination joramDest = (Destination) jndiCtx.lookup("joramQueue");
ConnectionFactory joramCF = (ConnectionFactory) jndiCtx.lookup("joramCF");
Destination bridgeDest = (Destination) jndiCtx.lookup("bridgeTopic");
ConnectionFactory bridgeCF = (ConnectionFactory) jndiCtx.lookup("bridgeCF");
jndiCtx.close();
Connection joramCnx = joramCF.createConnection();
Session joramSess = joramCnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer joramCons = joramSess.createConsumer(joramDest);
joramCons.setMessageListener(new MsgListener("joram"));
joramCnx.start();
Connection bridgeCnx = bridgeCF.createConnection();
Session bridgeSess = bridgeCnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer bridgeCons = bridgeSess.createConsumer(bridgeDest);
bridgeCons.setMessageListener(new MsgListener("bridge"));
bridgeCnx.start();
System.in.read();
joramCnx.close();
bridgeCnx.close();
}
}
......@@ -35,24 +35,24 @@ import javax.jms.TextMessage;
public class BridgeProducer {
public static void main(String[] args) throws Exception {
javax.naming.Context jndiCtx = new javax.naming.InitialContext();
Destination joramDest = (Destination) jndiCtx.lookup("joramQueue");
ConnectionFactory joramCF = (ConnectionFactory) jndiCtx.lookup("joramCF");
Destination bridgeDest = (Destination) jndiCtx.lookup("bridgeQueue");
ConnectionFactory bridgeCF = (ConnectionFactory) jndiCtx.lookup("bridgeCF");
jndiCtx.close();
Connection joramCnx = joramCF.createConnection();
Session joramSess = joramCnx.createSession(true, 0);
MessageProducer joramSender = joramSess.createProducer(joramDest);
Connection bridgeCnx = bridgeCF.createConnection();
Session bridgeSess = bridgeCnx.createSession(true, 0);
MessageProducer bridgeProducer = bridgeSess.createProducer(bridgeDest);
TextMessage msg = joramSess.createTextMessage();
TextMessage msg = bridgeSess.createTextMessage();
for (int i = 1; i < 11; i++) {
msg.setText("Joram message number " + i);
msg.setText("Joram message number " + i + "sent through bridge queue.");
System.out.println("send msg = " + msg.getText());
joramSender.send(msg);
bridgeProducer.send(msg);
}
joramSess.commit();
bridgeSess.commit();
joramCnx.close();
bridgeCnx.close();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2007 - ScalAgent DT
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): Nicolas Tachker (ScalAgent)
* Contributor(s):
*/
package bridge;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
/**
* Produces messages on the foreign destination.
*/
public class BridgePublisher {
public static void main(String[] args) throws Exception {
javax.naming.Context jndiCtx = new javax.naming.InitialContext();
Destination joramDest = (Destination) jndiCtx.lookup("joramTopic");
ConnectionFactory joramCF = (ConnectionFactory) jndiCtx.lookup("joramCF");
jndiCtx.close();
Connection joramCnx = joramCF.createConnection();
Session joramSess = joramCnx.createSession(true, 0);
MessageProducer joramSender = joramSess.createProducer(joramDest);
TextMessage msg = joramSess.createTextMessage();
for (int i = 1; i < 11; i++) {
msg.setText("Joram message number " + i);
System.out.println("send msg = " + msg.getText());
joramSender.send(msg);
}
joramSess.commit();
joramCnx.close();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2007 - ScalAgent DT
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): Nicolas Tachker (ScalAgent)
* Contributor(s):
*/
package bridge;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.MessageConsumer;
import javax.jms.Session;
/**
* Consumes messages on a foreign destination through the JORAM bridge.
*/
public class BridgeSubscriber {
public static void main(String[] args) throws Exception {
javax.naming.Context jndiCtx = new javax.naming.InitialContext();
Destination joramDest = (Destination) jndiCtx.lookup("joramTopic");
ConnectionFactory joramCF = (ConnectionFactory) jndiCtx.lookup("joramCF");
jndiCtx.close();
Connection joramCnx = joramCF.createConnection();
Session joramSess = joramCnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer joramCons = joramSess.createConsumer(joramDest);
joramCons.setMessageListener(new MsgListener("topic joram"));
joramCnx.start();
System.in.read();
joramCnx.close();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2007 - ScalAgent DT
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): Nicolas Tachker (ScalAgent)
* Contributor(s):
*/
package bridge;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.MessageConsumer;
import javax.jms.Session;
/**
* Consumes messages on a foreign destination through the JORAM bridge.
*/
public class ForeignConsumer {
public static void main(String[] args) throws Exception {
javax.naming.Context jndiCtx = new javax.naming.InitialContext();
Destination foreignDest = (Destination) jndiCtx.lookup("foreignQueue");
ConnectionFactory foreignCF = (ConnectionFactory) jndiCtx.lookup("foreignCF");
jndiCtx.close();
Connection foreignCnx = foreignCF.createConnection();
Session foreignSess = foreignCnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer foreignCons = foreignSess.createConsumer(foreignDest);
foreignCons.setMessageListener(new MsgListener("foreign"));
foreignCnx.start();
System.in.read();
foreignCnx.close();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2007 - ScalAgent DT
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): Nicolas Tachker (ScalAgent)
* Contributor(s):
*/
package bridge;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
/**
* Produces messages on the foreign destination.
*/
public class ForeignProducer {
public static void main(String[] args) throws Exception {
javax.naming.Context jndiCtx = new javax.naming.InitialContext();
Destination foreignDest = (Destination) jndiCtx.lookup("foreignQueue");
ConnectionFactory foreignCF = (ConnectionFactory) jndiCtx.lookup("foreignCF");
jndiCtx.close();
Connection foreignCnx = foreignCF.createConnection();
Session foreignSess = foreignCnx.createSession(true, 0);
MessageProducer foreignSender = foreignSess.createProducer(foreignDest);
TextMessage foreignMsg = foreignSess.createTextMessage();
for (int i = 1; i < 11; i++) {
foreignMsg.setText("Foreign message number " + i);
System.out.println("send msg = " + foreignMsg.getText());
foreignSender.send(foreignMsg);
}
foreignSess.commit();
foreignCnx.close();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2007 - ScalAgent DT
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): Nicolas Tachker (ScalAgent)
* Contributor(s):
*/
package bridge;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
/**
* Produces messages on the foreign destination.
*/
public class ForeignPublisher {
public static void main(String[] args) throws Exception {
javax.naming.Context jndiCtx = new javax.naming.InitialContext();
Destination foreignDest = (Destination) jndiCtx.lookup("foreignTopic");
ConnectionFactory foreignCF = (ConnectionFactory) jndiCtx.lookup("foreignCF");
jndiCtx.close();
Connection foreignCnx = foreignCF.createConnection();
Session foreignSess = foreignCnx.createSession(true, 0);
MessageProducer foreignSender = foreignSess.createProducer(foreignDest);
TextMessage foreignMsg = foreignSess.createTextMessage();
for (int i = 1; i < 11; i++) {
foreignMsg.setText("topic Foreign message number " + i);
System.out.println("send msg = " + foreignMsg.getText());
foreignSender.send(foreignMsg);
}
foreignSess.commit();
foreignCnx.close();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2007 - ScalAgent DT
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): Nicolas Tachker (ScalAgent)
* Contributor(s):
*/
package bridge;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.MessageConsumer;
import javax.jms.Session;
/**
* Consumes messages on a foreign destination through the JORAM bridge.
*/
public class ForeignSubscriber {
public static void main(String[] args) throws Exception {
javax.naming.Context jndiCtx = new javax.naming.InitialContext();
Destination foreignDest = (Destination) jndiCtx.lookup("foreignTopic");
ConnectionFactory foreignCF = (ConnectionFactory) jndiCtx.lookup("foreignCF");
jndiCtx.close();
Connection foreignCnx = foreignCF.createConnection();
Session foreignSess = foreignCnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer foreignCons = foreignSess.createConsumer(foreignDest);
foreignCons.setMessageListener(new MsgListener("topic foreign"));
foreignCnx.start();
System.in.read();
foreignCnx.close();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2007 - ScalAgent DT
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): Nicolas Tachker (ScalAgent)
* Contributor(s):
*/
package bridge;
import java.util.Properties;
import org.objectweb.joram.client.jms.Queue;
import org.objectweb.joram.client.jms.Topic;
import org.objectweb.joram.client.jms.admin.AdminModule;
import org.objectweb.joram.client.jms.admin.User;
import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
/**
* Administers an agent server for the bridge sample.
*/
public class XABridgeAdmin {
public static void main(String[] args) throws Exception {
System.out.println();
System.out.println("XA Bridge administration...");
AdminModule.connect("root", "root", 60);
User.create("anonymous", "anonymous", 0);
User.create("anonymous", "anonymous", 1);
javax.naming.Context jndiCtx = new javax.naming.InitialContext();
// create The foreign destination and connectionFactory
Queue foreignQueue = Queue.create(1, "foreignQueue");
foreignQueue.setFreeReading();
foreignQueue.setFreeWriting();
System.out.println("foreign queue = " + foreignQueue);
Topic foreignTopic = Topic.create(1, "foreignTopic");
foreignTopic.setFreeReading();
foreignTopic.setFreeWriting();
System.out.println("foreign topic = " + foreignTopic);
javax.jms.XAConnectionFactory foreignCF = TcpConnectionFactory.create("localhost", 16011);
// bind foreign destination and connectionFactory
jndiCtx.rebind("foreignQueue", foreignQueue);
jndiCtx.rebind("foreignTopic", foreignTopic);
jndiCtx.rebind("foreignCF", foreignCF);
// Setting the bridge properties
Properties prop = new Properties();
// Foreign QueueConnectionFactory JNDI name: foreignCF
prop.setProperty("connectionFactoryName", "foreignCF");