【问题标题】:Sending message to queue in SingleActiveConsumer mode in MassTransit在 MassTransit 中以 SingleActiveConsumer 模式将消息发送到队列
【发布时间】:2021-10-19 15:39:50
【问题描述】:

我已经在 SingleActiveConsumer 模式下注册了接收端点。但是我找不到使用 sendEndpoint 将消息直接发送到队列的方法。我收到以下错误:

The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=406, text='PRECONDITION_FAILED - inequivalent arg 'x-single-active-consumer' for queue 'test' in vhost '/': received none but current is the value 'true' of type 'bool'', 

我尝试使用总线配置器设置标题“x-single-active-consumer”=true:

    var bus = Bus.Factory.CreateUsingRabbitMq(cfg =>
        {
            cfg.Host("localhost", "/", h =>
            {
                h.Username("guest");
                h.Password("guest");
            });
            cfg.ConfigureSend(a => a.UseSendExecute(c => c.Headers.Set("x-single-active-consumer", true)));
        });

直接在 sendEndpoint 上:

        await sendEndpoint.Send(msg, context => {
                context.Headers.Set("x-single-active-consumer", true);
                });

【问题讨论】:

    标签: rabbitmq masstransit


    【解决方案1】:

    如果您想直接发送到 MassTransit 中的接收端点,您可以改用短地址 exchange:test,它将发送到交换,而无需尝试创建/绑定队列到同名交换。这样,您就可以将队列配置与消息生产者分离。

    或者,您可以只使用Publish,让交换绑定将消息路由到接收端点队列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-02
      • 1970-01-01
      • 1970-01-01
      • 2011-08-20
      • 2013-11-15
      • 1970-01-01
      相关资源
      最近更新 更多