MarcinB
MarcinB

Reputation: 3

ActiveMQ receiving messages from a queue sent before client get connected

In my scenario producer is sending messages to a queue (as usual:) but one of the consumer from time to time turns off, so I must be able to read all messages sent to that queue while consumer was off. In other words I'm looking for configuration of messages or whole server which allows to receive messages after reconnecting of a consumer, while the messages were send beforehand.

To be more precise, when the client gets reconnected it is unable to receive messages pending in the queue. What I need is to force the newly connected client to receive the messages already pending in the queue to help the other clients to discharge the queue.

Upvotes: 0

Views: 1798

Answers (1)

Hassen Bennour
Hassen Bennour

Reputation: 3913

this the normal behavior defined, messages sent to a queue still pending and not lost if there is no consumer connected.

UPDATE

So i think your problem is the prefetchPolicy.

persistent queues (default value: 1000)
non-persistent queues (default value: 1000)
persistent topics (default value: 100)
non-persistent topics (default value: Short.MAX_VALUE - 1)

so i think that all messages was dispatched to the connected consumer and when another one connects he don't receive messages, so to change this behavior if you have concurrent consumer for a queue you need to set prefetchPolicy to a lower value than default. for example add this jms.prefetchPolicy.queuePrefetch=1 to the uri config in activemq.xml or set it on the client url.

Large prefetch values are recommended for high performance with high message volumes. However, for lower message volumes, where each message takes a long time to process, the prefetch should be set to 1. This ensures that a consumer is only processing one message at a time. Specifying a prefetch limit of zero, however, will cause the consumer to poll for messages, one at a time, instead of the message being pushed to the consumer.

Take a look at http://activemq.apache.org/what-is-the-prefetch-limit-for.html

And

http://activemq.apache.org/destination-options.html

Upvotes: 2

Related Questions