Advisory messages for remote broker clients?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Advisory messages for remote broker clients?

nauman73
Hi

I was handed over an ActiveMQ related development project recently. I do not have lot of background knowledge on ActiveMQ so I may not explain my question in exact ActiveMQ terminology.

We have a network of brokers where one broker is acting as the publisher and the other is acting as subscriber. The publisher transport connector is declared as follows in activemq.xml.

<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616" updateClusterClients="false" rebalanceClusterClients="false" updateClusterClientsOnRemove="true"/>
</transportConnectors>

On the subscriber side the network connector and transport connector are declared as follows. The {othernode} in network connector is replaced with publisher machine IP during deployment.

<networkConnectors>
<networkConnector name="Broker12Bridge" userName="system" password="manager" uri="static:(tcp://${othernode}:61616)" duplex="true" prefetchSize="100"/>
</networkConnectors>

<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616" updateClusterClients="false" rebalanceClusterClients="false" updateClusterClientsOnRemove="true"/>
</transportConnectors>

We are using ActiveMQ-CPP in the client application code to make connection with local ActiveMQ. We have a client application on the publisher machine and a client application on the subscriber machine. Both clients create a producer, a durable consumer and a non-durable consumer on local ActiveMQ. Both clients register the same topic (i.e. EEP) so both can exchange messages with each other in both directions.

In addition, both clients also create a consumer for the "ActiveMQ.Advisory.Connection" advisory messages. The aim of the advisory messages consumer is to get the intimation in case the broker or the client application on the opposite machine has disconnected. This allows us to handle some failover tasks.

We are able to get the advisory messages when the opposite machine shuts down or gets unplugged from network. However, we also need to know if the client application on other machine has crashed for some reason. We do have a mechanism to intimate the opposite machine client in case of a graceful shutdown of one machine client application (i.e. before shutdown the client application sends a status message to the ActiveMQ topic, and this message is received by the client application on opposite machine). But in case of a crash of client application on one machine, the client on opposite machine does not get any intimation from ActiveMQ of that machine. However, in the ActiveMQ logs of opposite machine, I can see that the ActiveMQ does know about crash of client application. In the ActiveMQ logs, I see following log when the client crashes.

2014-07-09 16:47:53,719 | DEBUG | static-broker2 removing interest in sub on vm://static-broker2#0 from static-broker1 : sub: ID:PAK-W2012R2-NH1-62609-1404905690709-0:0:0:0 existing matched sub: ConsumerInfo {commandId = 0, responseRequired = false, consumerId = ID:PAK-W2012R2-NH2-51238-1404905790383-2:2:1:1, destination = topic://EEP, prefetchSize = 0, maximumPendingMessageLimit = 0, browser = false, dispatchAsync = false, selector = null, subscriptionName = null, noLocal = false, exclusive = false, retroactive = false, priority = 0, brokerPath = null, optimizedAcknowledge = false, noRangeAcks = false, additionalPredicate = null} | org.apache.activemq.network.ConduitBridge | ActiveMQ Transport: tcp://PAK-W2012R2-NH1/10.110.22.32:61616

I registered for some other available advisory topics "ActiveMQ.Advisory.Consumer.Topic.EEP", "ActiveMQ.Advisory.Producer.Topic.EEP", "ActiveMQ.Advisory.Producer.Topic", and "ActiveMQ.Advisory.NetworkBridge". However, it seems these topics only reflect the status of local ActiveMQ subscribers. I have also looked at ActiveMQ documentation for any other advisory topic that can be enabled to get notification of remote broker client/subscriber connection/disconnection. But so far I have not been able to find anything.

Any help/guidance with above situation is most appreciated.

Regards
Nauman
Reply | Threaded
Open this post in threaded view
|

Re: Advisory messages for remote broker clients?

ceposta
You could have a little camel route listen on the broker for the
ActiveMQ.Advisory.Connection advisory topic and see when the client goes
away. Then if it does, broadcast a message out to the clients that are
interested in this information.

http://activemq.apache.org/advisory-message.html


On Wed, Jul 9, 2014 at 4:51 AM, nauman73 <[hidden email]> wrote:

