ActiveMQ中Session以及消息ACKNOWLEDGE不同方式的说明

参考博文:http://www.cnblogs.com/SzeCheng/p/4792084.html

参考博文:http://activemq.apache.org/producer-flow-control.html

名词解释:

P:生产者

C:消费者

服务端:P 或者 ActiveMQ服务

客户端:ActiveMQ服务 或者 C

客户端成功接收一条消息的标志是这条消息被签收。成功接收一条消息一般包括如下三个阶段: 

1.客户端接收消息; 

2.客户端处理消息; 

3.消息被签收。

session = connection.createSession(Boolean.false, Session.CLIENT_ACKNOWLEDGE);##第一个参数控制事务,第二个参数控制消息

另外ACKNOWLEDGE说明:

根据API说明

http://activemq.apache.org/maven/apidocs/org/apache/activemq/ActiveMQSession.html#acknowledge--

如果调用ack将会ack这个session的所有消息。

Acknowledges all consumed messages of the session of this consumed message.

All consumed JMS messages support the acknowledge method for use when a client has specified that its JMS session's consumed messages are to be explicitly acknowledged. By invokingacknowledge on a consumed message, a client acknowledges all messages consumed by the session that the message was delivered to.

Calls to acknowledge are ignored for both transacted sessions and sessions specified to use implicit acknowledgement modes.

A client may individually acknowledge each message as it is consumed, or it may choose to acknowledge messages as an application-defined group (which is done by calling acknowledge on the last received message of the group, thereby acknowledging all messages consumed by the session.)Messages that have been received but not acknowledged may be redelivered.

还好AcitveMq提供了另外一种方法来避免一个消息一次ack 将会ack掉全部消息的问题。

1 session = connection.createSession(Boolean.FALSE, 2                    ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);

参考 Java Enterprise Edition : A Practical Approach - 第 228 页

在不带事务的 Session 中,一条消息何时和如何被签收取决于Session的设置。 

1.Session.AUTO_ACKNOWLEDGE 

当客户端从 receive 或 onMessage成功返回时,Session 自动签收客户端的这条消息的收条。

2.Session.CLIENT_ACKNOWLEDGE 

    客户端通过调用消息的 acknowledge 方法签收消息。

message.acknowledge();

在带事务的 Session 中,签收自动发生在事务提交时。如果事务回滚,所有已经接收的消息将会被再次传送。其实这里的Session.CLIENT_ACKNOWLEDGE 用处不大。

1session = connection.createSession(Boolean.TRUE, Session.CLIENT_ACKNOWLEDGE); 2 3session.commit();

总结:

1、对于生产者:服务端端为P,客户端为ActiveMQ服务。  Session设置为AUTO_ACKNOWLEDGE 和CLIENT_ACKNOWLEDGE ,相对来说区别不是很大,根据情况考虑。

2、对于消费者:服务端为ActiveMQ为服务,客户端为C。 Session设置为AUTO_ACKNOWLEDGE ,接收到消息(receive 或 onMessage成功返回时),即为消费成功,然后从队列里移除该数据。不关心该数据有没有正确被处理成我们想要的结果;Session设置为CLIENT_ACKNOWLEDGE 时,必须手动调用acknowledge 方法才为消费成功,然后从队列里移除该条数据。

3、P和C的Session设置成哪种模式,互不影响。

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )