rabbitmq中的queueDeclare方法

rabbitmq中的queueDeclare方法
强烈推介IDEA2020.2破解激活,IntelliJ IDEA 注册码,2020.2 IDEA 激活码
queueDeclare
Queue.DeclareOk queueDeclare() throws IOException;

   /**
     * Declare a queue
     * @see com.rabbitmq.client.AMQP.Queue.Declare
     * @see com.rabbitmq.client.AMQP.Queue.DeclareOk
     * @param queue the name of the queue
     * @param durable true if we are declaring a durable queue (the queue will survive a server restart)
     * @param exclusive true if we are declaring an exclusive queue (restricted to this connection)
     * @param autoDelete true if we are declaring an autodelete queue (server will delete it when no longer in use)
     * @param arguments other properties (construction arguments) for the queue
     * @return a declaration-confirm method to indicate the queue was successfully declared
     * @throws java.io.IOException if an error is encountered
     */
    Queue.DeclareOk queueDeclare(String queue, boolean durable, boolean exclusive, boolean autoDelete,
                                 Map<String, Object> arguments) throws IOException;


queue :队列名称
durable : 是否持久化。true持久化,队列会保存磁盘。服务器重启时可以保证不丢失相关信息。
exclusive :设置是否排他。true排他的。如果一个队列声明为排他队列,该队列仅对首次声明它的连接可见,并在连接断开时自动删除。
排它是基于连接可见的,同一个连接不同信道是可以访问同一连接创建的排它队列,“首次”是指如果一个连接已经声明了一个排他队列,其他连接是不允许建立同名的排他队列,即使这个队列是持久化的,一旦连接关闭或者客户端退出,该排它队列会被自动删除,这种队列适用于一个客户端同时发送与接口消息的场景。

autoDelete :设置是否自动删除。true是自动删除。自动删除的前提是:致少有一个消费者连接到这个队列,之后所有与这个队列连接的消费者都断开 时,才会自动删除
生产者创建这个队列,或者没有消费者客户端与这个队列连接时,都不会自动删除这个队列

arguments :设置队列的一些其它参数。如
x-message-ttl,x-expires等。

queueDeclareNoWait方法
  void queueDeclareNoWait(String queue, boolean durable, boolean exclusive, boolean autoDelete,
                            Map<String, Object> arguments) throws IOException;

返回值为void,表示不需要服务端的任何返回,同样注意,在调用完
queueDeclareNoWait方法之后,紧接着使用声明的队列有可能会发生异常

queueDeclarePassive方法
/**
     * Declare a queue passively; i.e., check if it exists.  In AMQP
     * 0-9-1, all arguments aside from nowait are ignored; and sending
     * nowait makes this method a no-op, so we default it to false.
     * @see com.rabbitmq.client.AMQP.Queue.Declare
     * @see com.rabbitmq.client.AMQP.Queue.DeclareOk
     * @param queue the name of the queue
     * @return a declaration-confirm method to indicate the queue exists
     * @throws java.io.IOException if an error is encountered,
     * including if the queue does not exist and if the queue is
     * exclusively owned by another connection.
     */
    Queue.DeclareOk queueDeclarePassive(String queue) throws IOException;

这个方法用来检测队列是否存在,如果存在正常返回,不存在则抛出异常

与交换器对应也有删除方法


 Queue.DeleteOk queueDelete(String queue) throws IOException;
 
  Queue.DeleteOk queueDelete(String queue, boolean ifUnused, boolean ifEmpty) throws IOException;
  
      /**
     * Like {@link Channel#queueDelete(String, boolean, boolean)} but sets nowait parameter
     * to true and returns nothing (as there will be no response from the server).
     * @see com.rabbitmq.client.AMQP.Queue.Delete
     * @see com.rabbitmq.client.AMQP.Queue.DeleteOk
     * @param queue the name of the queue
     * @param ifUnused true if the queue should be deleted only if not in use
     * @param ifEmpty true if the queue should be deleted only if empty
     * @throws java.io.IOException if an error is encountered
     */
    void queueDeleteNoWait(String queue, boolean ifUnused, boolean ifEmpty) throws IOException;


queue: 队列名
ifUnused: 是否使用,true是否没有使用的才删除false,不管有没有使用都删除
ifEmpty :true 只有是空队列时才删除 ,false 无论如何都删除
queuePurge 清空队列

    /**
     * Purges the contents of the given queue.
     * @see com.rabbitmq.client.AMQP.Queue.Purge
     * @see com.rabbitmq.client.AMQP.Queue.PurgeOk
     * @param queue the name of the queue
     * @return a purge-confirm method if the purge was executed successfully
     * @throws java.io.IOException if an error is encountered
     */
    Queue.PurgeOk queuePurge(String queue) throws IOException;

 

本文来源huayang183,由架构君转载发布,观点不代表Java架构师必看的立场,转载请标明来源出处:https://javajgs.com/archives/18683

发表评论