tags:

views:

528

answers:

2

I have a local ActiveMQ broker which is on an unreliable internet connection, and also a remote ActiveMQ broker in a reliable datacenter. I have already sorted out a "store and forward" setup so that outgoing messages are sent to the remote broker when the Internet connection is available. That alone works great, but when messages are outbound.

However, now I have to do the reverse. Here is the scenario:

  1. A new message appears in the remote ActiveMQ broker. The message is put into a specific queue.
  2. In a few minutes, the Internet connection becomes available to the local ActiveMQ broker.
  3. The local broker should then be able to pull the message from the remote broker, and place it in its own local queue.
  4. Local consumers will then be able to see the message.

So in essence, I need the local broker to become a subscribed consumer to the remote queue. I have looked through the ActiveMQ documentations but I can't find anything yet about how to do this in the .xml configuration file.

Is this what I should be looking for? See: "ActiveMQ: JMS to JMS Bridge".

Any advice and tips would be highly appreciated.

+1  A: 

I made it work using JMS to JMS Bridge. See relevant config below.

I see another potential problem though. On the remote ActiveMQ broker, the "enqueued messages" seem to just linger there. I'd prefer them to be automatically deleted.

... snip snip
    <jmsBridgeConnectors>
        <jmsTopicConnector
          outboundTopicConnectionFactory="#remoteFactory">
          <inboundTopicBridges>
            <inboundTopicBridge inboundTopicName="jms/TestTopic1" localTopicName="jms/TestTopicResult" />
          </inboundTopicBridges>
        </jmsTopicConnector>
    </jmsBridgeConnectors>

</broker>
<bean id="remoteFactory"
    class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="tcp://x.x.x.x:61616" />
</bean>
... snip snip
T.K.
Comment to myself again: ActiveMQ's control panel on the remote broker says: 4 messages enqueued. 8 messages dequeued. I guess this seems OK after all. I was worried that memory would fill up with messages, but it appears that it is actually dequeueing them.
T.K.
A: 

With activemq network of brokers, you can easily do the store and forward. ( http://activemq.apache.org/networks-of-brokers.html )

If you want from local to remote, the default works, if you want remote to talk back to local, you should either:

A) Make a connection from the remote to the local broker in the same way you did from local to remote ( use the failover transport so the brokers reconnect after loss and restore of connection. We do this all the time and it works great)

B) Make the connection you already have from local to remote duplex ( take a look at the duplex uri parameter on the link above).

duplex false if true, a network connection will be used to both produce AND Consume messages. This is useful for hub and spoke scenarios when the hub is behind a firewall etc.

Example:

 <networkConnector name="REMOTE" uri="static://(tcp://IP_OR_REMOTE_HOST:61616)" userName="system" password="manager" duplex="true"/>
Noctris