20.10.2. Using Duplicate Message Detection for Sending Messages
To enable duplicate message detection for sent messages you need to set a special property on the message to a unique value. You can create this value the way you wish but this value must be unique.
When the target server receives this message, it checks if the special property is set. If the property is set then the target server checks its memory cache for a received message with that value of the header. If the server finds any message with the same value of the header it ignores the message sent by a client.
If you are sending messages in a transaction then you do not have to set the property for every message you send in that transaction; you only need to set it once in the transaction. If the server detects a duplicate message for any message in the transaction, then it will ignore the entire transaction.
The name of the property that you set is given by the value of
org.hornetq.api.core.HDR_DUPLICATE_DETECTION_ID, which is
_HQ_DUPL_ID. The value of this property can be of type
SimpleStringfor core API. For Java Messaging Service (JMS) clients, it must be of the type
Stringwith a unique value. An easy way of generating a unique id is by generating a UUID.
The following example shows how to set the property for core API:
... ClientMessage message = session.createMessage(true); SimpleString myUniqueID = "This is my unique id"; // Can use a UUID for this message.setStringProperty(HDR_DUPLICATE_DETECTION_ID, myUniqueID); ...The following example shows how to set the property for JMS clients:
... Message jmsMessage = session.createMessage(); String myUniqueID = "This is my unique id"; // Could use a UUID for this message.setStringProperty(HDR_DUPLICATE_DETECTION_ID.toString(), myUniqueID); ...