skip to Main Content

I am building a spring boot application with a cluster of ActiveMQ servers. In order to solve the duplicate message issue in the consumer side, all the dequeued JMSMessageID will be saved in redis, and the consumer will ignore all the new messages with duplicate IDs in redis.

In order to achieve this, I need all the JMSMessageID to be unique. I tried to set JMSMessageID in the producer code, but it seems that I cannot change it. My question is that in the distributed system(multiple application servers, and a cluster of ActiveMQ server), will the system generated JMSMessageID be unique?

jmsTemplate.send(name, new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
               Email email = new Email("l****@gmail.com", "this is test body", "test");
               ObjectMessage objectMessage = session.createObjectMessage();
               objectMessage.setJMSMessageID(customID);
               return objectMessage;
            }
         });

2

Answers


  1. The JMSMessageID is set by the JMS provider. It cannot be set by the client as per the JMS specification. The JMS spec does guarantee the uniqueness of the JMSMessageID. Section 3.4.3 of both the JMS 1.1 & 2 specifications says:

    A JMSMessageID is a String value which should function as a unique key for identifying messages in a historical repository. The exact scope of uniqueness is provider defined. It should at least cover all messages for a specific installation of a provider where an installation is some connected set of message routers.

    Login or Signup to reply.
  2. Send a generic message GenericMessage(T payload, Map<String,Object> headers)
    . The payload will be your object, and in the header you can inject some unique value, with which you can uniquely identify the message.

      MessageHeaders headers = new MessageHeaders(Collections.<String, Object>singletonMap("foo", "some unique value"));
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search