pardahlman / RawRabbit

A modern .NET framework for communication over RabbitMq
MIT License
746 stars 144 forks source link

Perform multicast and gather results #292

Closed wicharypawel closed 6 years ago

wicharypawel commented 6 years ago

Hello pardahlman, I do have microservice architecture and want to send one message (that few microservices are listening to), gather results from all microservices.

I have nearly working code, which works when executed only ONCE.

Sender (System Fasade): await _busClient.PublishAsync(new GetVersionsCommand()); await _busClient.SubscribeAsync(@event => { // gather results return Task.CompletedTask; }); await Task.Delay(3000); // dont mind about this I am going to use TaskCompletitionSource return Ok(versionsEvents);

Receivers: Any Microservice code simply subscribes to GetVersionsCommand and respond with VersionsEvent.

Summarize: When I call sender (fasade) for the first time everything works beautifully. Second call and following that are executed on sender, call microservices but result messages coming from Microservices are lost.

Thank you for your help in advance.

Best regards Pablites

pardahlman commented 6 years ago

hello, @Pablites - are you calling SubscribeAsync from within an Controller? That can be troublesome, as that code will be run on each request, and a new subscription will be created for the message you are subscribing to. You can have a look at this project to see how I wire up subscriptions: https://github.com/pardahlman/RawRabbit.Todo. HTH!

pardahlman commented 6 years ago

Closing this now,. Feel free to re-open if you still have problems with this.