EasyNetQ模型关闭 [英] EasyNetQ model shutdown

查看:120
本文介绍了EasyNetQ模型关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用EasyNetQ实现了RabbitMQ的简单客户端.建立连接后,我收到通知队列的模型关闭" .这是我的代码:

I implement a simple client to RabbitMQ, using EasyNetQ. After a connection, I get a notification "Model shutdown for queue". Here is my code:

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());
  });
 });

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

Using more low-level approach, everything works great (the message length is displayed in the console):

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);
}

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

Please, prompt, what's wrong in the first approach?

UPD 我用IntelliTrace捕获到异常:

UPD I caught Exception with IntelliTrace :

AMQP操作被中断:AMQP关闭原因,由 对等体,代码= 406,文本="PRECONDITION_FAILED-无法重新声明交换 在虚拟主机'/'中的'live',具有不同类型,持久性,内部或 自动删除值",classId = 40,methodId = 10,cause =

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=

Exchange设置相同(请参见上文).那怎么了?

Exchange settings are the same (see above). So what's wrong?

推荐答案

我遇到了同样的问题,直到添加了通过 Mike Hallow所说.

I had the same problem until I added the parameters that I had already set up when I created the queue via RabbitMQ Management web interface, as 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界面设置的现有参数.

You can check the existing parameters that are set via the RabbitMQ Management web interface.

由于最近的代码更改,直接设置参数的唯一方法是通过 Management API ,除非您仅使用每个队列ttl(x-message-ttl)或过期(x过期),在这种情况下,您可以使用

Since the recent code change, the only way to set arguments directly is through the Management API, unless you are only using per queue ttl (x-message-ttl) or expires (x-expires) in which case you can use the Advanced API.

这篇关于EasyNetQ模型关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