Reputation: 1117
I am new to Activemq
and Java
,I read tutorials,somewhat I understand.can anyone help me to solve the following task.
Imagine we have a 10 messages in Queue/Topic of Activemq. we are getting messages from Database,we already did it.
I want to write 2 Java Applications (using JMS for receiving messages from activemq ) that will act as a consumer in Activemq. What i want to achieve out of this is that whenever Activemq
get messages from Database, activemq should check if any consumer is free or not.If any consumer is free activemq should push message to consumer,once consumer receives it will do its own processing.
So how should my java code be inorder to achieve this?
Also how to set the prefetch limit?
can anyone help me.
Thanks.
Upvotes: 0
Views: 4600
Reputation: 784888
Ok good to know that there is Producer sitting between AMQ brokers and Database that is constantly pushing messages to AMQ.
To answer your question. There can be multiple consumers listening on any destination (queue/topic). ActiveMQ broker will push the message to any consumer (distribution of which can be customized). As I answered in my previous question that AMQ will use prefetch limit
(let's say N) to send that many messages before starting to wait to get ack
. If a consumer is busy then there can be only N messages waiting in its local buffer and AMQ broker will automatically choose the other consumer to push the messages.
Upvotes: 3