문제

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.

도움이 되었습니까?

해결책

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();
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top