我是靠谱客的博主 孤独白开水,这篇文章主要介绍RabbitMQ学习笔记:队列容量设置(x-max-length、x-max-length-bytes、x-overflow),现在分享给大家,希望可以做个参考。

rabbitmq可以设置队列的最大长度、队列最大容量及溢出后的处理逻辑

Max length
复制代码
1
2
3
How many (ready) messages a queue can contain before it starts to drop them from its head. (Sets the "x-max-length" argument.)

即:设置队列中可以存储处于ready状态消息的数量

复制代码
1
2
3
4
5
/** * queue中可以存储处于ready状态的消息数量 */ arguments.put("x-max-length", 6);
Max length bytes
复制代码
1
2
3
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.)

即:队列中可以存储处于ready状态消息占用内存的大小(只计算消息体的字节数,不计算消息头、消息属性占用的字节数)

复制代码
1
2
3
4
5
/** * queue中可以存储处于ready状态的消息占用的内存空间,单位:字节 */ arguments.put("x-max-length-bytes", 1024);
Overflow behaviour
复制代码
1
2
Sets the queue overflow behaviour. This determines what happens to messages when the maximum length of a queue is reached. Valid values are drop-head, reject-publish or reject-publish-dlx. The quorum queue type only supports drop-head.

即:队列的处于ready状态存储消息的个数或消息占用的容量超过设定值后的处理策略

复制代码
1
2
3
4
5
6
7
8
9
10
/** * queue溢出行为,这将决定当队列达到设置的最大长度或者最大的存储空间时发送到消息队列的消息的处理方式; * 有效的值是: * drop-head(删除queue头部的消息)、 * reject-publish(最近发来的消息将被丢弃)、 * reject-publish-dlx(拒绝发送消息到死信交换器) * 类型为quorum 的queue只支持drop-head; */ arguments.put("x-overflow", "reject-publish");
复制代码
1
2
The default behaviour for RabbitMQ when a maximum queue length or size is set and the maximum is reached is to drop or dead-letter messages from the front of the queue (i.e. the oldest messages in the queue). To modify this behaviour, use the overflow setting described below.

x-overflow属性默认的处理策略是丢掉或者死信消息从队列的头部(也可以说是队列中最老的消息)

GitHub地址:https://github.com/mingyang66/spring-parent

最后

以上就是孤独白开水最近收集整理的关于RabbitMQ学习笔记:队列容量设置(x-max-length、x-max-length-bytes、x-overflow)的全部内容,更多相关RabbitMQ学习笔记内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(80)

评论列表共有 0 条评论

立即
投稿
返回
顶部