Use of exclusive + long queues for RabbitMQ

If I made a queue that is exceptional and durable (do not automatically delete). Now, if the consumer joins this line, then he drops. Then this queue is deleted.

I checked the scenario when the queue is only long-lasting (i.e. neither exclusive nor automatic). Now, if the consumer joins this line, then he drops. Then this queue is deleted.

Please explain the 1st case, the 2nd case gives the expected result. In both scenarios, only one consumer subscribes to one queue, and there is only one queue associated with one direct_exchange.

+5
source share
2 answers

, , , , , .

, , , , .

.

+15

, , . :

package rabbitmq.java.sample.exclusivequeue;

import java.io.IOException;

import com.rabbitmq.client.*;
import com.rabbitmq.client.AMQP.Queue.DeclareOk;

public class Producer {

    private final static String QUEUE_NAME = "UserLogin2";
    private final static String EXCHANGE_NAME = "user.login";

    /**
     * @param args
     */
    public static void main(String[] args) {
        ConnectionFactory factory=new ConnectionFactory();
        factory.setHost("CNCDS108");
        try {
            Connection conn = factory.newConnection();          
            Channel channel =conn.createChannel();
            DeclareOk declareOk = channel.queueDeclare(QUEUE_NAME, false, true, false, null);

            channel.basicPublish("", QUEUE_NAME, null, "Hello".getBytes());

            //close the channel, check if the queue is deleted
            System.out.println("Try to close channel");
            channel.close();
            System.out.println("Channel closed");

            System.out.println("Create a new channel");
            Channel channel2 =conn.createChannel();
            DeclareOk declareOk2 = channel2.queueDeclarePassive(QUEUE_NAME);

            **//we can access the exclusive queue from another channel
            System.out.println(declareOk2.getQueue()); //will output "UserLogin2"
            channel2.basicPublish("", QUEUE_NAME, null, "Hello2".getBytes());
            System.out.println("Message published through the new channel");**

//          System.out.println("Try to close Connection");
//          conn.close();
//          System.out.println("Connection closed");


        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
+6

All Articles