gpt4 book ai didi

.net - EasyNetQ 模型关闭

转载 作者:行者123 更新时间:2023-12-02 22:11:12 25 4
gpt4 key购买 nike

我使用 EasyNetQ 为 RabbitMQ 实现了一个简单的客户端。连接后,我收到通知“队列模型关闭”。这是我的代码:

var _bus = RabbitHutch.CreateBus(String.Format("host={0}", hostName)).Advanced;
var _exchange = Exchange.DeclareFanout(exName);
var _queue = Queue.DeclareTransient();
_queue.BindTo(_exchange, "_");
_bus.Subscribe(
_queue,
(msg, properties, messageReceivedInfo) =>
{
return Task.Factory.StartNew(() =>
{
Console.WriteLine(msg.Length.ToString());
});
});

使用更底层的方法,一切都很好(消息长度显示在控制台中):

var factory = new ConnectionFactory();
factory.HostName = hostName;
var connect = factory.CreateConnection();
var channel = connect.CreateModel();
channel.ExchangeDeclare(exName, "fanout");
var resultQueue = channel.QueueDeclare(string.Empty, false, true, false, null);
string queueName = resultQueue.QueueName;
var consumer = new QueueingBasicConsumer(channel);
channel.QueueBind(queueName, exName, string.Empty);
var resultConsume = channel.BasicConsume(queueName, false, consumer);
while(true)
{
var e = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
Console.WriteLine(e.Body.Length.ToString());
channel.BasicAck(e.DeliveryTag, false);
}

请提示,第一种方法有什么问题?

UPD我用 IntelliTrace 捕获了异常:

The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=406, text="PRECONDITION_FAILED - cannot redeclare exchange 'live' in vhost '/' with different type, durable, internal or autodelete value", classId=40, methodId=10, cause=

交换设置相同(见上文)。那怎么了?

最佳答案

我遇到了同样的问题,直到我添加了我在通过 RabbitMQ Management web interface 创建队列时已经设置的参数。 , 作为 Mike Hallow said .

    var arguments = new Dictionary<string, object>( 2 );
arguments.Add( "x-message-ttl", 900000 );
arguments.Add( "x-dead-letter-exchange", "deadLetter" );
this.requestMessageQueue = Queue.Declare( true, false, false, this.messageQueueConfiguration.RequestMessageQueueName, arguments );

您可以检查通过 RabbitMQ 管理 Web 界面设置的现有参数。


recent code change , 直接设置参数的唯一方法是通过 Management API ,除非您只使用每个队列 ttl (x-message-ttl) 或过期 (x-expires),在这种情况下您可以使用 Advanced API .

关于.net - EasyNetQ 模型关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15290541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com