0
votes

I have a question on how JMS is supposed to be used. Here's my case:

  • I have a queue with multiple consumers
  • A message gets sent to the queue - f.e. a "login" message
  • One of the consumers processes the message

Now I want to tell all my systems about the "login" message - i.e. that the user successfully logged in. What I'm currently doing is:

  • The consumer that processed the message sends a message to a Topic where everybody listens telling them "User x successfully logged in". Let's call this SUCCESS.

Now every system concerned knows that "user x has successfully logged in" due to the SUCCESS message. This is what I want.

However, if I understood JMS message delivery rules right, it is theoretically possible that a message to another topic/queue that relies on the fact that the receiving consumer knows that "user x logged in" could arrive before my SUCCESS message has been received. Even if it was sent after the session.send() call of the SUCCESS message. Is that right?

If so, how are you supposed to implement such a case with JMS?

Any help would be greatly appreciated!

1

1 Answers

2
votes

Is that right?

Unfortunately, yes.

If so, how are you supposed to implement such a case with JMS?

Two different approaches come to my mind:

  • simulate other network protocols - add ACKNOWLEDGE message that every system must sent when it receives SUCCESS message. ACKNOWLEDGE message would be sent to some dedicated topic, and messages that rely on the fact the receiving consumer knows that user x logged in cannot be sent until ACKNOWLEDGE message arrived from that consumer.

  • send both SUCCESS and further messages on same topic (if that's applicable; other consumers can ignore further messages if they aren't final destination), and give greater priority to SUCCESS message. That should (at least theoretically - JMS API doesn't require this!) guarantee that SUCCESS message arrived prior to messages that rely on the fact the receiving consumer knows that user x logged in. The method that should interest you in this case is Message#setJMSPriority