rebus-org / Rebus.Async

:bus: Experimental async extensions for Rebus
https://mookid.dk/category/rebus
Other
13 stars 9 forks source link

Breaking change in 9.0 #23

Closed boskjoett closed 1 year ago

boskjoett commented 1 year ago

May I ask why you decided to remove the PublishRequest method in version 9.0? Maybe that should be mentioned in the CHANGELOG.

mookid8000 commented 1 year ago

Oh yeah sorry, I forgot to mention it in the changelog.

I removed it because I have never believed that "publishing a request" should be something anyone should ever have to do.

It raises too many questions. E.g. when you "publish" something, you should not care how many from 0..n subscribers receive the published event, when when you "publish a request" you would need only one single reply (at least that's how it works – if two subscribers were to reply, you would only receive the first).

If what you really want is to request something from multiple parties and then go with the one that anwers first, .NET has the nifty Task.WhenAny that can help you. Combined with the new explicit routing method, you can write code like this:

var routing = bus.Advanced.Routing;
var request = new SomeRequest();
var response = await Task.WhenAny(
    routing.SendRequest<SomeResponse>("service1", request),
    routing.SendRequest<SomeResponse>("service2", request),
    routing.SendRequest<SomeResponse>("service3", request)
);

and then response would simply contain the first response.

Are you using PublishRequest? And may I ask what for?

boskjoett commented 1 year ago

We were using PublishRequest, but now we use SendRequest. I agree that it is a better approach.

mookid8000 commented 1 year ago

Great! 🙂

Sorry for any inconvenience it may have caused.