How can my controller action wait and respond the result of my message driven workflow?

25 Views Asked by At

I have a legacy client and a WebApi with the controller action ArticleController.AddArticle(). The action ArticleController.AddArticle() receives a request and returns a response. In between there is a message driven workflow. At the end of the workflow there is a result message. The action ArticleController.AddArticle() should return the result message.

The workflow looks sth. like this:

  • Client sends HTTP Request to ArticleController.AddArticle()
  • ArticleController.AddArticle() sends message to CalcA
  • CalcA sends message to CalcB
  • CalcB sends message to ArticleController.AddArticle()
  • ArticleController.AddArticle() sends HTTP Response to client
// Pseude code
[HttpPost()]
public async Task<ResultMessage> PostAsync()
{
    await _bus.Publish(/*...*/);
    // Message driven workflow
    var resultMessage = await _bus.SubscribeAndWaitOn<ResultMessage>(/*...*/);
    return resultMessage;
}

How can I let the action wait for the result message?

I am using .NET with MassTransit and RabbitMQ. I have found the request/response pattern (https://masstransit.io/documentation/concepts/requests) and it works for a simple message. But is this the right way for large workflows?

0

There are 0 best solutions below