ActiveMQ -- 消息持久化

为了防止系统意外down机丢失消息,同时能在系统恢复后能重新发送原来未发送的消息。一般消息系统都会采用持久化机制。Activemq5.4提供了几种持久化机制:

  1. KahaDB message store
  2. Journaled JDBC adapter
  3. 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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值