【发布时间】:2019-11-08 15:56:48
【问题描述】:
使用 .net rabbitmq 客户端 (https://www.rabbitmq.com/dotnet.html)。创建了一个库,其他项目可以引用该库以在总线上订阅/取消订阅/发布消息。
根据here 和here 提供的信息,为了让每个订阅者接收所有消息,每个客户端需要为每个订阅者定义一个不同的队列,绑定到交换器。我遇到的问题是如何在“客户端”应用程序使用队列完成后删除队列(因为这会成倍增长并且永远不会被清理)。
会在 Dispose 方法中吗?最好的方法是什么?
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
然后在客户端项目中我引用我的程序集并像这样使用总线:
var bus = serviceProvider.GetService<IEventBus>();
bus.Subscribe<CancelEventHandler, CancelEvent>();
...
bus.Publish(....);
【问题讨论】:
标签: c# .net rabbitmq rabbitmq-exchange