keepmoving
keepmoving

Reputation: 2043

ActiveMQ messageId not working to stop duplication

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;
});

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.

Upvotes: 0

Views: 1143

Answers (1)

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 includes powerful automatic duplicate message detection, filtering out messages sent by a producer more times.

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

Upvotes: 1

Related Questions