> Hi
>
> I was handed over an ActiveMQ related development project recently. I do
> not
> have lot of background knowledge on ActiveMQ so I may not explain my
> question in exact ActiveMQ terminology.
>
> We have a network of brokers where one broker is acting as the publisher
> and
> the other is acting as subscriber. The publisher transport connector is
> declared as follows in activemq.xml.
>
> <transportConnectors>
> <transportConnector name="openwire" uri="tcp://0.0.0.0:61616"
> updateClusterClients="false" rebalanceClusterClients="false"
> updateClusterClientsOnRemove="true"/>
> </transportConnectors>
>
> On the subscriber side the network connector and transport connector are
> declared as follows. The {othernode} in network connector is replaced with
> publisher machine IP during deployment.
>
> <networkConnectors>
> <networkConnector name="Broker12Bridge" userName="system"
> password="manager"
> uri="static:(tcp://${othernode}:61616)" duplex="true" prefetchSize="100"/>
> </networkConnectors>
>
> <transportConnectors>
> <transportConnector name="openwire" uri="tcp://0.0.0.0:61616"
> updateClusterClients="false" rebalanceClusterClients="false"
> updateClusterClientsOnRemove="true"/>
> </transportConnectors>
>
> We are using ActiveMQ-CPP in the client application code to make connection
> with local ActiveMQ. We have a client application on the publisher machine
> and a client application on the subscriber machine. Both clients create a
> producer, a durable consumer and a non-durable consumer on local ActiveMQ.
> Both clients register the same topic (i.e. EEP) so both can exchange
> messages with each other in both directions.
>
> In addition, both clients also create a consumer for the
> "ActiveMQ.Advisory.Connection" advisory messages. The aim of the advisory
> messages consumer is to get the intimation in case the broker or the client
> application on the opposite machine has disconnected. This allows us to
> handle some failover tasks.
>
> We are able to get the advisory messages when the opposite machine shuts
> down or gets unplugged from network. However, we also need to know if the
> client application on other machine has crashed for some reason. We do have
> a mechanism to intimate the opposite machine client in case of a graceful
> shutdown of one machine client application (i.e. before shutdown the client
> application sends a status message to the ActiveMQ topic, and this message
> is received by the client application on opposite machine). But in case of
> a
> crash of client application on one machine, the client on opposite machine
> does not get any intimation from ActiveMQ of that machine. However, in the
> ActiveMQ logs of opposite machine, I can see that the ActiveMQ does know
> about crash of client application. In the ActiveMQ logs, I see following
> log
> when the client crashes.
>
> 2014-07-09 16:47:53,719 | DEBUG | static-broker2 removing interest in sub
> on
> vm://static-broker2#0 from static-broker1 : sub:
> ID:PAK-W2012R2-NH1-62609-1404905690709-0:0:0:0 existing matched sub:
> ConsumerInfo {commandId = 0, responseRequired = false, consumerId =
> ID:PAK-W2012R2-NH2-51238-1404905790383-2:2:1:1, destination = topic://EEP,
> prefetchSize = 0, maximumPendingMessageLimit = 0, browser = false,
> dispatchAsync = false, selector = null, subscriptionName = null, noLocal =
> false, exclusive = false, retroactive = false, priority = 0, brokerPath =
> null, optimizedAcknowledge = false, noRangeAcks = false,
> additionalPredicate
> = null} | org.apache.activemq.network.ConduitBridge | ActiveMQ Transport:
> tcp://PAK-W2012R2-NH1/10.110.22.32:61616
>
> I registered for some other available advisory topics
> "ActiveMQ.Advisory.Consumer.Topic.EEP",
> "ActiveMQ.Advisory.Producer.Topic.EEP", "ActiveMQ.Advisory.Producer.Topic",
> and "ActiveMQ.Advisory.NetworkBridge". However, it seems these topics only
> reflect the status of local ActiveMQ subscribers. I have also looked at
> ActiveMQ documentation for any other advisory topic that can be enabled to
> get notification of remote broker client/subscriber
> connection/disconnection. But so far I have not been able to find anything.
>
> Any help/guidance with above situation is most appreciated.
>
> Regards
> Nauman
>
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Advisory-messages-for-remote-broker-clients-tp4683016.html
> Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
>



--
*Christian Posta*
http://www.christianposta.com/blog
http://fabric8.io
twitter: @christianposta
Reply | Threaded
Open this post in threaded view
|

Re: Advisory messages for remote broker clients?

nauman73
Hi ceposta

Thanks for quick feedback. The camel route does the trick and I am able to route the advisory messages to opposite broker.

I have a little hiccup though that I have not been able to overcome. In order to route the messages to opposite broker I need to establish a connection with opposite broker by providing the configuration in XML. I have done as follows for the moment.

<bean id="activemqRemote" class="org.apache.activemq.camel.component.ActiveMQComponent" >
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://10.110.22.45:61616" />
<property name="userName" value="${activemq.username}"/>
<property name="password" value="${activemq.password}"/>
</bean>
</property>
</bean>

