11

I need the queue to enforce no-duplicate policy. Is it possible? If so , how? (I've been googling for hours... )

Edit:

The ActiveMQSession implementation has this lines:

        // transform to our own message format here
            ActiveMQMessage msg = ActiveMQMessageTransformation.transformMessage(message, connection);

        // Set the message id.
        if (msg == message) {
            msg.setMessageId(new MessageId(producer.getProducerInfo().getProducerId(), sequenceNumber));
        } else {
            msg.setMessageId(new MessageId(producer.getProducerInfo().getProducerId(), sequenceNumber));
            message.setJMSMessageID(msg.getMessageId().toString());
        }

The ActiveMQMessageTransformation is plugable (you can set it) , but the following if statement is a rather incontrovertible .

Any ideas , except changing their code?

Yossale
  • 14,165
  • 22
  • 82
  • 109

1 Answers1

1

ActiveMQ has duplicate message detection built in - how are you defining a duplicate ? If the duplicate has the same messageId - it should be discarded

Rob Davies
  • 795
  • 6
  • 6
  • 1
    (I'm sorry for the non-specific class names , it's been a while) I wanted to define the parameter message id which is tested for duplication . However , in spite the fact that you can do message.setId , it is being override(!) in the AMQProxy and set with a new manufactured messageId. – Yossale Jan 05 '10 at 12:35
  • the messageID is set by the JMS provider - and for ActiveMQ we provide a globally unique id. The correct way to do this with JMS is to set a Message Header property. For ActiveMQ - you can use use generated messageID itself - as it will always be unique. – Rob Davies Jan 07 '10 at 10:15
  • I'm using ActiveMQ 5.4.1. If I set a custom JMSMessageID, it doesn't work as expected. The JMSMessageId is built by ActiveMQ internals. I reported a example and a HornetQ example on http://stackoverflow.com/questions/4934386/avoiding-duplicated-messages-on-jms-activemq – Andre Pastore Feb 09 '11 at 14:53
  • Yes - not all JMS providers accept a user setting the JMSMessageID. Its in the JMS spec that a provider can ignore it. Could you not use a well defined property you set on the header ? That way your message id will work with any JMS provider – Rob Davies Feb 11 '11 at 15:04
  • 2
    @Rob But how do I get ActiveMQ to honor said well-defined property on the header when detecting duplicates? How do I get ActiveMQ to discard incoming messages with MY_MSG_ID=123 as long as there's already another one with 123 on the queue, regardless of the JMSMessageID? – Antares42 Jan 22 '15 at 14:01