Jms: Pub/Sub with mutiple consumers

143 Views Asked by At

For JMS pub/sub with a topic and two durable subscribers, in most cases when a message is sent to the topic we want the message to be consumed by both subscribers.

But in a particular scenario we may want want the message to be consumed by only a particular subscriber. Is that possible and can it be done? We are using OracleAQ with Spring Boot.

1

There are 1 best solutions below

0
On

You can use message selectors.

Simply add a property to the message that you then filter in the consumer.

Producer

Message msg = ...

// Setting message properties
msg.setStringProperty("releaseYear", "1977");

Consumer

MessageConsumer consumer = session.createConsumer(queue, "releaseYear < 1980");

Read more here: https://docs.oracle.com/cd/A87860_01/doc/ois.817/a65435/jms_feat.htm#1001827