The "brokerURL" is currently pointing to IP address of opposite broker. However, I would like to dynamically discover the brokerURL for the opposite broker by somehow fetching the remote address of the network bridge, as seen in attached image.



I have tried to find a way to do this via XML configuration but so far no luck.

Is it at all possible to do it in XML configuration?

Thanks

Regards
Nauman
Reply | Threaded
Open this post in threaded view
|

Re: Advisory messages for remote broker clients?

ceposta
You may need to write a little JMX query script (or see the activemq-admin
script that ships by default). You can try looking it up that way. I think
jolokia is enabled an all recent versions as well, so could use
REST/json/http to look it up as well:

http://activemq.apache.org/rest.html

In general, for dynamic discover of brokers, Fabric8 can help you:

http://fabric8.io
http://fabric8.io/gitbook/brokerClients.html




On Thu, Jul 10, 2014 at 3:26 AM, nauman73 <[hidden email]> wrote:

> Hi ceposta
>
> Thanks for quick feedback. The camel route does the trick and I am able to
> route the advisory messages to opposite broker.
>
> I have a little hiccup though that I have not been able to overcome. In
> order to route the messages to opposite broker I need to establish a
> connection with opposite broker by providing the configuration in XML. I
> have done as follows for the moment.
>
> <bean id="activemqRemote"
> class="org.apache.activemq.camel.component.ActiveMQComponent" >
> <property name="connectionFactory">
> <bean class="org.apache.activemq.ActiveMQConnectionFactory">
> <property name="brokerURL" value="tcp://10.110.22.45:61616" />
> <property name="userName" value="${activemq.username}"/>
> <property name="password" value="${activemq.password}"/>
> </bean>
> </property>
> </bean>
>
> The "brokerURL" is currently pointing to IP address of opposite broker.
> However, I would like to dynamically discover the brokerURL for the
> opposite
> broker by somehow fetching the remote address of the network bridge, as
> seen
> in attached image.
>
> <http://activemq.2283324.n4.nabble.com/file/n4683064/remoteBroker.png>
>
> I have tried to find a way to do this via XML configuration but so far no
> luck.
>
> Is it at all possible to do it in XML configuration?
>
> Thanks
>
> Regards
> Nauman
>
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Advisory-messages-for-remote-broker-clients-tp4683016p4683064.html
> Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
>



--
*Christian Posta*
http://www.christianposta.com/blog
http://fabric8.io
twitter: @christianposta
Reply | Threaded
Open this post in threaded view
|

Re: Advisory messages for remote broker clients?

nauman73
This post was updated on .
Hi ceposta

I am having little problem with routing of advisory messages to opposite broker. While the advisory message does appear to get routed to opposite broker, the format of the advisory message is not the same as the original message. The route declaration is as follows. I have followed the example given at "Consuming Advisory Messages" section of http://camel.apache.org/activemq.html with some modification.

<route>
<description>Connection Advisory Route</description>
<from uri="activemq:topic:ActiveMQ.Advisory.Connection?mapJmsMessage=false"/>
<to uri="activemqRemote:topic:ActiveMQ.Advisory.Routed"/>
</route>

The issue I have is that the "dataStructure" of the routed ActiveMQMessage is always null. Whereas the "dataStructure" of the original advisory message has the RemoveInfo, ProducerInfo etc. depending on type of activity. If I run the example route given at above mentioned URL, I do get the proper "dataStructure" written to the output file used in that example.

If I change my route to match the route given in the example, except for the "to" endpoint, the route becomes as follows.

<route>
<description>Connection Advisory Route</description>
<from uri="activemq:topic:ActiveMQ.Advisory.Connection?mapJmsMessage=false"/>
<convertBodyTo type="java.lang.String"/>
<transform>
  <simple>${in.body} </simple>
</transform>
<to uri="activemqRemote:topic:ActiveMQ.Advisory.Routed"/>
</route>

With this route, the routed message type is changed to "ActiveMQTextMessage" instead of the "ActiveMQMessage". The "dataStructure" is still null.

I have tried variations of above route definition. I have also tried to set the "jmsMessageType" and "mapJmsMessage" options differently. None of these works and I always get the dataStructure as null in the advisory message routed to opposite broker.

Any clues?

Thanks

Regards
Nauman
Reply | Threaded
Open this post in threaded view
|

Re: Advisory messages for remote broker clients?

nauman73
Hi ceposta

I think I found the solution. Adding the "forceSendOriginalMessage=true" option on the "to" endpoint seems to do the trick.

Regards
Nauman