如何将消息从Activemq推送到使用者 [英] How to push messages from Activemq to consumer

查看:467
本文介绍了如何将消息从Activemq推送到使用者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ActivemqJava的新手,我了解了一些教程,据我所知.任何人都可以帮助我解决以下任务.

I am new to Activemq and Java,I read tutorials,somewhat I understand.can anyone help me to solve the following task.

想象一下,在Activemq的队列/主题中有10条消息.我们正在从数据库获取消息,我们已经做到了.

Imagine we have a 10 messages in Queue/Topic of Activemq. we are getting messages from Database,we already did it.

我想编写2个Java应用程序(使用JMS从activemq接收消息),它们将充当Activemq的使用者.我要实现的目标是,每当Activemq从数据库获取消息时,activemq应该检查是否有任何使用者是免费的.如果任何使用者是免费的,activemq应该将消息推送给使用者,一旦使用者收到消息,它将执行自己的操作处理.

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.

那么我的Java代码应该如何实现呢?

So how should my java code be inorder to achieve this?

还有如何设置预取限制?

Also how to set the prefetch limit?

任何人都可以帮助我.

谢谢.

推荐答案

好的,很高兴知道AMQ代理与数据库之间存在生产者,该生产者不断将消息推送到AMQ.

Ok good to know that there is Producer sitting between AMQ brokers and Database that is constantly pushing messages to AMQ.

回答您的问题.可以有多个消费者在任何目的地(队列/主题)上监听. ActiveMQ代理会将消息推送给任何使用者(可以自定义其分发).正如我在上一个问题中回答的那样,AMQ在开始等待获取ack之前将使用prefetch limit(假设N)发送那么多消息.如果某个使用者繁忙,则其本地缓冲区中只能等待N条消息,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.

这篇关于如何将消息从Activemq推送到使用者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