ActiveMQ -- 消息持久化
2016-08-22 11:16
302 查看
为了防止系统意外down机丢失消息,同时能在系统恢复后能重新发送原来未发送的消息。一般消息系统都会采用持久化机制。Activemq5.4提供了几种持久化机制:
KahaDB message store
Journaled JDBC adapter
Non-journaled JDBC adapter
消息持久化,就是将消息进行一个存储。
如图所示,主题中的消息都是持久化后的,订阅同一topic的用户,都有自己的一个指针记录,消息处理的进展。
基于文件存储,不需要第三方存储数据库。
使用KahaDB存储需要配置activemq.xml中
同样可以以编程的方式,制定消息的存储
默认情况下,ActiveMQ后台开启kahaDB,
我们查看目录:/mq/apache-activemq-5.13.3/data/kahadb
有4中类型格式的文件生成
db log files—KahaDB stores messages into data log files named db-.log of
a predefined size. When a data log is full, a new one will be created, and the log number incremented. When there are no more references to any of the messages in the data log file, it’ll be deleted or archived
db.data —This file contains the persistent BTree indexes to the messages held in the message data logs.(用于存储消息索引)
db.redo —This is the redo file, used for recovering the BTree indexes if the KahaDB message store starts after a hard stop(用于数据恢复)
更多参数,详见下图
更多存储方式:
The AMQ message store—A file-based message store designed for
performance
The JDBC message store—A message store based on JDBC
The Memory message store—A memory-based message store
KahaDB message store
Journaled JDBC adapter
Non-journaled JDBC adapter
消息持久化,就是将消息进行一个存储。
如图所示,主题中的消息都是持久化后的,订阅同一topic的用户,都有自己的一个指针记录,消息处理的进展。
KahaDB存储
基于文件形式存储的。基于文件存储,不需要第三方存储数据库。
使用KahaDB存储需要配置activemq.xml中
<persistenceAdapter>
<persistenceAdapter> <kahaDB directory="${activemq.data}/kahadb"/> </persistenceAdapter>
同样可以以编程的方式,制定消息的存储
public class EmbeddedBrokerUsingAMQStoreExample { BrokerService createEmbeddedBroker() throws Exception { BrokerService broker = new BrokerService(); File dataFileDir = new File("target/amq-in-action/kahadb"); KahaDBStore kaha = new KahaDBStore(); kaha.setDirectory(dataFileDir); // Using a bigger journal file kaha.setJournalMaxFileLength(1024 * 100); // small batch means more frequent and smaller writes kaha.setIndexWriteBatchSize(100); // do the index write in a separate thread kaha.setEnableIndexWriteAsync(true); broker.setPersistenceAdapter(kaha); // create a transport connector broker.addConnector("tcp://localhost:61616"); // start the broker broker.start(); return broker; } }
默认情况下,ActiveMQ后台开启kahaDB,
我们查看目录:/mq/apache-activemq-5.13.3/data/kahadb
有4中类型格式的文件生成
db log files—KahaDB stores messages into data log files named db-.log of
a predefined size. When a data log is full, a new one will be created, and the log number incremented. When there are no more references to any of the messages in the data log file, it’ll be deleted or archived
db.data —This file contains the persistent BTree indexes to the messages held in the message data logs.(用于存储消息索引)
db.redo —This is the redo file, used for recovering the BTree indexes if the KahaDB message store starts after a hard stop(用于数据恢复)
更多参数,详见下图
更多存储方式:
The AMQ message store—A file-based message store designed for
performance
The JDBC message store—A message store based on JDBC
The Memory message store—A memory-based message store
相关文章推荐
- JMS学习(五)--ActiveMQ中的消息的持久化和非持久化 以及 持久订阅者 和 非持久订阅者之间的区别与联系
- ActiveMq笔记2-消息持久化
- ActiveMQ - 持久化消息与持久主题订阅
- JMS消息持久化,将ActiveMQ消息持久化到mySql数据库中
- ActiveMQ深入浅出(五)——ActiveMQ将消息持久化到数据库
- JMS消息持久化,将ActiveMQ消息持久化到mySql数据库中
- JMS之activemq消息持久化
- 3、ActiveMQ学习记录 之 消息持久化
- ActiveMQ的消息持久化到Mysql数据库
- ActiveMQ消息持久化到Mysql数据库
- [jms那点事儿] JMS ( java message service )入门 + activemq消息持久化
- ActiveMQ入门到精通4-消息持久化到Mysql
- MQTT下ActiveMQ的消息持久化
- ActiveMQ消息持久化
- ActiveMQ开启用户认证及消息持久化到数据库功能
- ActiveMQ将消息持久化到数据库
- 消息中间件(3)-ActiveMQ消息持久化
- ActiveMQ使用MySQL进行消息持久化
- ActiveMQ消息持久化到Mysql数据库
- [jms那点事儿] JMS ( java message service )入门 + activemq消息持久化