简体   繁体   English

如何将消息从Activemq推送到使用者

[英]How to push messages from Activemq to consumer

I am new to Activemq and Java ,I read tutorials,somewhat I understand.can anyone help me to solve the following task. 我是ActivemqJava新手,据我所知,我阅读了一些教程。任何人都可以帮助我解决以下任务。

Imagine we have a 10 messages in Queue/Topic of Activemq. 想象一下,Activemq的队列/主题中有10条消息。 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. 我想编写2个Java应用程序(使用JMS从activemq接收消息),它们将充当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. 我要实现的目标是,每当Activemq从数据库获取消息时,activemq应该检查是否有任何使用者是免费的。如果任何使用者是免费的,activemq应该将消息推送给使用者,一旦使用者收到消息,它将执行自己的处理。

So how should my java code be inorder to achieve this? 那么我的Java代码应该如何实现呢?

Also how to set the prefetch limit? 另外如何设置预取限制?

can anyone help me. 谁能帮我。

Thanks. 谢谢。

Ok good to know that there is Producer sitting between AMQ brokers and Database that is constantly pushing messages to AMQ. 好的,很高兴知道AMQ经纪人和数据库之间坐有Producer不断将消息推送到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). ActiveMQ代理会将消息推送给任何使用者(可以自定义其分发)。 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 . 正如我在上一个问题中回答的那样,AMQ将在开始等待ack之前使用prefetch limit (假设N)发送那么多消息。 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. 如果使用方忙,则其本地缓冲区中只能等待N条消息,AMQ代理将自动选择其他使用方来推送消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM