问题
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 I caught Exception with 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=
Exchange settings are the same (see above). So what's wrong?
回答1:
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 );
You can check the existing parameters that are set via the RabbitMQ Management web interface.
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.
回答2:
Are you disposing your _bus soon after doing the subscribe? That would close the subscription channel.
来源:https://stackoverflow.com/questions/15290541/easynetq-model-shutdown