2

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?

Brain89
  • 460
  • 1
  • 4
  • 17

2 Answers2

3

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.

Community
  • 1
  • 1
WhiteKnight
  • 4,938
  • 5
  • 37
  • 41
2

Are you disposing your _bus soon after doing the subscribe? That would close the subscription channel.

Mike Hadlow
  • 9,427
  • 4
  • 45
  • 37
  • No, I'm not disposing the **_bus** after subscribing – Brain89 Mar 09 '13 at 12:12
  • I've tried running your example code. I only get "Model Shutdown for queue' when I dispose the _bus, otherwise it works fine. – Mike Hadlow Mar 11 '13 at 16:02
  • I have updated the question. Could you give me any advice now? – Brain89 Mar 13 '13 at 07:58
  • 1
    The problem is exactly as described in the error message. You are redeclaring the exchange with different parameters. If you first delete your existing exchange (it might be a good idea to clear everything - all exchanges and queues), it will work fine. – Mike Hadlow Mar 13 '13 at 09:21
  • Unfortunately, there is no way to remove exchange (or change anything in server-side). Is there any other option? If I'm right I catch this error because of exchange is non-durable – Brain89 Mar 13 '13 at 11:35
  • You can delete exchanges using the C# Client library: http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v3.0.4/rabbitmq-dotnet-client-3.0.4-client-htmldoc/html/type-RabbitMQ.Client.IModel.html#method-M:RabbitMQ.Client.IModel.ExchangeDelete(System.String) – Mike Hadlow Mar 14 '13 at 13:15
  • I need to connect to an existing exchange. I can't remove it because the other subscribers use it too. – Brain89 Mar 19 '13 at 07:35