Search code examples
javaqueueactivemq-classicdispatch

How activemq wildcard consumers work?


I am using ActiveMQ 5.8 with wildcard consumers configured in camel route.

I am using default ActiveMQ configuration, so I have defaults as below

prefetch = 1
dispatch policy= Round Robin

Now I start a consumer jvm with 5 consumers each for 2 queues. both the queue has same type of message and same number of messages.

Consumers are doing nothing but printing the message (so no db blocking or slow consumer issue)

EDIT I have set preFetch to 1 for each of the queue

What I observe is one of the queue getting drained faster than other.

What I expect is both the queue getting drained at equal pace, kind of load balance.

One surprising observation is Though activemq webconsole shows 5 consumers for each of those queues

enter image description here

When I debug my consumer, I see only 5 threads / consumers from camel flow for a wildcard queue *.processQueue enter image description here

What will be cause of above behavior? How do I make sure that all the queue drain at equal pace?

Did anyone has experience to share on writting custom dispatch policy or overriding defaults of activemq?


Solution

  • I was able to find a reference to this behavior

    Message distribution in case of wildcard queue consumers is random.

    http://activemq.2283324.n4.nabble.com/Wildcard-and-message-distribution-td2346132.html#a2346133

    Though this can be tuned by setting appropriate prefetch size.

    After trial & error, I arrived at following formula, to have fair distribution across the consumers and all the queue getting de-queued at almost same pace.

    prefetch = number of wildcard consumers