Question

I am running a cluster(node 1 & node 2) with 2 Application. App A and App B.

  1. App A will send Messages to JMS queue Q(That will be distribute across node 1 & 2).
  2. App B will listen from the queue, process and Send a message back to the Q(This is also will be distributed).

So I want the App B sending message to same node where it receives.How can we achieve this ?

Code/configuration. How ?

Thanks in advance.

Was it helpful?

Solution

You can set the String property on the message depending on which node you intend to deliver it to.

        TextMessage textmsg1 = qs.createTextMessage();
        textmsg1.setStringProperty("SentToNode","Node1");

(If it delivers each message to both the nodes then you can simply make appB send messages to both nodes which makes no sense so ignoring this case).

Now on the receiver end (Your App B) which is listening to this queue you can retrieve this property and take appropriate actions.

@Override
public void onMessage(Message message) {
    try {
        count++;
        TextMessage msg = (TextMessage) message;
        System.out.println("Message Received " + msg.getText());
        System.out.println("Message received from " + msg.getStringProperty("SentToNode"));
        //now you can send the message to that node

    } catch (JMSException e) {
        e.printStackTrace();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top