🎄 Happy Holidays! 🥳
Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.
Happy Holidays!
Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.
How can we receive multiple replies for a single request?
I'm implementing the pubsub+ request-reply pattern where I need to receive multiple records as a reply for a particular request but, I'm receiving just one record as a reply per request after which the session exits.
Can someone suggest what can be done for this.
Reference - https://tutorials.solace.dev/jcsmp/request-reply/
Answers
-
Hello @riddhisurve, the way the BasicRequestor sample works is to send a blocking request. It waits for the reply, or times out, then exits. This isn't normally the way you'd do things: you send the request, wait for the reply, then send more requests or wait for something else to happen.
Given you are waiting for multiple replies to a single request, you'd be better off moving to a non-blocking request-reply model. Here, we tag the outgoing request with a correlation identifier, so that when the response comes back you can work out which request it relates to. When you receive multiple replies you can then simply correlate them via the correlation ID.
To summarise:
- Add a correlationID to the request with setCorrelationId.
- Use a non-blocking request send: set request(..., timeout,...) timeout to 0.
- In the repliers, reply to the message remembering to set the correlationID
- In the requestor, you'll be getting multiple replies asynchronously, so set up XMLMessageConsumer or its XMLMessageListener for replies.
- Use getCorrelationID on the replies to determine which request the reply corresponds to.
- Don't allow your application to exit until you're happy all the responses have been received.
2 -
Hey @TomF I do have XMLMessageConsumer running.
It seems the "reply = requestor.request(request, timeoutMs, topic)" statement receives just one reply after sending the request and exits. Thus the rest of the sendReply calls from the replier seems to get lost as there is no variable receiving it.
For me to receive all the records I have to hit the above statement again and again which will be the wrong way of doing it.0 -
@riddhisurve yes you're right, I forgot a key step! requestor.request will return after one response. What you need to do is specify a "Reply-To" topic using .setReplyTo() in your outgoing request. You then need to subscribe to this Reply To topic so your XMLMessageConsumer gets the extra responses.
To make the code more logical, you might want to consider removing the requestor completely and publish the request as a message using XMLMessageProducer, then dealing with the responses via the Reply To subscription.
1 -
+1 for this; I think leaving the "requestor" could be confusing.
To make the code more logical, you might want to consider removing the requestor completely and publish the request as a message using XMLMessageProducer, then dealing with the responses via the Reply To subscription.
0