5.2 The KahaDB message store
5.2 KahaDB消息存储
The recommended message store for general-purpose messages since ActiveMQ version
5.3 is KahaDB. This is a file-based message store that combines a transactional journal,
for reliable message storage and recovery, with good performance and scalability.
ActiveMQ从5.3版本以后,推荐使用KahaDB作为通用的消息存储方式.KahaDB是一种基于文件的存储,具有
卓越的性能和扩展性,具有事务日志功能,能够可靠的今昔消息的存储和恢复.
The KahaDB store is a file-based, transactional store that’s been tuned and designed
for the fast storage of messages. The aim of the KahaDB store is to be easy to use and as
fast as possible. Its use of a file-based message database means there’s no prerequisite
for a third-party database. This message store enables ActiveMQ to be downloaded and
running in literally minutes. In addition, the structure of the KahaDB store has been
streamlined especially for the requirements of a message broker.
KahaDB存储是一种基于文件,具有事务存储功能,为消息的快速存储而设计并做了优化.
KahaDB存储的目标是易于使用并且做到尽可能的快速.使用基于文件的消息数据库表明
KahaDB不需要使用第三方数据库.这种消息存储使得能在数分钟之内完成ActiveMQ的下载和运行.
并且,为满足消息代理的需求,KahaDB的存储结构已经做了特殊的优化.
The KahaDB message store uses a transactional log for its indexes and only uses
one index file for all its destinations. It’s been used in production environments with
10,000 active connections, each connection having a separate queue. The configurability
of the KahaDB store means that it can be tuned for most usage scenarios, from
high throughput applications (for example, trading platforms), to storing large
amounts of messages (for example, GPS tracking).
KahaDB消息存储使用一个事物日志文件作为索引,并且所有的destination只使用一个索引文件.
KahaDB已可用于这样的生产环境:具有10000个活动连接,并且每一个连接拥有一个独立的队列.
KahaDB的可配置性说明,KahaDB可以针对从要求高吞吐量(比如交易平台)到处理海量消息(比如GPS跟踪)
等不同的应用场景进行调优.
To enable the KahaDB store for ActiveMQ, you need to configure the
<persistenceAdapter> element in the activemq.xml configuration file. Here’s a minimal
configuration for the KahaDB message store:
为了在ActiveMQ启用KahaDB存储,你需要在配置文件activemq.xml中配置<persistenceAdapter>
元素.下面是启用KahaDB存储的一个最小化配置例子:
<broker brokerName="broker" persistent="true" useShutdownHook="false">
...
<persistenceAdapter>
<kahaDB directory="activemq-data" journalMaxFileLength="16mb"/>
</persistenceAdapter>
...
</broker>
If you want to embed an ActiveMQ broker inside an application, the message store can
also be configured programmatically. Here’s an example of a programmatic configuration
for KahaDB:
如果你打算在应用程序内部启动一个嵌入式的ActiveMQ代理,也可以使用程序代码来配置消息存储.
下面是一个使用程序代码配置KahaDB的例子:
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;
}
}
Although the example seems small, it’s enough to create an ActiveMQ broker using
the KahaDB message store and listen for ActiveMQ clients connecting over TCP. For
more information about embedding ActiveMQ, see chapter 8.
尽管上面的实例代码看起来比较小巧,但是代码已足够创建一个ActiveMQ代理并使用KahaDB作为
消息存储同时监听通过TCP协议连接的ActiveMQ客户端.更多关于嵌入式ActiveMQ的内容请参阅
第8章内容.
In order to better understand its use and configuration, it’s important to examine
the internals of the KahaDB message store.
为了更好的理解和配置KahaDB消息存储,能深入KahaDB消息存储的内部一探究竟变得十分
重要.
5.2.1 The KahaDB message store internals
5.2.1 KahaDB消息存储内部探秘
The KahaDB message store is the fastest of all the provided message store implementations.
Its speed is the result of the combination of a fast transactional journal comprised
of data log files, the highly optimized indexing of message IDs, and inmemory
message caching. Figure 5.3 provides a high-level diagram of the KahaDB
message store.
在所有以提供的消息存储实现中,KahaDB是最快的.KahaDB的高速度源自一种包含数据日志文件的
高速事务日志文件和根据消息ID高度优化的索引以及基于内存的消息缓存.图5.3显示了KahaDB
消息存储概览.
The diagram provides a view of the three distinct parts of the KahaDB message
store including the following:
图5.3展示了KahaDB消息存储的三个独立的构件如下所示:
The data logs act as a message journal, which 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. In the data logs, messages are only
appended to the end of the current data file, so storage is fast.
数据日志类似消息日记,用固定长度的文件保存滚动消息和命令(比如事务边界和消息删除指令).
当数据日志文件的大小达到最大值时,一个新的数据文件会被自动创建.日志文件中的所有消息
都会被引用计数,这样一旦文件中所有的消息都不在需要了,这个数据文件会被删除或者归档.
在数据日志中,消息只会被附加到当前文件的尾部,所以存储非常快.
The cache holds messages temporarily if there are active consumer(s) for the messages.
If there are active consumers, messages are dispatched at the same time they’re
scheduled to be stored. If messages are acknowledged in time, they don’t need
to be written to disk.
当有活动的消息消费者时,消息会临时放到缓存中.如果有活动的消费者,消息在被存储同时会被分发.
如果消息被处理并及时确认过,就没有必要将消息写入磁盘了.
The BTree indexes hold references to the messages in the data logs that are
indexed by their message ID. The indexes maintain the FIFO data structure for
queues and the durable subscriber pointers to their topic messages. The redo
log is used only if the ActiveMQ broker hasn’t shut down cleanly, and are used
to insure the integrity of the BTree index is maintained.
BTree索引文件保存数据日志文件中的消息引用,这些消息已根据消息ID建立了索引.消息索引
为消息队列维护一个先进先出的数据结构,同时维护由持久的消息订阅者指向其订阅的的主题中消息
的指针.重做日志文件仅用当ActiveMQ没有正常关闭时,保证BTree索引仍然完整.
The KahaDB uses different files on disk for its data logs and indexes, so in the next
section we’ll show a typical KahaDB directory structure.
KahaDB为数据日志和索引使用不同的磁盘文件,所以在下面的章节中我们将看到典型的KahaDB
目录结构.
5.2.2 The KahaDB message store directory structure
5.2.2 KahaDB消息存储的目录结构
When you start an ActiveMQ broker configured to use a KahaDB store, a directory will
automatically be created in which the persistent messages are stored. This directory
structure is shown in figure 5.4.
当你启动了配置KahaDB存储的ActiveMQ代理是,消息存储持久化文件目录会自动创建,该目录结构
如图5.4所示:
Inside of the KahaDB directory, the following directory and file structures can be
found:
KahaDB的目录结构中的目录和文件如下:
db log files—KahaDB stores messages into data log files named db-<Number>.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 log 文件 --KahaDB将消息存储到数据日志文件中,该文件命名方式为db-<编号>.log,文件大小事先已经定义好.
当数据日志文件达到预定的大小,一个新的文件会自动创建,同时文件名中的编号自动加1.如果没有任何引用指向
数据日志文件中的消息,那么该日志文件将被删除或者归档.
archive directory—This exists only if archiving is enabled. The archive is used to store data logs
that are no longer needed by KahaDB, making it possible to replay messages from the archived data
logs at a later point. If archiving isn’t enabled(the default), data logs that are no longer in
use are deleted from the file system.
归档目录 -- 归档目录仅在启用归档时才会出现.归档文件用于存储那些不再被KahaDB使用的数据日志文件.
使用归档文件可以保存消息以便以后重新检视消息变为可能.如果没有启用归档功能(默认不启用归档),不在使用的数据
日志文件会从文件系统中删除.
db.data —This file contains the persistent BTree indexes to the messages held in the message data logs.
db.data -- 该文件保存了数据日志文件中消息的持久化BTree索引.
db.redo —This is the redo file, used for recovering the BTree indexes if the KahaDB
message store starts after a hard stop.
db.redo -- 这是重做日志文件,用于KahaDB从一次非正常关闭后重启时恢复BTree索引.
Now that we’ve covered the basics of the KahaDB store, the next step is to review its
configuration.
现在我们已经了解了KahaDB的基础知识,下一步让我们回顾下KahaDB的配置.
5.2.3 Configuring the KahaDB message store
5.2.3 配置KahaDB消息存储
The KahaDB message store can be configured in the activemq.xml file. Its configuration
options control the different tuning parameters, as described in table 5.1.
可以在activemq.xml文件中配置KahaDB消息存储.不同的配置选择控制控制不同的功能参数,如表
5.1所示:
Table 5.1 Configuration options available for the KahaDB message store
表5.1 KahaDB消息存储的配置选项
Property name Default value Description
属性名 默认值 描述
directory activemq-data Directory path used by KahaDB
directory activemq-data KahaDB使用的目录
indexWriteBatchSize 1000 Number of index pages to write in a batch to disk
indexWriteBatchSize 1000 一次写入磁盘的属性页数量
indexCacheSize 10000 Number of index pages cached in memory
indexCacheSize 10000 内存中缓存的所引用数量
enableIndexWriteAsync false If set, will asynchronously write indexes
enableIndexWriteAsync false 如果设置为true,索引将以异步方式写入
journalMaxFileLength 32mb A hint to set the maximum size of each of the message data logs
journalMaxFileLength 32mb 设置每个消息数据日志文件的最大尺寸
enableJournalDiskSyncs true Ensures every nontransactional journal write is followed
by a disk sync (JMS durability requirement)
enableJournalDiskSyncs true 保证每个非事务日志写操作后进行磁盘同步(JMS持久化要求)
cleanupInterval 30000 Time (ms) before checking for and discarding/moving message
data logs that are no longer used
cleanupInterval 30000 检查 丢弃/移动数据日志文件中是不不再使用的消息 间隔时间(单位 毫秒)
checkpointInterval 5000 Time (ms) before checkpointing the journal
checkpointInterval 5000 执行checkpoint的时间间隔
ignoreMissingJournalfiles false If enabled, will ignore a missing message log file
ignoreMissingJournalfiles false 如果启用,则忽视丢失消息日志(译注:在消息丢失时不记录日志)
checkForCorruptJournalFiles false If enabled, on startup will validate that the message data logs haven’t been corrupted.
checkForCorruptJournalFiles false 如果启用,在启动是会检查消息数据日志文件是否被占用
checksumJournalFiles false If enabled, will provide a checksum foreach message data log
checksumJournalFiles false 如果启用,将为每一个消息数据日志问价开启检查消息总数服务
archiveDataLogs false If enabled, will move a message data log to the archive directory instead of deleting it
archiveDataLogs false 如果启用,不用的消息数据文件会被移动到归档目录 而不是删除掉
directoryArchive null Defines the directory to move data logs to when all the messages they contain have been consumed
directoryArchive null 存放规定文件的目录
databaseLockedWaitDelay 10000 Time (ms) before trying to acquire the database lock (used by shared master/slave)
databaseLockedWaitDelay 10000 尝试获取数据库锁的等待时间(用于共享主/从数据库)
maxAsyncJobs 10000 Maximum number of asynchronous messages that will be queued awaiting
storage (should be the same as the number of concurrent MessageProducers)
maxAsyncJobs 10000 排队等待存储的异步消息的最大数量(应该和并发的消息生产者数量相同)
concurrentStoreAndDispatchTransactions true Enables the dispatching of messages to interested clients to happen concurrently with transaction storage
concurrentStoreAndDispatchTransactions true 允许在存储事务时分发消息到对其感兴趣的客户端
concurrentStoreAndDispatchTopics true Enables the dispatching of topic messages to interested clients to happen concurrently with message storage
concurrentStoreAndDispatchTopics true 允许在存储消息时,分发主题中的消息给对其感兴趣的客户端
concurrentStoreAndDispatchQueues true Enables the dispatching of queue messages to interested clients to happen concurrently with message storage
concurrentStoreAndDispatchQueues true 允许在存储消息是,分发队列中的消息给对其感兴趣的客户端
ActiveMQ provides a pluggable API for message stores, and there are three additional
implementations to KahaDB that are shipped with ActiveMQ:
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
ActiveMQ为消息存储提供了一种可插拔式的API.ActiveMQ版本中包含一下三种KahaDB消息存储实现:
AMQ 消息存储 -- 基于文件的高性能消息存储
JDBC 消息存储 -- 基于JDBC的消息存储
Memory 消息存储 -- 基于内存的消息存储
We’ll look at the use cases and configuration for these additional message stores in the
next three sections. We’ll start with the AMQ message store, which like the KahaDB
message store is a file-based implementation. It predates KahaDB, but because of its
performance characteristics, it can make sense to use the AMQ store instead of
KahaDB, provided the number of persistent destinations is relatively low.
在接下来的三个章节中,我们将看到这三个消息存储的应用实例和配置方法.我们将从AMQ消息存储开始,
AMQ消息存储和KahaDB类似是基于文件的存储实现,但鉴于改存储方式的高性能特性,可以使用AMQ消息存储
替代KahaDB,但AMQ消息存储可提供的持久化目的地的数量比较少.
相关推荐
**CCSv5.2中文使用说明** **一、CCSv5.2简介** CCS,全称为Code Composer Studio,是由Texas Instruments(TI)公司开发的一款强大的集成开发环境(IDE),专门用于针对TI的微处理器和微控制器进行应用程序开发。...
asm-all-5.2.jar asm-all-5.2.jar asm-all-5.2.jar asm-all-5.2.jar asm-all-5.2.jar asm-all-5.2.jar asm-all-5.2.jar asm-all-5.2.jar asm-all-5.2.jar asm-all-5.2.jar asm-all-5.2.jar asm-all-5.2.jar asm-all-...
蓝牙5.2核心规范 蓝牙5.2核心规范是 Bluetooth SIG(蓝牙特别兴趣集团)发布的一份核心规范文档,旨在确保蓝牙设备之间的互操作性。该规范定义了蓝牙设备所需的技术,包括蓝牙协议栈、蓝牙设备架构、蓝牙应用程序...
"mstsc5.2"指的是这个客户端的一个特定版本。 在mstsc5.2中,用户可以访问远程电脑的桌面环境,如同坐在那台电脑前一样,执行各种任务,如打开应用程序、编辑文档、管理文件等。这一版本的mstsc可能包含了一些针对...
《蓝牙5.2核心协议详解》 蓝牙技术作为无线通信领域的主流标准,已经广泛应用于我们的日常生活,如无线耳机、智能手表、智能家居等。随着技术的不断迭代,蓝牙5.2核心协议应运而生,为物联网(IoT)提供更高效、安全...
《单双色五代软件LED Player 5.2:深入解析与应用》 在LED显示技术日益发达的今天,各种专业软件的出现极大地提升了显示效果和操作效率。其中,LED Player 5.2作为一款专注于单双色显示的控制软件,因其易用性和...
西门子贴片机知识PRO 5.2安装步骤 1.pro5.2协议 ----DotNetFramework-----WinXP----1.1----dotnetfx; 2.pro5.2协议 ----DotNetFramework-----WinXP----1.1 SP1----NDP1.1sp1-KB867460-X86; 3.pro5.2协议 ----...
UniSolder-5.2C 俄罗斯开源
在标题和描述中提到的“蓝牙核心协议v5.2pdf”是指蓝牙技术联盟(SIG)发布的蓝牙5.2版本的核心规范文档。这份文档详细阐述了蓝牙5.2的所有核心技术、协议栈以及实现细节,是开发、设计和优化蓝牙设备的基础。 蓝牙...
INODE PC 版本 .5.2
acs5.2破解安装教程 首先要网上找ACS5.2的破解ISO 然后根据文档一步一步操作
ACS+5.2安装破解教程+5.2lincese
APM 5.2简体中文 APM 5.2简体中文
NCVIEWER5.2是一款专为NC(计算机数控)编程和制造领域设计的查看软件,主要服务于使用UG、沪东、TRIBON等CAD/CAM软件的用户。这款工具提供了强大的功能,帮助工程师和程序员在不打开原始CAD系统的情况下查看、分析...
VirtualBox 5.2.44是VirtualBox5.2系列的最新版本 VirtualBox是一个跨平台的虚拟化应用程序。它可以安装在现有的基于Intel或AMD的计算机上,无论它们运行的是Windows,Mac,Linux还是Solaris操作系统。它扩展了...
【黑群晖_完整安装包_DSM_5.2-5644】是一个针对NAS(网络附加存储)系统的软件套件,由群辉科技(Synology)开发的DiskStation Manager(DSM)操作系统的一个特定版本。这个版本是5.2-5644,它提供了丰富的功能和...
PHP 5.2中的数组功能强大,可以存储不同类型的数据,并提供多种操作数组的方法,如`array_push`、`array_pop`、`array_merge`、`array_slice`等。此外,还引入了关联数组,允许使用字符串作为键。 四、错误处理和...
《ZYtrans5.2:一款超好用的即时翻译工具详解》 在信息化时代,语言不再成为交流的障碍,各种翻译工具应运而生,其中ZYtrans5.2以其高效、便捷的特点,深受广大用户的喜爱。这款即时翻译工具,不仅在文献翻译方面...
据悉,此次瑞友天翼应用虚拟化系统5.2版本升级主要围绕优化用户体验、提升用户办公效率,以此打造企业专属的信息管理平台。通过加入Windows认证、HTTPS协议安全访问等便捷的功能,瑞友天翼应用虚拟化系统将为用户...
用户可以通过中国最大的云存储平台获取软件,这大大降低了下载和部署的难度,尤其是对于网络环境不稳定的地区或企业,这种便捷的下载方式显得尤为实用。 再者,5.2.txt这个文件名可能包含了软件的使用指南、安装...