0
votes

I have the following scenario, where i can not respond directly to the request of a MassTransit RequestClient

  • Request Service 1 implementing a RequestClient and calling GetResponse
  • Another service 2 have the consumer of the request that just save the request information (messageId, requestId ...) to some storage and not send a response back.
  • Based on an API call in service 2, we can find the saved request information and send back the response to the RequestClient. I could achive this by sending the response to the temporaty queue of the RequestClient bus but the message ends up in the skipped queue of the temporary queue and GetResponse never gets the message.

How can i make the message arrives to the main temporary queue, and that the GetResponse consumer find it.

1
Did you save the ResponseAddress from the original request, and use that to send the response, including the RequestId header? A complex example is in the source code, but you need to set properties on the SendContext so that the message is correlated back to the request client. - Chris Patterson
Yes, i have saved the ResponseAddress and use it to send the response, i included the same RequestId in the send. I will try with populating rest of properties of the context. Thanks for pointing the right place to look in code. - Mohamed Ben Dhaou
Will it be an option to use the existing RequestStateMachine where i publish a RequestStarted from the consumer and RequestCompleted from the API controller. - Mohamed Ben Dhaou
In the future? I don't know. I honestly can't remember what I was adding with that state machine, probably something related to Conductor. - Chris Patterson

1 Answers

0
votes

If anyone has a similar scenario. We achived this by implementing an event waiter mechanism in the consumer. When the external API call is made in service 2, an internal event is fired then consumer who is waiting for it through ResetEvent continue by gathering the response and send it back through out of the box RespondAsync.