rebus-org / Rebus

:bus: Simple and lean service bus implementation for .NET
https://mookid.dk/category/rebus
Other
2.31k stars 361 forks source link

Request/reply or Sagas is the way to use Rebus with MVC where we wait for the distributed task result? #845

Closed Andras-Csanyi closed 4 years ago

Andras-Csanyi commented 4 years ago

Hi,

I have been struggling integrating request/reply pattern into my WebApi controllers. Following the example here, the controller is the producer and there is a workerservice as consumer. The problem I face to is that, the controller doesn't wait (this is the right thing, but gives me problems) for the worker to finish and publish its task, so the controller returns with null. Remembering what I did with NServiceBus a few years ago, we need a callback function here. But, I haven't found anything similar in the samples.

The case:

My question, do we have any callback functionality in Rebus, similar to NServiceBus, or I should use Saga for this purpose? Or what is the right thing to do? If its possible I don't want to go to CQRS direction, because SignalR will come into picture which is another complexity. (TBH I might already overengineered the whole stuff :D, but it is a pet project, in this case overengineering is kind of the right thing to do :D )

mookid8000 commented 4 years ago

You might want to take a look at Rebus.Async, which is a "synchronous API" for Rebus (in quotes, because it's actually Task-based and async, but it's synchronous in the sense that it can send a request and wait for a corresponding reply.

With it, your controller will be able to do something like this:

SomeReply reply = await _bus.SendRequest<SomeReply>(new SomeRequest());