Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveMQ network of brokers don't forward messages

I had two ActiveMQ brokers (A and B) that were configured as store-forward network. They work perfectly to forward messages from A to B when there is a consumer connected on broker B and producer sends messages to A. The problem is that when the consumer is killed and reconnected to A, the queued messages on B (they were forwarded from A) won't forward back to A where the consumer connected to. Even I send new messages to B, all messages were stuck on B until I restart brokers. I have tried to set networkTTL="4" and duplex="true" on the broker network connector, but it doesn't work.

like image 810
Carl Z Avatar asked Mar 20 '13 17:03

Carl Z


People also ask

How ActiveMQ works internally?

ActiveMQ uses memory to store messages awaiting dispatch to consumers. Each message occupies some memory (how much depends on the size of the message) until it is dequeued and delivered to a consumer. At that point, ActiveMQ frees up the memory that had been used for that message.

Can ActiveMQ be distributed?

Apache ActiveMQ (AMQ) is a message broker which transfers the messages from the sender to the receiver. A distributed queue is a single unit of Java Message Service (JMS) queues that are accessible as a single, logical queue to a client.

Is ActiveMQ a message broker?

ActiveMQ. Apache ActiveMQ® is the most popular open source, multi-protocol, Java-based message broker. It supports industry standard protocols so users get the benefits of client choices across a broad range of languages and platforms.

How does ActiveMQ store messages?

References to messages are held in memory, and periodically inserted into the reference store to improve performance. The messages are stored in data logs, which are individual files, typically 32mb in size (though this is configurable, they can be larger if the size of a message is large than the file size).


2 Answers

Late answer, but hopefully this will help someone else in the future.

Messages are getting stuck in B because by default AMQ doesn't allow messages to be sent back to a broker to which they have previously been delivered. In the normal case, this prevents messages from going in cycles around mesh-like network topologies without getting delivered, but in the failover case it results in messages stuck on one broker and unable to get to the broker where all the consumers are.

To allow messages to go back to a broker if the current broker is a dead-end because there are no consumers connected to it, you should use replayWhenNoConsumers=true to allow forwarding messages that got stuck on B back to A.

That configuration option, some settings you might want to use in conjunction with it, and some considerations when using it, are described in the "Stuck Messages (version 5.6)" section of http://activemq.apache.org/networks-of-brokers.html, http://tmielke.blogspot.de/2012/03/i-have-messages-on-queue-but-they-dont.html, and https://issues.apache.org/jira/browse/AMQ-4465. Be sure that you can live with the side effects of these changes (e.g. the potential for duplicate message delivery of other messages across your broker-to-broker network connections).

like image 176
Tim Avatar answered Sep 22 '22 17:09

Tim


Can you give more information on the configuration of broker A and B, as well as what you are trying to achieve?

It seems to me you could achieve what you want by setting a network of brokers (with A and B), with the producer only connecting to one, the consumer to the other. The messages will automatically be transmitted to the other broker as long as the other broker has an active subscription to the destination the message was sent to.

I would not recommend changing the networkTTL if you are not sure of the consequences it produces (it tends to lead to unwanted messages loops).

like image 28
srodriguez Avatar answered Sep 22 '22 17:09

srodriguez