ActiveMQ messageId 无法停止复制 [英] ActiveMQ messageId not working to stop duplication

查看:16
本文介绍了ActiveMQ messageId 无法停止复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ActiveMQ 进行消息传递,并且有一个要求,如果消息是重复的,那么它应该由 AMQ 自动处理.为此,我生成唯一的消息密钥并设置为 messageproccessor.以下是代码:

I am using ActiveMQ for messaging and there is one requirement that if message is duplicate then it should handled by AMQ automatically. For that I generate unique message key and set to messageproccessor. following is code :

jmsTemplate.convertAndSend(dataQueue, event, messagePostProccessor -> {

    LocalDateTime dt = LocalDateTime.now();
    long ms = dt.get(ChronoField.MILLI_OF_DAY) / 1000;
    String messageUniqueId = event.getResource() + event.getEntityId() + ms;
    System.out.println("messageUniqueId : " + messageUniqueId);
    messagePostProccessor.setJMSMessageID(messageUniqueId);
    messagePostProccessor.setJMSCorrelationID(messageUniqueId);
    return messagePostProccessor;
});

正如所见,代码生成唯一的 id,然后将其设置为 messagepostproccessor.

As it can be seen code generates unique id and then set it to messagepostproccessor.

可以帮我解决这个问题吗,我还需要做其他配置吗.

Can somehelp me on this, is there any other configuration that I need do.

推荐答案

消费者收到重复消息主要有两个原因:生产者多次发送同一条消息或消费者多次收到同一条消息.

A consumer can receive duplicate messages mainly for two reasons: a producer sent the same message more times or a consumer receive the same message more times.

Apache ActiveMQ Artemis 包括强大的自动重复消息检测,过滤掉生产者多次发送的消息.

Apache ActiveMQ Artemis includes powerful automatic duplicate message detection, filtering out messages sent by a producer more times.

为了防止消费者多次收到相同的消息,必须实现幂等消费者,即Apache Camel提供了一个可以与任何JMS提供者一起使用的幂等消费者组件,请参阅:http://camel.apache.org/idempotent-consumer.html

To prevent a consumer from receiving the same message more times, an idempotent consumer must be implemented, ie Apache Camel provides an Idempotent consumer component that would work with any JMS provider, see: http://camel.apache.org/idempotent-consumer.html

这篇关于ActiveMQ messageId 无法停止复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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