ActiveMQ messageId无法停止复制

问题描述 投票:0回答:1

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

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。

可以帮助我吗,我需要做其他配置吗?

spring activemq activemq-artemis
1个回答
1
投票

消费者可以收到重复的消息主要有两个原因:生产者多次发送相同的消息,或者消费者多次接收相同的消息。

Apache ActiveMQ Artemis包含功能强大的自动duplicate message detection,可过滤掉生产者发送的消息多次。

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

© www.soinside.com 2019 - 2024. All rights reserved.