首页 > 其他分享 >rabbitmq中的queueDeclare方法

rabbitmq中的queueDeclare方法

时间:2023-05-25 20:05:53浏览次数:34  
标签:Queue queueDeclare 队列 rabbitmq queue boolean IOException 方法 throws


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;

 

标签:Queue,queueDeclare,队列,rabbitmq,queue,boolean,IOException,方法,throws
From: https://blog.51cto.com/chengzheng183/6350780

相关文章

  • RabbitMQ消费消息方法basicConsume
    RabbitMQ-消费消息 Address[]addresses=newAddress[]{newAddress(IP_ADDRESS,PORT)};/***1.建立连接工厂*/ConnectionFactoryconnectionFactory=newConnectionFactory();connectionFactory.setUsername(USER_NAME);......
  • 关于linux系统中umask值的说明-以及计算转换成默认权限符号的方法
    关于linux系统中的umask值,我们可以通过man手册的解释为:Theuserfile-creationmaskissettomode简单的理解,就是用户的umask的值决定着文件(也包括目录)创建时的默认权限,对于root用户来说,一般为0022[root@qq-5201351~]#umask0022这样可能还是不能很直观的表达出,可以通过......
  • JAVA List和Map切割方法
    importorg.springframework.util.CollectionUtils;importjava.util.ArrayList;importjava.util.HashMap;importjava.util.Iterator;importjava.util.List;importjava.util.Map;importjava.util.Set;publicclassCollectionUtil{/***将map切成段,作......
  • 恒创科技:5种易实现的Linux和 Windows VPS速度提升方法
    ​无论是LinuxVPS还是WindowsVPS,网站速度的提高都是非常重要的。它们在提高网站速度方面都有很多的优化方法。下面我们将介绍5种提高网站速度的方法。1.通过缓存加速缓存通常是用来加快商业网站加载时间的技术,因此它也可以用在VPS上。没有它,不断的静态文件请......
  • RabbitMQ之消息确认机制
    RabbitMQ之消息确认机制标签(空格分隔):php,rabbitmq在使用RabbitMQ的时候,我们可以通过消息持久化操作来解决因为服务器的异常奔溃导致的消息丢失,除此之外我们还会遇到一个问题,当消息的发布者在将消息发送出去之后,消息到底有没有正确到达broker代理服务器呢?如果不进行特殊配置的话......
  • Windows系统下设置cmd命令行(终端)走代理的方法
     根据代理软件查看对应端口号(因为可能不是缺省端口号) 这里我本地代理的端口号是10792,下一步设置记得修改端口号与此对应。#有些朋友好像为什么设置http和socket5其实设置哪种都是可以的,具体看你们自己代理软件都支持的协议有哪些,就可以了#记得修改端口号,比如我的是10792,记......
  • Python集合 (set) 的增删改查及 copy()方法
    集合是无序的,不重复的数据集合,它里面的元素是可哈希的(不可变类型),但是集合本身是不可哈希(所以集合做不了字典的键)的。以下是集合最重要的两点:1、去重,把一个列表变成集合,就自动去重了。2、关系测试,测试两组数据之前的交集、差集、并集等关系。一、集合的创建set1=set({1,2......
  • 0-1背包问题详解-动态规划-两种方法
    问题描述:给定n种物品和一背包。物品i的重量为wi,其价值为vi,背包容量为c。问应如何选择装入背包中的物品,使得背入背包的物品的总价值最大?解析:此问题形式化的描述是,给定c>0,wi,vi,1<=i<=n(c为背包容量),要找出一个n元0-1向量(x1,x2,...,xn),xi ∈{0,1},1<=i<=n,使......
  • 流水调度问题-动态规划-Johnson法则-两种方法
    问题描述:n个作业{0,1,2,…,n}在2台机器上M1和M2组成的流水线上完成加工。每个作业加工的顺序都是先在M1上加工,后在M2上加工。在两台机器上加工的时间分别为ai和bi。 确定这n个作业的加工顺序,使得从第一台作业开始加工,到最后一个作业完成加工所需要的时间最少。 递归关......
  • MySQL——2.数据库的安装及配置(亲测有效)及启动MySQL服务的两种方法
    安装文件的mysql-installer-community-8.0.3.0-rc.msi的链接:https://pan.baidu.com/s/1G-hO_IlhlFqVuhO_mHjKzA密码:emhm目录文章目录一、数据库的安装及配置步骤1.下载后,双击msi文件安装。2.打勾,点击Next3.选择server,点击Next4.点击Execute按钮5.点击Next按钮。6.点击Next按钮。......