0

The following is the exception i receive .Net core and rabbitMQ : The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=405, text='RESOURCE_LOCKED - cannot obtain exclusive access to locked queue 'demo-queue' in vhost '/'. It could be originally declared on another connection or the exclusive property value does not match that of the original declaration.', classId=50, methodId=10

enter image description here

Producer :

var factory = new ConnectionFactory
        {

            Uri = new Uri("amqp://guest:guest@localhost:5672")

        };

        using var connection= factory.CreateConnection();   
        using var channel=  connection.CreateModel();
        channel.QueueDeclare("demo-queue",durable:true,exclusive:true,autoDelete:false, arguments:null);
        var message = new
        {
            Name = "Producer",
            Message = "Hello!"
        };
        var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message));


        channel.BasicPublish("", "demo-queue",null,body);

Consumer:

  var factory = new ConnectionFactory
        {

            Uri = new Uri("amqp://guest:guest@localhost:5672")

        };

        using var connection = factory.CreateConnection();
        using var channel = connection.CreateModel();
        channel.QueueDeclare("demo-queue", durable: true,
            exclusive: true, autoDelete: false,
            arguments: null);
        var consumer = new EventingBasicConsumer(channel);
        consumer.Received += (sender, e) =>
         {
             var body = e.Body.ToArray();
             var message = Encoding.UTF8.GetString(body);
             Console.WriteLine(message);
         };


        channel.BasicConsume("demo-queue",true,consumer);

Is it the right practice or right way IF I Change the name of the queue that I have given in producer or consumer? which is the right way to handle this?

1
  • Can you check in the rabbitmq dashboard that your queue is linked with the exchange? Commented Nov 29, 2022 at 7:24

2 Answers 2

3

In the QueueDeclare section, you said properties that are different from the queue you created.

Edit:

All your mistakes are in this line of code. Because you created a queue. Now you want to open it with the wrong properties. I think exclusive: false will solve the problem

//channel.QueueDeclare("demo-queue",durable:true,exclusive:true,autoDelete:false, arguments:null);

  channel.QueueDeclare(queue: "demo-queue",
                       durable: true,
                       exclusive: false,
                       autoDelete: false,
                       arguments: null);
Sign up to request clarification or add additional context in comments.

4 Comments

Is it not required for both producer and consumer queues to have same names?
@SubashreeKrishnan I edited the answer. I hope your problem is solved.
I changed the exclusive to false in both it worked
@SubashreeKrishnan If my answer was correct, please select it as the correct answer to the question
1

Exchange and queu need to be connected. If you do not do this, the message cannot know the queue address it will go to. After QueueDeclare, it must be bind with the exchange address. I have implemented it this way. If you want, you can look at the repo I created here. https://github.com/oguzhanKomcu/RabbitMQ_Sample

I think this is the missing function.

public void BindQueu(string exName, string queuName, string routingKey)
     {
             channel.QueueBind(queuName,exName, routingKey);
     }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.