开发者

Exception with creating a RabbitMQ server with the C# library

I've got a console application that starts up the RabbitMQ server (as an app using the rabbitmq-server.bat file) and then attempts to create a queue on top of it and begin listening for messages. The broker starts up fine but once I try to declare the queue I get an exception stating the queue name doesn't exist. I'm a bit confused at this since I'm trying to create the queue, and don't know why it is looking for an existing one with that name.

Here's the code I'm using to run the server:

var model = QueueModelFactory.CreateModel();
model.ExchangeDeclare(exchangeName, ExchangeType.Fanout, true);
model.QueueDeclare(QueueName, false, false, false, null);
model.QueueBind(QueueName, exchangeName, "");

var subscription = new Subscription(model, QueueName, false);

while (true)
{
    var args = subscription.Next();
    ProcessQueueItem(args.Body);
    subscription.Ack(args);
}

The exception happens on the line the calls QueueDeclare. The exact exception that I get is:

"The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=404, text="NOT_FOUND - no queue 'FavorCompletions' in vhost '/'", classId=50, methodId=10, cause=".

I had this working at one point and then refactored some code only to have it break. I have no clue what I'm doing wrong, since all the sample apps seem to do the exact same thing.

Any help would be appreciated开发者_开发知识库.


Not knowing what is in your QueueModelFactory code for CreateModel() and looking at the rest of the code the use of ExchangeDeclare, QueueDeclare and QueueBind they seem fine.

All I can suggest is there's an issue with how you go about creating a connection / model.

Substituting your

var model = QueueModelFactory.CreateModel();

with :

IModel model = new ConnectionFactory { Address = "127.0.0.1" }
    .CreateConnection()
    .CreateModel();

Seems to kick off and not cause that exception.

I have experienced your exception before, but haven't narrowed the exact cause of it, in one of my cases I made a mistake in declaring the exchange model.ExchangeDeclare() portion, so that's an area to look at too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