ActiveMQ 中 consumer 的优先级,message 的优先级
http://activemq.apache.org/consumer-priority.htmlconsumer 优先级
http://activemq.apache.org/activemq-message-properties.html 消息优先级
1、设置 consumer 的优先级:
queue = new ActiveMQQueue("TEST.QUEUE?consumer.priority=10");
consumer = session.createConsumer(queue);
priority 的取值从0到127。broker 按照 consumer 的优先级给 queue 的 consumers 排序,首先把消息分发给优先级最高的 consumer。一旦该 consumer 的 prefetch buffer 满了,broker 就把消息分发给优先级次高的,prefetch buffer 不满的 consumer。
// org.apache.activemq.broker.region.Queue
// consumer priority 的比较器
private final Comparator<Subscription> orderedCompare = new Comparator<Subscription>() { @Override
public int compare(Subscription s1, Subscription s2) {
// We want the list sorted in descending order
// 倒序,即数值大的优先级高
int val = s2.getConsumerInfo().getPriority() - s1.getConsumerInfo().getPriority();
if (val == 0 && messageGroupOwners != null) {
// then ascending order of assigned message groups to favour less loaded consumers
// Long.compare in jdk7
long x = s1.getConsumerInfo().getLastDeliveredSequenceId();
long y = s2.getConsumerInfo().getLastDeliveredSequenceId();
val = (x < y) ? -1 : ((x == y) ? 0 : 1);
}
return val;
}
}; // 添加 consumer 的时候,会触发排序
// 在 consumers 列表中,靠前的 consumer,先分发消息
private void addToConsumerList(Subscription sub) {
if (useConsumerPriority) {
consumers.add(sub);
Collections.sort(consumers, orderedCompare);
} else {
consumers.add(sub);
}
}
2、设置 message 的优先级需要在 broker 端和 producer 端配置:
2.1 在 broker 端设置 TEST.BAT 队列为 prioritizedMessages = "true"
<policyEntry queue="TEST.BAT" prioritizedMessages="true" producerFlowControl="true" memoryLimit="1mb">
<deadLetterStrategy>
<individualDeadLetterStrategy queuePrefix="TEST"/>
</deadLetterStrategy>
<pendingQueuePolicy>
<storeCursor/>
</pendingQueuePolicy>
</policyEntry>
2.2 producer 发送消息时,设置 message 的优先级
TextMessage message = session.createTextMessage(text);
producer.send(destination, message, DeliveryMode.NON_PERSISTENT, 1, 0);
设置 message 的优先级,需要调用:
void javax.jms.MessageProducer.send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive)
throws JMSException
而不能这么写:
TextMessage message = session.createTextMessage(text);
message.setJMSPriority(0);
初步看是 ActiveMQ 的 bug。消息的 priority 值,从0到9。消息配置了优先级之后,消息存放在 PrioritizedPendingList 中。
// 省略部分代码
private class PrioritizedPendingListIterator implements Iterator<MessageReference> {
private int index = 0;
private int currentIndex = 0;
List<PendingNode> list = new ArrayList<PendingNode>(size()); PrioritizedPendingListIterator() {
for (int i = MAX_PRIORITY - 1; i >= 0; i--) {
// priority 值大的优先级高
OrderedPendingList orderedPendingList = lists[i];
if (!orderedPendingList.isEmpty()) {
list.addAll(orderedPendingList.getAsList());
}
}
}
}
ActiveMQ 中 consumer 的优先级,message 的优先级的更多相关文章
- spring+activemq中多个consumer同时处理消息时遇到的性能问题
最近在做数据对接的工作,用到了activemq,我需要从activemq中接收消息并处理,但是我处理数据的步骤稍微复杂,渐渐的消息队列中堆的数据越来越多,就想到了我这边多开几个线程来处理消息. 可是会 ...
- 【转】STM32中的抢占优先级、响应优先级概念
STM32(Cortex-M3)中有两个优先级的概念--抢占式优先级和响应优先级,有人把响应优先级称作'亚优先级'或'副优先级',每个中断源都需要被指定这两种优先级. 具有高抢占式优先级的中断可以在具 ...
- ActiveMQ 中的链表
ActiveMQ 中的消息在内存中时,以链表形式保存,以 PendingList 表示,每一个消息是 PendingNode. PendingList 主要有2种实现:OrderedPendingLi ...
- ActiveMQ中Broker的应用与启动方式
Broker:英语有代理的意思,在activemq中,Broker就相当于一个Activemq实例. 1. 命令行启动实例: 1.activemq start使用默认的activemq.xml启动 E ...
- 802.1p 优先级与内部优先级的映射关系
缺省情况下,所有华为 S 系列交换机的 802.1P 优先级 与内部优先级的映射关系是 一 样的,如表 10-3 所示.从中可以看出,这些交换机中 802.1p 优先级与内部优先级的缺省映射关系是按等 ...
- stm32中断 抢占优先级 和 响应优先级 有什么区别
与51不同,stm32的中断分类更灵活.51只是按先后顺序大小排列互相打断. stm32中多了响应优先级这一概念. stm32的中断分为 1.抢占(占先)优先级. 2.响应优先级. 1.抢占优先级.抢 ...
- STM32 抢占优先级和响应优先级
一.抢占优先级和响应优先级 STM32 的中断向量具有两个属性,一个为抢占属性,另一个为响应属性,其属性编号 越小,表明它的优先级别越高. 抢占,是指打断其他中断的属性,即因为具有这个属性会出现嵌套中 ...
- Spring Boot 监听 Activemq 中的特定 topic ,并将数据通过 RabbitMq 发布出去
1.Spring Boot 和 ActiveMQ .RabbitMQ 简介 最近因为公司的项目需要用到 Spring Boot , 所以自学了一下, 发现它与 Spring 相比,最大的优点就是减少了 ...
- Object-C中ARC forbids explicit message send of ' ' 错误
OC中ARC forbids explicit message send of '...'错误 转自CSDN hahahacff 有所整理 ARC forbids explicit message s ...
随机推荐
- 2.在Jenkins中配置及执行 maven + selenium + testng项目
1. 在Jenkins中配置Maven与Git 1)在系统管理>管理插件>可选插件 页面分别下载Git plugin 与 Maven Integration plugin插件,安装完成后再 ...
- Spring-json依赖
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jacks ...
- CSS--点击改变样式
当某个链接或元素被选中时可以时,需要改变其颜色或状态,而stylus中提供&选择器,&指向父选择器,用于判断父元素达到某条件时改变状态,下面的例子中当父元素router-link有被选 ...
- VirtualBox--虚拟机网络设置1--(四种方式)
转载自:https://www.douban.com/group/topic/15558388/ VirtualBox的提供了四种网络接入模式,它们分别是: 1.NAT 网络地址转换模式(NAT,Ne ...
- Python3 函数注解
Python3提供一种语法,用于为函数声明中的参数和返回值附加元数据.下面的例子是注解后的版本,特点在第一行: 1 def clip(text : str, max_len : 'int > 0 ...
- Windows下使用创建多层文件夹 SHCreateDirectoryEx 函数需要注意的问题
1.在使用SHCreateDirectoryEx函数创建多层文件夹的过程中,发现在文件夹路径中,只能使用\\而不能使用/,否则将创建文件夹失败. 2.下面为在MFC中使用的代码片段 CString n ...
- Mac Anaconda 简单介绍 -- 环境管理
Anaconda Anaconda(官方网站)就是可以便捷获取包且对包能够进行管理,同时对环境可以统一管理的发行版本.Anaconda包含了conda.Python在内的超过180个科学包及其依赖项. ...
- Mac Python PyQt5 环境搭建
pip install pyqt5 测试开发环境 在Terminal里敲下以下代码,如果没有报错就说明安装成功了. python -c "import PyQt5" 或是如下图,导 ...
- Unity--- 资源路径问题
使用 System.IO.Path 这个API得到的路径,其实也是以"\"分隔路径的. 我们在windows下打开资源管理器,某个目录或文件的路径为:E:\uniuProject5 ...
- 创建.ignore文件
方法一:1. 在需要创建 .gitignore 文件的文件夹, 右键选择Git Bash 进入命令行,进入项目所在目录.如:(cd /d/git/project) 2. 输入 touch .gitig ...