RabbitMq队列声明参数详细解析

小Tips:

大家可以通过RabbitMQ的web插件查看本文中的大部分信息。

在这里插入图片描述
在这里插入图片描述
队列的声明的5个参数分别是:
1.队列名称
2.队列是否持久化
3.队列是否具有排他性(只有同一连接共享此队列,且连接断开时队列删除)排他队列详细说明
4.队列是否自动删除

自动删除是队列经历过至少一次连接后,所有的消费者都断开了连接,此时队列会进行自动删除。

5.封装队列的一些参数
Message TTL:
How long a message published to a queue can live before it is discarded. 一个消息被发布在队列里最多能存活的时间。

//通过设置队列的消息存活时间
Map<String, Object> args = new HashMap<String, Object>();
args.put("x-message-ttl", 60000);
channel.queueDeclare(QUEUE_NAME, false, false, false, args);
//也可以通过发布消息时,给消息绑定时间
byte[] messageBodyBytes = "Hello, world!".getBytes();
AMQP.BasicProperties properties = new AMQP.BasicProperties.Builder()
                                   .expiration("60000")
                                   .build();
channel.basicPublish("my-exchange", "routing-key", properties, messageBodyBytes);

如果俩者都设置了过期时间,那么会选择更小的那一个作为真正的消息存活时间
Auto expire:
How long a queue can be unused for before it is automatically deleted (milliseconds).
(Sets the “x-expires” argument.)
一个队列的存活时间

Queues will expire after a period of time only when they are not used (e.g. do not have consumers) 没有消费者后,进行倒计时。

Map<String, Object> args = new HashMap<String, Object>();
args.put("x-expires", 1800000);
channel.queueDeclare("myqueue", false, false, false, args);

Max length:

How many (ready) messages a queue can contain before it starts to drop them from its head.
(Sets the “x-max-length” argument.) 设置队列消息最大数。

Map<String, Object> args = new HashMap<String, Object>();
args.put("x-max-length", 10); //队列最多容下10条消息
channel.queueDeclare("myqueue", false, false, false, args);

Max length bytes:

Total body size for ready messages a queue can contain before it starts to drop them from its head.
(Sets the “x-max-length-bytes” argument.) 设置单条消息最长字节数(只针对消息体)

Map<String, Object> args = new HashMap<String, Object>();
args.put("x-max-length-bytes", 1024); //单条消息最长字节为1024字节
channel.queueDeclare("myqueue", false, false, false, args);

后面几个参数后面再补QAQ

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值