简体   繁体   English

如何/何时删除 RabbitMQ .net 客户端中的队列

[英]How / When to remove queues in RabbitMQ .net Client

Working with .net rabbitmq client ( https://www.rabbitmq.com/dotnet.html ). 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?它会在 Dispose 方法中吗? 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(....);

You're looking for an Exclusive/Autodelete queue.您正在寻找独占/自动删除队列。 By definition, such a queue can only be accessed by the client that created it- and when the client disconnects, the queue is instantly removed.根据定义,这样的队列只能由创建它的客户端访问 - 当客户端断开连接时,队列会立即删除。 These are useful for cases where you set up a consumer to subscribe to a topic, and you don't actually need messages to be enqueued on the server.这些对于您设置消费者来订阅主题的情况很有用,并且您实际上不需要在服务器上排队消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM