1,JMS规范支持两种类型的消息传递:persistent and non-persistent。ActiveMQ在支持这两种类型的传递方式时,还支持消息的恢复、中间状态的消息(message are cached in memory)

2,ActiveMQ可将消息存储在三种类型介质中:file-based(存储在文件中)、in-memory(存储在内存中)、relational databases(存储在关系数据库中)

3,Persistence Message有何用处?

Persistent messages are ideal if you want messages to always be available to a message consumer after they have been delivered to a message broker, or you need messages to survive even if there has been a system failure。

①消息对消费者总是可用。②系统宕机后,消息不被丢失。

4,ActiveMQ中存储两种Destination,主题(Topic)与 队列(Queue)。主题对应的Domain是发布-订阅模型(Pub/Sub),队列对应的Domain是点对点模型(P2P)。

队列存储:按FIFO的顺序存储消息,Only one message is dispatched between one of potentially many consumers. Only when that message has been consumed and acknowledged can it be deleted from the broker's message store.

对于众多的消费者,只有其中一个消费者可以接收该消息。也只有当消费者消费了之后,该消息才能删除。

Topic存储:

For durable subscribers to a topic, each consumer gets a copy of the message. In order to save space (some messages can be very large!), only one copy of a message is stored by the broker.

什么是durable subscribers(持久订阅者)?对于 durable subscribers而言,尽管当前它是不活跃的(没有连接到borker),也不会错失发给broker的消息(类似于QQ的离线消息)。持久订阅者维护者一个消息指针,指针总是指向该订阅者需要的下一个消息。

A durable subscriber object in the store maintains a pointer to its next stored message and dispatches a copy of it to its consumer as shown in Figure 5.2.

为什么要这样设计?

①每个消费者消费速率是不同的

②不是所有的消费者都在线(actived)

③同一个消息可能被多个消费者订阅

通过指针这种形式,可以很好地解决上面三种情况下出现的问题。只有当所有的消费者都获得了该消息时,消息才能从broker中删除。

5,ActiveMQ中消息存储的方式:

ActiveMQ provides a pluggable API for message stores as well as multiple message store implementations including:

①AMQ Message Store

②KahaDB Message Store,ActiveMQ 5.13.2版本默认的存储方式

③JDBC Message Store

在配置文件activemq.xml中有存储方式的配置选项:

AMQ存储方式的实现思想非常值得一看:

The Journal consists of a rolling log of messages and commands (such as transactional boundaries and message deletions) stored in data files of a certain length. When the maximum length of the currently used data file has been reached a new data file is created. All the messages in a data file are reference counted, so that once every message in that data file is no longer required, the data file can be removed or archived. The journal only appends messages to the end of the current data file, so storage is very fast.

存储Journal的文件是定长的,并且只以append方式向文件写入日志。

为了方便,直接截图了。

KahaDB 消息存储方式就不截图了。AMQ方式采用HashTable存储Reference Index,而KahaDB采用B-Tree存储索引。

此外,关于配置ActiveMQ使用JDBC作为持久存储的方法,参考这篇文章

6,Broker为Consumer缓存消息

由于第5点中讲到,消息存储到持久介质中,因此就不适用那些需要实时消息的场合。---比如,交易信息需要在秒级时间内获得,用完之后就不再需要它了。

因此,ActiveMQ可以配置缓存哪种类型的消息、缓存多少消息、这些消息缓存多久?

Messages that are cached by the broker are only dispatched to a topic consumer if it is retroactive; and never to durable topic subscribers

http://www.cnblogs.com/hapjin/p/5438377.html

