ActiveMQ messageId 无法停止复制

ActiveMQ messageId not working to stop duplication

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

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。

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

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

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

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