在masstransse中以SingleActiveConsumer模式向队列发送消息



我已经在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'', 

我尝试使用总线配置器设置header "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);
});

如果您想直接发送到MassTransit中的接收端点,您可以使用短地址exchange:test代替,它将发送到交换,而无需尝试创建/绑定具有相同名称的交换队列。这样,您就可以将队列配置与消息生成器解耦。

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

最新更新