Working with .net rabbitmq client (https://www.rabbitmq.com/dotnet.html). Created a library that other projects can reference to subscribe/unsubscribe/publish messages on the bus.
Based on the info provided here and here, in order to have each subscriber receive all messages, each client needs to define a different queue per subscriber, bound to the exchange. The issue I'm having is how to remove queues after the "client" app is done using the queue (as this would grow exponentially and never get cleaned up).
Would it be in Dispose method? What would be the best approach?
public interface IEventBus
{
void Publish(DomainEvent @event);
void Subscribe<TH, T>()
where TH : IEventHandler<T> where T : DomainEvent;
void Unsubscribe<TH, T>()
where TH : IEventHandler<T> where T : DomainEvent;
}
public class EventBus : IEventBus, IDisposable
{
....//implementation
// dispose connection/channel etc
Then in the client project I reference my assembly and use the bus like so:
var bus = serviceProvider.GetService<IEventBus>();
bus.Subscribe<CancelEventHandler, CancelEvent>();
...
bus.Publish(....);