0

I have one thread that is waiting in a message queue. Let's call it THFS.

Other threads send messages to this queue, asking for some operations.

These operations need a response. I'm not sure what is the best way to put this response. At first, I thought of putting it in another message queue, but I was not sure how to do it so that the response can link to the correct request. For example, TH1 put msg1, TH2 puts msg2 and they wait for their own response. Then THFS receives these messages and executes the operations requested,then it has to send back the answers.

How to be sure that TH1 and TH2 will receive the answer intended for them?

1
  • Do you use custom queueing? In addition to the general publish/subscribe paradigm, many standard message queuing platforms support request/response. Commented Sep 28, 2024 at 20:40

1 Answer 1

0

The standard approach is to use a correlationID. So the design looks like:

  • Keep a map of callbacks/futures using the correlationID as a key.
  • Before sending a msg1 generate a correlationID and put this ID into the message (or its header). Put the message into the map.
  • The code that responds to msg1 must include the correlationID in the response message.
  • The code that receives a message from the response queue looks up the callback/future by the correlationID and calls it.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.