【问题标题】:Connect to existing RabbitMQ queue using MassTransit problem使用 MassTransit 问题连接到现有 RabbitMQ 队列
【发布时间】:2020-07-30 11:05:00
【问题描述】:

我已预先设置 RabbitMQ 配置:Exchange-1、Queue-1,使用路由密钥“notifications.info”进行绑定。我想使用 MassTransit 连接到现有的 Queue-1。

var busControl = Bus.Factory.CreateUsingRabbitMq(cfg =>
{
    cfg.Host("rabbitmq://guest:guest@localhost");


    cfg.ReceiveEndpoint("Queue-1", e =>
    {
        e.ConfigureConsumeTopology = false;

        e.Consumer<EventConsumer>();
        e.Bind("Exchange-1", x =>
        {
            x.Durable = false;
            x.AutoDelete = false;
            x.ExchangeType = ExchangeType.Topic;
            x.RoutingKey = "notifications.info";
        });
    });
});

错误:

The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=406,
text='PRECONDITION_FAILED - inequivalent arg 'durable' for exchange 'Queue-1' in vhost '/':
received 'true' but current is 'false'', classId=40, methodId=10

MassTransit 创建交换“Queue-1”。我不需要在 RabbitMQ 创建额外的实体。有任何禁用它的选项吗?

有用的信息

bash-5.0# rabbitmqctl list_exchanges name type durable auto_delete internal arguments policy
name    type    durable auto_delete     internal        arguments       policy
Exchange-1      topic   false   false   false   []
Queue-1 fanout  false   false   false   []

bash-5.0# rabbitmqctl list_queues name durable auto_delete arguments exclusive
name    durable auto_delete     arguments       exclusive
Queue-1 false   false   [{"x-queue-type","classic"}]    false

【问题讨论】:

    标签: rabbitmq masstransit


    【解决方案1】:

    没有禁用它的选项,这是 MassTransit 为接收端点(交换和队列同名)配置拓扑的方式。

    该错误实际上是因为交换已经存在并且与您的接收端点配置不匹配。

    这个小改动应该可以修复错误:

    cfg.ReceiveEndpoint("Queue-1", e =>
    {
        e.ConfigureConsumeTopology = false;
    
        // since your queue is non-durable
        e.Durable = false;
    
        e.Consumer<EventConsumer>();
        e.Bind("Exchange-1", x =>
        {
            x.Durable = false;
            x.AutoDelete = false;
            x.ExchangeType = ExchangeType.Topic;
            x.RoutingKey = "notifications.info";
        });
    });
    

    【讨论】:

    • 感谢您的回答。那么改变 lib 的最佳解决方案是什么,比如说 EasyNetQ?
    • 更新了答案,向您展示如何使用不等价参数解决问题。至于你选择的图书馆,这取决于你。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多