JMS学习(三)ActiveMQ Message Persistence(转)的更多相关文章

  1. JMS学习(五)--ActiveMQ中的消息的持久化和非持久化 以及 持久订阅者 和 非持久订阅者之间的区别与联系

    一,消息的持久化和非持久化 ①DeliveryMode 这是传输模式.ActiveMQ支持两种传输模式:持久传输和非持久传输(persistent and non-persistent deliver ...

  2. JMS学习(六)-ActiveMQ的高可用性实现

    原文地址:http://www.cnblogs.com/hapjin/p/5663024.html 一,ActiveMQ高可用性的架构 ActiveMQ的高可用性架构是基于Master/Slave 模 ...

  3. JMS学习(三)ActiveMQ Message Persistence

    1,JMS规范支持两种类型的消息传递:persistent and non-persistent.ActiveMQ在支持这两种类型的传递方式时,还支持消息的恢复.中间状态的消息(message are ...

  4. JMS学习三(ActiveMQ消息的可靠性)

    下面我们来学习一下消息接受确认和发送持久化消息.消息的过期.消息的选择器和消息的优先级. 一.消息接收确认 1.jms消息只有在被确认之后才认为成功消费了这条消息.消息的成功消费通常包括三个步骤:(1 ...

  5. JMS学习(七)-ActiveMQ消息的持久存储方式之KahaDB存储

    一,介绍 自ActiveMQ5.4以来,KahaDB成为了ActiveMQ默认的持久化存储方式.相比于原来的AMQ存储方式,官方宣称KahaDB使用了更少的文件描述符,并且提供了更快的存储恢复机制. ...

  6. Spring整合Jms学习(三)_MessageConverter介绍

    1.4     消息转换器MessageConverter MessageConverter的作用主要有双方面,一方面它能够把我们的非标准化Message对象转换成我们的目标Message对象,这主要 ...

  7. JMS学习(八)-ActiveMQ Consumer 使用 push 还是 pull 获取消息

    ActiveMQ是一个消息中间件,对于消费者而言有两种方式从消息中间件获取消息: ①Push方式:由消息中间件主动地将消息推送给消费者:②Pull方式:由消费者主动向消息中间件拉取消息.看一段官网对P ...

  8. JMS学习十一(ActiveMQ Consumer高级特性之独有消费者(Exclusive Consumer))

    一.简介 Queue中的消息是按照顺序被分发到consumers的.然而,当你有多个consumers同时从相同的queue中提取消息时, 你将失去这个保证.因为这些消息是被多个线程并发的处理.有的时 ...

  9. ActiveMQ基本详解与总结& 消息队列-推/拉模式学习 & ActiveMQ及JMS学习

    转自:https://www.cnblogs.com/Survivalist/p/8094069.html ActiveMQ基本详解与总结 基本使用可以参考https://www.cnblogs.co ...

随机推荐

  1. soundPool播放短、频、快的声音

    package com.example.soundpool; import android.media.AudioManager; import android.media.SoundPool; im ...

  2. android圆形进度条ProgressBar颜色设置

    花样android Progressbar http://www.eoeandroid.com/thread-1081-1-1.html http://www.cnblogs.com/xirihanl ...

  3. Eclipse用法和技巧二十一:工程的展示途径

    用eclipse阅读代码的时候,有时候代码会变成如图一所示的样子,有时候可能是图二的样子.为什么有时候是图一有时候是图二,笔者也不是很清楚.不过怎么手动设置成图一图二,就是接下来要讲的东西. 1    ...

  4. linux中多线程解析

    Linux系统下的多线程遵循POSIX线程接口,称为 pthread.编写Linux下的多线程程序,需要使用头文件pthread.h,连接时需要使用库libpthread.a.顺便说一下,Linux ...

  5. cocos2d-x游戏开发系列教程-坦克大战游戏之坦克的显示

    1.先定义坦克的一些属性 class Tank : public CCSprite { public : Tank(); ~Tank(); static Tank* createTankWithTan ...

  6. iOS开发 - 应用内打开第三方应用并传值

    首先说下这个功能, 应该都有接触过. 比方,你下载了一个电子书,然后选择打开方式的时候,可能会看到你手机中已经安装的阅读类App. 或者,你的QQ收到了某个文件,你也能够选择本地的应用来打开. 那这种 ...

  7. 编写高质量代码改善java程序的151个建议——[52-57]String !about String How to use them?

    原创地址:   http://www.cnblogs.com/Alandre/  (泥沙砖瓦浆木匠),须要转载的,保留下! Thanks Although the world is full of s ...

  8. android第一天-------环境搭建

    今天正式第一天学习android的. 1.昨晚下班后回家跟同事刘江龙打了四把dota.还好,都赢了把对面虐成狗了.大多都是1300到1450的局,玩的很爽. 2.dota打完后给在湖南常德的女朋友打了 ...

  9. 【linux】内核源代码下载与阅读

      原创,转载时请注明,谢谢.邮箱:tangzhongp@163.com 博客园地址:http://www.cnblogs.com/embedded-tzp Csdn博客地址:http://blog. ...

  10. Cocos2d-x教程第(11)讲-利用遮罩(蒙版)CCLayerColor制作新手引导界面(上)

    欢迎转载,转载时请注明原文出处:http://blog.csdn.net/u012945598/article/details/17280019 源码下载地址:http://download.csdn ...