How to push messages from Activemq to consumer

此生再无相见时 提交于 2019-12-11 19:25:22

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/18630657/how-to-push-messages-from-activemq-to-consumer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!