ActiveMQ Message Groups
http://activemq.apache.org/message-groups.html
与Exclusive Consumer相比,Message Groups的对消息分组的粒度更细。具有相同groupId的消息会被投送到同一个消费者,除非这个消费者挂了。
代码示例:
Mesasge message = session.createTextMessage("<foo>hey</foo>");
// 设置groupId
message.setStringProperty("JMSXGroupID", "IBM_NASDAQ_20/4/05");
// 设置sequence
message.setIntProperty("JMSXGroupSeq", -1);
producer.send(message);
对应的代码在 org.apache.activemq.broker.region.Queue 中:
// 判断消息能否分发给消费者,返回true表示可以
// Subscription 表示消费者,QueueMessageReference 表示消息
protected boolean assignMessageGroup(Subscription subscription, QueueMessageReference node)
throws Exception {
// 默认为true
boolean result = true;
// Keep message groups together.
// 获取消息的"JMSXGroupID"属性
String groupId = node.getGroupID();
// 获取消息的"JMSXGroupSeq"属性
int sequence = node.getGroupSequence();
if (groupId != null) {
// MessageGroupMap是一个Map,键是groupId,值是消费者
MessageGroupMap messageGroupOwners = getMessageGroupOwners();
// If we can own the first, then no-one else should own the
// rest.
if (sequence == 1) {
assignGroup(subscription, messageGroupOwners, node, groupId);
} else { // Make sure that the previous owner is still valid, we may
// need to become the new owner.
ConsumerId groupOwner;
// 根据groupId取出消费者
groupOwner = messageGroupOwners.get(groupId);
if (groupOwner == null) {
assignGroup(subscription, messageGroupOwners, node, groupId);
} else {
if (groupOwner.equals(subscription.getConsumerInfo().getConsumerId())) {
// A group sequence < 1 is an end of group signal.
if (sequence < 0) {
messageGroupOwners.removeGroup(groupId);
subscription.getConsumerInfo().
setLastDeliveredSequenceId(subscription.getConsumerInfo().getLastDeliveredSequenceId() - 1);
}
} else {
result = false;
}
}
}
} return result;
} // 往MessageGroupMap中插入键值对
protected void assignGroup(Subscription subs, MessageGroupMap messageGroupOwners,
MessageReference n, String groupId) throws IOException {
messageGroupOwners.put(groupId, subs.getConsumerInfo().getConsumerId());
Message message = n.getMessage();
message.setJMSXGroupFirstForConsumer(true);
subs.getConsumerInfo().
setLastDeliveredSequenceId(subs.getConsumerInfo().getLastDeliveredSequenceId() + 1);
}
ActiveMQ Message Groups的更多相关文章
- JMS学习(三)ActiveMQ Message Persistence(转)
1,JMS规范支持两种类型的消息传递:persistent and non-persistent.ActiveMQ在支持这两种类型的传递方式时,还支持消息的恢复.中间状态的消息(message are ...
- JMS学习(三)ActiveMQ Message Persistence
1,JMS规范支持两种类型的消息传递:persistent and non-persistent.ActiveMQ在支持这两种类型的传递方式时,还支持消息的恢复.中间状态的消息(message are ...
- ActiveMQ 中 consumer 的优先级,message 的优先级
http://activemq.apache.org/consumer-priority.htmlconsumer 优先级 http://activemq.apache.org/activemq-me ...
- ActiveMQ消息队列的使用及应用
这里就不说怎么安装了,直接解压出来就行了. 谢绝转载,作者保留所有权力 目录: 一:JMQ的两种消息模式 1.1:点对点的消息模式 1.2:订阅模式 二:点对点的实现代码 2.1:点对点的发送端 2 ...
- ActiveMQ笔记(1):编译、安装、示例代码
一.编译 虽然ActiveMQ提供了发布版本,但是建议同学们自己下载源代码编译,以后万一有坑,还可以尝试自己改改源码. 1.1 https://github.com/apache/activemq/r ...
- ActiveMQ 简介与安装
一. 概述与介绍 ActiveMQ 是Apache出品,最流行的.功能强大的即时通讯和集成模式的开源服务器.ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provide ...
- JMS消息中间件系列[ActiveMQ](一)
版本5.13.3的特性: 1.Supports a variety of Cross Language Clients and Protocols from Java, C, C++, C#, Rub ...
- 关于ActiveMQ的问题分析
目前常用的消息队列组建无非就是MSMQ和ActiveMQ,至于他们的异同,这里不想做过多的比较.简单来说,MSMQ内置于微软操作系统之中,在部署上包含一个隐性条件:Server需要是微软操作系统.(对 ...
- MQ学习(二)----ActiveMQ简介(转)
1. 什么是ActiveMQ ActiveMQ是一种开源的,实现了JMS1.1规范的,面向消息(MOM)的中间件,为应用程序提供高效的.可扩展的.稳定的和安全的企业级消息通信.ActiveMQ使用A ...
随机推荐
- CSS sprites
CSS Sprites在国内很多人叫css精灵,是一种网页图片应用处理方式. 优点: 它允许你将一个页面涉及到的所有零星图片都包含到一张大图中去,这样一来,当访问该页面时,载入的图片就不会像以前那样一 ...
- 转 这种方法可以免去自己计算大文件md5 的麻烦
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEditor;using ...
- 51nod 1185 || 51nod 1072 威佐夫博弈
贴个模板:平常的跟高精度java的: int: #pragma comment(linker, "/STACK:1024000000,1024000000") #include&l ...
- ABP捕捉异常错误代码
在服务层或者CORE层 随便哪里都可以 创建一个捕捉异常的文件夹 里面写一个LonsidException类 继承后面的接口 然后重写继承的方法 这样在ABP项目运行阶段 无论在哪里出现异 ...
- Hadoop大数据分析应用场景
J 为了满足日益增长的业务变化,京东的京麦团队在京东大数据平台的基础上,采用了hadoop等热门的开源大数据计算引擎,打造了一款为京东运营和产品提供决策性的数据类产品-北斗平台. 一.Hadoop的应 ...
- 力扣(LeetCode) 35. 搜索插入位置
给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引.如果目标值不存在于数组中,返回它将会被按顺序插入的位置. 你可以假设数组中无重复元素. 示例 1: 输入: [1,3,5,6], 5 输 ...
- angular 拦截器
介绍:$http service在Angular中用于简化与后台的交互过程,其本质上使用XMLHttpRequest或JSONP进行与后台的数据交互.在与后台的交互过程中,可能会对每条请求发送到Ser ...
- 如何在ubuntu中安装中文输入法?
如何在ubuntu中安装中文输入法 在桌面右上角设置图标中找到“System Setting”,双击打开. 在打开的窗口里找到“Language Support”,双击打开. 可能打开会说没有安装 ...
- 全栈性能测试修炼宝典--Jmeter实战(三)
JMeter体系结构 1.JMeter体系结构 (1)名词解释 元件:JMeter工具菜单中的一个子菜单,比如HTTP请求.事务控制器.响应断言就是一个元件. 组件:一组元件的集合,比如逻辑控制器中有 ...
- firewalld管理防火墙常用命令
1.查看防火墙的状态 [root@localhost HMK]# firewall-cmd --state 查看防火墙的运行状态 not running [root@localhost HMK]# s ...