koalabruder
koalabruder

Reputation: 2904

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

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:

// 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?

Upvotes: 0

Views: 28

Answers (0)

Related Questions