1
votes

I have an issue with ActiveMQ loadbalancing with Mule. I am using Mule 3.2.0 and ActiveMQ 5.5.1

I have a Mule FLow application which uses JMS inbound Endpoint to listen to queues in ActiveMQ. I have 2 instances of AMQ running each having a queue called "MyQueue". Lets name them AMQ1 and AMQ2. I also have 2 mule instances running - each having the same app. Let's name them Mule1 and Mule2.

Now I want each mule instance to pick up messages from either of the AMQ queues. So say a Message Sender sends the message to the queue MyQueue in either AMQ1 or AMQ2 (Message sender load balances using failover transport supported by ActiveMQ - and that bit works fine). Say it reached AMQ1. Now ideally I would like to have 10 consumers each of Mule1 and Mule2 registered in each AMQ instance. So both of them are listening for incoming messages in both the queues. One of them should pick up the message from the queue and process it.

This is the config I am using in Mule to connect to both the AMQ brokers.

  <jms:activemq-connector name="Active_MQ"  brokerURL="failover:tcp://10.0.64.158:61616,tcp://10.0.64.160:61616)?randomize=true"  eagerConsumer="true" numberOfConsumers="10" dynamicNotification="true" validateConnections="true" clientId="MuleInstance1"  doc:name="Active MQ">
      <reconnect count="5" frequency="3000" blocking="false"/>

  </jms:activemq-connector>

kindly note clientId is different for different Mule instances. Also currently AMQ 1 and Mule1 share the same machine and AMQ2 and Mule2 share another machine.

However I am noticing soem random behaviour. AT times all consumers(both of Mule1 and Mule2) register only to one AMQ instance. At times Mule1 is registering only to AMQ1 and Mule 2 to AMQ2. What ideally I want is cosnumers of both Mule1 and Mule2 to register to both AM1 and AMQ2 I followed the instructions here http://www.mulesoft.org/documentation-3.2/display/MULE3USER/ActiveMQ+Integration

Basically I wanted to use the network of broker architecture so that there is no loss of service whether a Mule instance or AMQ instance goes down or has to be restarted. Not sure the randomize=true query param in helping in this case.

Can someone kindly advise how to achieve the above using Mule 3.2.0 and Active MQ 5.5.1?

If there isn't a solution sadly I may have to make Mule1 listen to AMQ1 and Mule2 listen to only AMQ2 and it won't really be clustered :(

Thanks in advance.

1
Adding this link I found if that helps. However still doesn't answer the random behaviour mentioned above. There is an outstanding jira request as follows issues.apache.org/jira/browse/AMQ-816. Still looking for help from Mule/ActiveMQ expertsSoumya
This doesn't look like a Mule issue. Have you seen this: stackoverflow.com/questions/2421198/…? Also why do you say it's not clustered if Mule1 connects to AMQ1 and Mule2 connects to AMQ2? The network of brokers exists between AMQ1 and AMQ2 independently of the consumers, so yes it's clustered. You can have Mule1 using AMQ1-failover-AMQ2 and Mule2 using AMQ2-failover-AMQ1, and be clustered/HA.David Dossot
Thanks David. Yes I am using the same failover transport protocal in my Mule app. I agree this may not be an issue with Mule and more to do with ActiveMQ but tagged it for both as some mule user may have encountered the same. Yes it will be clustered but only for the Message Producer who can send requests either to AMQ1 or AMQ2. But for the consumers in Mule they are listening to only one AMQ instance. In that case if say one Mule instance(Mule2) went down or had some issue all messages to AMQ2 will not get picked up. If 1 AMQ e.g. AMQ2 went down then Mule2 will be totally unused.Soumya
Also with Mule1 amq1-failover-amq2 - if amq1 goes down then to Mule1 amq2 becomes primary and will still remain primary even when amq1 is back up. so you may end up with a situation where both mule1 and mule2 are only talking to amq1 while messages coming to amq2 aren't getting picked up at all. Though one can use the priorityBackup avaialble in AMQ 5.6 where it always tries to reconnect to local one or the priority one - however not sure if that would have an impact on service. Also we are using 5.5.1 and yes we may have to upgrade to 5.6 for that but just trying to avoid that at the momentSoumya
btw found the priorityBackup info here .. activemq.apache.org/failover-transport-reference.htmlSoumya

1 Answers

2
votes

Got it working. Got a suggestion the Mule forum itself.

http://forum.mulesoft.org/mulesoft/topics/activemq_loadbalancing_with_mule

So basically instead of relying on AMQ load balancing for the consumer I used 2 AMQ connectors and used a composite source in each mule app listenign to 2 Inbound EndPoints. And it works a treat. Bringing up/Shutting down Mule and AMQ instances - all worked a treat. here's teh config

      <jms:activemq-connector  name="Active_MQ_1"  brokerURL="failover:  (tcp://10.0.64.158:61616)"  eagerConsumer="true"  numberOfConsumers="10"  dynamicNotification="true"  validateConnections="true"  clientId="MuleInstance1"  doc:name="Active MQ">
       <reconnect count="5" frequency="3000" blocking="false"/>

     </jms:activemq-connector>
     <jms:activemq-connector  name="Active_MQ_2"  brokerURL="failover:(tcp://10.0.64.160:61616)"  eagerConsumer="true"  numberOfConsumers="10"  dynamicNotification="true"  validateConnections="true"  clientId="MuleInstance1"  doc:name="Active MQ">
     <reconnect count="5" frequency="3000" blocking="false"/>

      </jms:activemq-connector>

Now refer to that from within your flow with composite-source

  <flow name="MyAutomationFlow" doc:name="MyAutomationFlow">
      <composite-source>
          <jms:inbound-endpoint queue="MyOrderQ" connector-ref="Active_MQ1" doc:name="JMS Inbound Endpoint"/>
          <jms:inbound-endpoint queue="MyOrderQ" connector-ref="Active_MQ2" doc:name="JMS Inbound Endpoint"/>
      </composite-source>
   ........

Worked a treat!