How can I prevent receiving JMS messages that I have produced?
Here's the scenario. I have a legacy system with two parts, Part A and Part B, that send messages to each other in a sort of client/server fashion. I've created an adapter that translates these messages into another format for use in a new system. The messa开发者_开发百科ges are published on multiple JMS topics. The adapters also listen to these same topics. However, because both adapters are identical and running on each Part of the legacy system, I'm obviously going to be receiving the same messages that I'm sending out.
Is there an elegant way to filter incoming messages that are the same messages I sent out, other than assigning a "message source" with a unique ID for each adapter and filtering on that?
Thanks for your help!
You need to specify that your subscribers ignore local messages. This can be specified in:
- javax.jms.TopicSubsciber.createSubscriber(Topic topic, String messageSelector, boolean noLocal)
- javax.jms.TopicSubsciber.createDurableSubscriber(Topic topic, String messageSelector, boolean noLocal)
- javax.jms.Session.createDurableSubscriber(Topic topic, java.lang.String name, java.lang.String messageSelector, boolean noLocal)
- javax.jms.Session.createDurableSubscriber(Topic topic, java.lang.String name, java.lang.String messageSelector, boolean noLocal)
- javax.jmx.Session.createConsumer(Destination destination, String messageSelector, boolean noLocal)
The key part is the noLocal which when set to true will ignore messages sent from the same javax.jms.Connection. From the subscriber's perspective, they do not exist.
精彩评论