問題描述
有沒有辦法抑制 ActiveMQ 服務(wù)器上定義的隊列上的重復(fù)消息?
Is there a way to suppress duplicated messages on a queue defined on ActiveMQ server?
我嘗試手動定義 JMSMessageID,(message.setJMSMessageID("uniqueid")),但服務(wù)器忽略了這個修改并使用內(nèi)置生成的 JMSMessageID 傳遞消息.
I tried to define manually JMSMessageID, (message.setJMSMessageID("uniqueid")), but server ignores this modification and deliver a message with built-in generated JMSMessageID.
按照規(guī)范,我沒有找到有關(guān)如何刪除重復(fù)消息的參考.
By specification, I didn't found a reference about how to deduplicate messages.
在 HornetQ 中,為了處理這個問題,我們需要在消息定義中聲明 HQ 特定的屬性 org.hornetq.core.message.impl.HDR_DUPLICATE_DETECTION_ID.
In HornetQ, to deal with this problem, we need to declare the HQ specific property org.hornetq.core.message.impl.HDR_DUPLICATE_DETECTION_ID on message definition.
即:
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);
有人知道 ActiveMQ 是否有類似的解決方案?
Somebody knows if there's a similar solution for ActiveMQ?
推薦答案
你應(yīng)該看看 Apache Camel,它提供了一個可以與任何 JMS 提供者一起工作的冪等消費者組件,請參閱:http://camel.apache.org/idempotent-consumer.html
You should look at Apache Camel, it provides an Idempotent consumer component that would work with any JMS provider, see: http://camel.apache.org/idempotent-consumer.html
將它與 ActiveMQ 組件結(jié)合使用使得 JMS 的使用變得非常簡單,請參閱:http://camel.apache.org/activemq.html
Using that in combination with the ActiveMQ component makes using JMS quite simple, see: http://camel.apache.org/activemq.html
這篇關(guān)于避免 JMS/ActiveMQ 上的重復(fù)消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!