本文介绍了ActiveMQ替代计划的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Active MQ通过覆盖消息来实现延迟队列.

I am trying to implement delayed queue with overriding of messages using Active MQ.

每条消息计划以x的延迟发送(例如60秒)

Each message is scheduled to be delivered with delay of x (say 60 seconds)

在两次接收相同消息的过程中,它应该覆盖先前的消息.

In between if same message is received again it should override previous message.

因此,即使我在x秒内收到10条消息也要说.仅应处理一条消息.

So even if I receive 10 messages say in x seconds. Only one message should be processed.

有没有干净的方法来实现这一目标?

Is there clean way to accomplish this?

推荐答案

问题有两个部分需要分别解决:

The question has two parts that need to be addressed separately:

可以在ActiveMQ中延迟邮件吗?

是-请参见延迟和计划邮件传递.您需要在ActiveMQ配置中设置<broker ... schedulerSupport="true">,并设置JMS消息的AMQ_SCHEDULED_DELAY属性,该属性说明您希望消息延迟多长时间(在您的情况下为10000).

Yes - see Delay and Schedule Message Delivery. You need to set <broker ... schedulerSupport="true"> in your ActiveMQ config, as well as setting the AMQ_SCHEDULED_DELAY property of the JMS message saying how long you want the message to be delayed (10000 in your case).

有什么方法可以防止同一条消息被多次使用?

是的,但这是应用程序方面的问题,而不是ActiveMQ.它通常被称为重复数据删除或幂等消耗.如果只有一个使用者,最简单的方法是跟踪地图中收到的消息,并检查该地图是否收到消息.已经看到,丢弃.

Yes, but that's an application concern rather than an ActiveMQ one. It's often referred to as de-duplication or idempotent consumption. The simplest way if you only have one consumer is to keep track of messages received in a map, and check that map whether you receive a message. It it has been seen, discard.

对于更复杂的用例,如果您在不同的计算机上有多个使用者,或者希望该状态在应用程序重新启动后仍然存在,则需要保留一个在数据库中看到的消息表,并每次对其进行查询.

For more complex use cases where you have multiple consumers on different machines, or you want that state to survive application restart, you will need to keep a table of messages seen in a database, and query it each time.

如果有帮助,请对此答案投票,因为它会鼓励人们帮助您.

Please vote this answer up if it helps, as it encourages people to help you out.

这篇关于ActiveMQ替代计划的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 09:57