确保经纪人保留消息,直到至少一名消费者收到消息为止 [英] Make sure the broker holds messages until at least one consumer gets it

查看:119
本文介绍了确保经纪人保留消息,直到至少一名消费者收到消息为止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始实现基于ActiveMQ的消息传递服务,以将辅助任务发送到各种服务器,但是我注意到,在默认模式下,如果没有人监听"生产者的主题,那么来自该生产者的任何消息都会被迷路了.

I am begining to implement an ActiveMQ based messaging service to send worker tasks to various servers, however I am noticing that in the default mode, if no one is "listening" to a producer's topic, any message from that producer will be lost.

  • 如果生产者发件人消息与实时经纪人联系
  • 但是没有消费者在听
  • 消息无处可去

我想让代理保留消息,直到至少一个侦听器收到为止.

I would like instead for the Broker to hold on to messages until at least one listener receives it.

我正在尝试几种方法来实现此目的,但不确定采用最佳/正确的方法:

I am trying a couple ways of implementing this, but not sure on the most optimal/right way way:

  • 实施消息确认功能
  • (要注意的是,我需要制作人在每条看起来非常非常笨拙且不得已的消息之后等待其侦听器.)
  • 执行会话交易
  • (我对此很麻烦,由于交易这个词,听起来好像在这里使用是正确的事情,但我认为这更多与生产者-经纪人的互动有关,而不是与生产者-消费者的互动有关) li>

理想情况下,存在一种发送(或一组)消息的模式,并且在发送布尔值之后返回一个布尔值,说明是否至少有一个使用者监听了该消息.

Ideally, there is a mode to send a (or a set of) messages, and after sending a Boolean is returned stating if the message(s) were listened by at least one consumer.

推荐答案

事务和确认与JMS主题的一般思想有所冲突.

Transactions and acknowlegdement conflict somehow with the general idea of a JMS topic.

只需使用队列代替主题.使用CLIENT_ACKNOWLEDGE或事务处理的会话访问此队列.无论如何,一个工作人员任务只能由一个工作人员处理,因此队列解决了另一个问题.

Just use a queue instead of a topic. Access this queue using CLIENT_ACKNOWLEDGE or a transacted session. A worker task is to be processed by one worker only anyway, so the queue solves another problem.

如果出于特殊原因需要使用主题,则可以考虑在与JMS提供程序相同的主机上使用消息驱动Bean(MDB)(例如,可以通过使用JBoss及其集成的HornetQ来实现此目的),但这是仍然不是很正确.

If there was a special reason to use topics, you could consider a message driven bean (MDB) on the same host like the JMS provider (you could achieve this by using JBoss with its integrated HornetQ for example), but this is still not really correct.

另一种可能性是同时拥有一个主题和一个队列.后者仅用于保证每条消息的传递.

Another possibility is to have both a topic and a queue. The latter is only for guaranteed delivery of each message.

这篇关于确保经纪人保留消息,直到至少一名消费者收到消息为止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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