如何在配置连接时将 x-max-length 和 x-overflow 添加到 MassTransit 队列?
How to add x-max-length and x-overflow to MassTransit queue while configuring connection?
我有一个消费者,他需要从现有的 RabbitMQ 队列中消费消息。它工作正常,当队列正常配置时,没有任何设置。
services.AddMassTransit(config =>
{
config.AddConsumer<OrderConsumer>();
config.UsingRabbitMq((ctx, cfg) =>
{
cfg.Host("amqp://user:12345@localhost:54425");
cfg.ReceiveEndpoint("transient-order-queue", c =>
{
c.ConfigureConsumer<OrderConsumer>(ctx);
});
});
});
services.AddMassTransitHostedService();
为了完成一些工作,我需要使用一些功能配置队列。
Features
x-max-length: 1000
x-overflow: reject-publish
arguments:
x-queue-type: classic
durable: true
我如何配置我的消费者以连接到该队列?它给我这样的错误:
PRECONDITION_FAILED - inequivalent arg 'x-max-length' for queue 'transient-order-queue' in vhost '/': received none but current is the value '1000' of type 'long'
但我不明白如何将这些参数添加到 MassTransit 配置中。请帮帮我!
只需将它们添加为队列属性:
cfg.ReceiveEndpoint("transient-order-queue", c =>
{
c.QueueAttributes["x-max-length"] = 1000;
c.QueueAttributes["x-overflow"] = "reject-publish";
c.ConfigureConsumer<OrderConsumer>(ctx);
});
找到答案了。您可以使用以下语法将属性添加到队列:
cfg.ReceiveEndpoint("transient-order-queue", c =>
{
c.ConfigureConsumer<OrderConsumer>(ctx);
c.SetQueueArgument("x-overflow", "reject-publish");
c.SetQueueArgument("x-max-length", 1000);
});
我有一个消费者,他需要从现有的 RabbitMQ 队列中消费消息。它工作正常,当队列正常配置时,没有任何设置。
services.AddMassTransit(config =>
{
config.AddConsumer<OrderConsumer>();
config.UsingRabbitMq((ctx, cfg) =>
{
cfg.Host("amqp://user:12345@localhost:54425");
cfg.ReceiveEndpoint("transient-order-queue", c =>
{
c.ConfigureConsumer<OrderConsumer>(ctx);
});
});
});
services.AddMassTransitHostedService();
为了完成一些工作,我需要使用一些功能配置队列。
Features
x-max-length: 1000
x-overflow: reject-publish
arguments:
x-queue-type: classic
durable: true
我如何配置我的消费者以连接到该队列?它给我这样的错误:
PRECONDITION_FAILED - inequivalent arg 'x-max-length' for queue 'transient-order-queue' in vhost '/': received none but current is the value '1000' of type 'long'
但我不明白如何将这些参数添加到 MassTransit 配置中。请帮帮我!
只需将它们添加为队列属性:
cfg.ReceiveEndpoint("transient-order-queue", c =>
{
c.QueueAttributes["x-max-length"] = 1000;
c.QueueAttributes["x-overflow"] = "reject-publish";
c.ConfigureConsumer<OrderConsumer>(ctx);
});
找到答案了。您可以使用以下语法将属性添加到队列:
cfg.ReceiveEndpoint("transient-order-queue", c =>
{
c.ConfigureConsumer<OrderConsumer>(ctx);
c.SetQueueArgument("x-overflow", "reject-publish");
c.SetQueueArgument("x-max-length", 1000);
});