Apache ActiveMQ ™ -- JMS to JMS Bridge
Connectivity > JMS to JMS Bridge
Introduction
Warning, try Camel first!
Note that we recommend you look at using Apache Camel for bridging ActiveMQ to or from any message broker (or indeed any other technology, protocol or middleware) as its much easier to:
- keep things flexible; its very easy to map different queue/topic to one or more queues or topics on the other provider
- perform content based routing, filtering and other Enterprise Integration Patterns
- allows you to work with any technology, protocol or middleware, not just JMS providers
e.g. in your Spring XML file just add:
ActiveMQ provides bridging functionality to other JMS providers that implement the JMS 1.0.2 and above specification.
A JMS bridge can be co-located with an ActiveMQ broker or run remotely.
In order to support JMS 1.0.2 there is seperation between Queues and Topics.
temporary destinations and replyTo destinations in the inbound message exchanges are automatically handled, enabling an ActiveMQ service to handle a foreign JMS TopicRequestor or QueueResquestor exchanges.
properties
JMS Bridge Topic Connector
property name
default value
description
localTopicConnection
null
if set will be used to connect to ActiveMQ
localTopicConnectionFactory
null
used to initialize the ActiveMQ JMS Connection if localTopicConnection is not set
localClientId
null
set the id of the local connection
outboundClientId
null
set the id of the outbound connection
jndiLocalTemplate
Spring default template
used for locating the Connection Factory for the ActiveMQ Connection if the localTopicConnection or localTopicConnectionFactory is not set
outboundTopicConnection
null
if set will be used to connect to the foreign JMS provider
outboundTopicConnectionFactory
null
used to initialize the foreign JMS Connection if outboundTopicConnection is not set
jndiOutboundTemplate
Spring default template
used for locating the Connection Factory for the ActiveMQ Connection if the localTopicConnection or localTopicConnectionFactory is not set
localUsername
null
if set will be used for authentication to the ActiveMQ JMS provider
localPassword
null
if set will be used for authentication to the ActiveMQ JMS provider
outboundUsername
null
if set will be used for authentication to the foreign JMS provider
outboundPassword
null
if set will be used for authentication to the foreign JMS provider
inboundMessageConvertor
null
if set will be used for converting foreign JMS Messages to a format for ActiveMQ
outboundMessageConvertor
null
if set will be used for converting ActiveMQ messages to a format for the foriegn JMS provider
inboundTopicBridges
null
an array of InboundTopicBridge instances - used for defining inbound (subscribe to) traffic from the foreign JMS provider
outboundTopicBridges
null
an array of OutboundTopicBridge instances - used for defining destinations that will be published to the foreign JMS provider
JMS Bridge Queue Connector
property name
default value
description
localQueueConnection
null
if set will be used to connect to ActiveMQ
localQueueConnectionFactory
null
used to initialize the ActiveMQ JMS Connection if localQueueConnection is not set
localClientId
null
set the id of the local connection
outboundClientId
null
set the id of the outbound connection
jndiLocalTemplate
Spring default template
used for locating the Connection Factory for the ActiveMQ Connection if the localQueueConnection or localQueueConnectionFactory is not set
outboundQueueConnection
null
if set will be used to connect to the foreign JMS provider
outboundQueueConnectionFactory
null
used to initialize the foreign JMS Connection if localQueueConnection is not set
jndiOutboundTemplate
Spring default template
used for locating the Connection Factory for the ActiveMQ Connection if the localQueueConnection or localQueueConnectionFactory is not set
localUsername
null
if set will be used for authentication to the ActiveMQ JMS provider
localPassword
null
if set will be used for authentication to the ActiveMQ JMS provider
outboundUsername
null
if set will be used for authentication to the foreign JMS provider
outboundPassword
null
if set will be used for authentication to the foreign JMS provider
inboundMessageConvertor
null
if set will be used for converting foreign JMS Messages to a format for ActiveMQ
outboundMessageConvertor
null
if set will be used for converting ActiveMQ messages to a format for the foriegn JMS provider
inboundQueueBridges
null
an array of InboundQueueBridge instances - used for defining inbound (subscribe to) traffic from the foreign JMS provider
outboundQueueBridges
null
an array of OutboundQueueBridge instances - used for defining destinations that will be forwarded to the foreign JMS provider
Topic Bridges
InboundTopicBridge
property name
default value
description
localTopicName
null
the name of the local ActiveMQ Queue
inboundTopicName
null
the foreign topic name to subscribe to
selector
null
selector to use - if any
consumerName
null
if set will create a durable consumer
OutboundTopicBridge
property name
default value
description
localTopicName
null
the name of the local ActiveMQ Queue
outboundTopicName
null
the foreign topic name to publish to
Queue Bridges
InboundQueueBridge
property name
default value
description
localQueueName
null
the name of the local ActiveMQ Queue
inboundQueueName
null
the foreign queue name to receive from
selector
null
selector to use - if any
OutboundQueueBridge
property name
default value
description
localQueueName
null
the name of the local ActiveMQ Queue
outboundQueueName
null
the foreign queue name to send to
Example XBean Configuration
The following example config file shows how to use the regular Xml Configuration to configure a JMS to JMS bridge.
<!\-\- Set up the template for connecting to Weblogic -->
<bean id="remoteJndi" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
<prop key="java.naming.provider.url">t3://<your ip here>:7001</prop>
</props>
</property>
</bean>
<bean id="bridgedBroker" class="org.apache.activemq.broker.BrokerService" init-method="start" destroy-method="stop">
<property name="brokerName" value = "bridgedBroker"/>
<property name="persistent" value="false"/>
<property name="transportConnectorURIs">
<list>
<value>tcp://localhost:7001</value>
</list>
</property>
<property name="jmsBridgeConnectors">
<list>
<bean class="org.apache.activemq.network.jms.JmsQueueConnector">
<property name="outboundQueueConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:7000" />
</bean>
</property>
<property name="outboundQueueBridges">
<list>
<bean class="org.apache.activemq.network.jms.OutboundQueueBridge">
<constructor-arg value="messages.input"/>
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>
</beans>
Java code:
public class BridgeTest {
public BridgeTest() throws Exception {
Log log = LogFactory.getLog(getClass());
new ClassPathXmlApplicationContext("bridge/context-bridge.xml");
ActiveMQConnection connection = ActiveMQConnection.makeConnection("tcp://localhost:7001");
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("messages.input");
MessageProducer producer = session.createProducer(destination);
producer.send(session.createTextMessage("Test Message"));
log.debug("send message");
session.close();
connection.close();
connection = ActiveMQConnection.makeConnection("tcp://localhost:7000");
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = session.createQueue("messages.input");
MessageConsumer consumer = session.createConsumer(destination);
log.debug("receive message");
Message message = consumer.receive(5000);
log.debug("Received: " + message);
session.close();
connection.close();
}
public static void main(String\[\] args) throws Exception {
new BridgeTest();
}
}