0

I have a mdb attached to a listener port of websphere which will read the message from the queue and persist it to database.

Now while sending a request using sessionBean, I added correlation id to the message.

msg.setJMSCorrelationId(theID);

My current MDB code is

onMessage(Message message) {
//it will read the message and insert to db
}

I want my MDB to only listen to the messages which will have the correlation id that i have set while sending the message.

Can someone please suggest how to do this?

V Joe
  • 271
  • 1
  • 5
  • 23
  • JMSCorrelationID in general should be unique, as it represents id of the message that you are responding to. In your case it should rather be custom message property like `myMessage.setStringProperty("NumberOfOrders", "2")` – Gas Mar 04 '15 at 12:18

1 Answers1

0

Use a message selector in your mdb's ejb-jar.xml. Message Selectors are used to receive only those messages that fulfill a certain criteria. Your criteria here is the correlation id which is a predefined field.

<activation-config-property>
            <activation-config-property-name>messageSelector</activation-config-property-name>
            <activation-config-property-value><![CDATA[JMSCorrelationID = 'value']]></activation-config-property-value>
        </activation-config-property>

Note : IMHO its a bad idea to set the correlation id as a message selector as each message usually has its own value in use cases where you need to use the JMS correlation id. You may end up needing an MDB per message :)

ramp
  • 1,256
  • 8
  • 14
  • so here is what i have done. While passing the correlationID im passing a hardcoded value ID:414243 using msg.setJMSCorrelationID im setting this value. Now as u said i added the above code in my xml file and instead of value used the above hardcoded value. In my MDB, i have added the code to lookup a particular queue and then used session.createReceiver(queue, messageSelector) where messageSelector is JMSCorrelationID='"ID:414243"' and then receiver.receive(50000). Still i am not able to read the message back. Am i missing something? – V Joe Mar 05 '15 at 11:07