2024-04-01  阅读(108)
原文作者:立小言先森 原文地址: https://mingyang.blog.csdn.net/article/details/102752982

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

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.)

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

                /**
                 * queue中可以存储处于ready状态的消息数量
                 */
                arguments.put("x-max-length", 6);
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.)

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

                /**
                 * queue中可以存储处于ready状态的消息占用的内存空间,单位:字节
                 */
                arguments.put("x-max-length-bytes", 1024);
Overflow behaviour
    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状态存储消息的个数或消息占用的容量超过设定值后的处理策略

                /**
                 * queue溢出行为,这将决定当队列达到设置的最大长度或者最大的存储空间时发送到消息队列的消息的处理方式;
                 * 有效的值是:
                 * drop-head(删除queue头部的消息)、
                 * reject-publish(最近发来的消息将被丢弃)、
                 * reject-publish-dlx(拒绝发送消息到死信交换器)
                 * 类型为quorum 的queue只支持drop-head;
                 */
                arguments.put("x-overflow", "reject-publish");
    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


Java 面试宝典是大明哥全力打造的 Java 精品面试题,它是一份靠谱、强大、详细、经典的 Java 后端面试宝典。它不仅仅只是一道道面试题,而是一套完整的 Java 知识体系,一套你 Java 知识点的扫盲贴。

它的内容包括:

  • 大厂真题:Java 面试宝典里面的题目都是最近几年的高频的大厂面试真题。
  • 原创内容:Java 面试宝典内容全部都是大明哥原创,内容全面且通俗易懂,回答部分可以直接作为面试回答内容。
  • 持续更新:一次购买,永久有效。大明哥会持续更新 3+ 年,累计更新 1000+,宝典会不断迭代更新,保证最新、最全面。
  • 覆盖全面:本宝典累计更新 1000+,从 Java 入门到 Java 架构的高频面试题,实现 360° 全覆盖。
  • 不止面试:内容包含面试题解析、内容详解、知识扩展,它不仅仅只是一份面试题,更是一套完整的 Java 知识体系。
  • 宝典详情:https://www.yuque.com/chenssy/sike-java/xvlo920axlp7sf4k
  • 宝典总览:https://www.yuque.com/chenssy/sike-java/yogsehzntzgp4ly1
  • 宝典进展:https://www.yuque.com/chenssy/sike-java/en9ned7loo47z5aw

目前 Java 面试宝典累计更新 400+ 道,总字数 42w+。大明哥还在持续更新中,下图是大明哥在 2024-12 月份的更新情况:

想了解详情的小伙伴,扫描下面二维码加大明哥微信【daming091】咨询

同时,大明哥也整理一套目前市面最常见的热点面试题。微信搜[大明哥聊 Java]或扫描下方二维码关注大明哥的原创公众号[大明哥聊 Java] ,回复【面试题】 即可免费领取。

阅读全文