持久化 http://activemq.apache.org/persistence.html
消息存储 http://activemq.apache.org/amq-message-store.html
Kaha Persistence 基于文件式的本地存储持久化方案,速度最快(现在已经是AMQ默认的持久化方式)可轻松恢复。
Kaha存储数据的方式类似于写日志,它在文件结尾追加记录。消息被存储在单个文件中,文件大小以配置为准,默认是32MB(如果消息本身大于32MB可以修改配置文件)当所有存储在data log中的消息都被成功的消费后,这个日志文件将被标识为待删除或归档,待下一次系统自动清理时将会被清除。
ActiveMQ 5.0 and above:
<broker brokerName="broker" persistent="true" useShutdownHook="false"> <transportConnectors> <transportConnector uri="tcp://localhost:61616"/> </transportConnectors> <persistenceAdapter> <kahaPersistenceAdapter directory="activemq-data" maxDataFileLength="33554432"/> </persistenceAdapter> </broker> |
ActiveMQ 4.1 and earlier:
<broker brokerName="broker" persistent="true" useShutdownHook="false"> <transportConnectors> <transportConnector uri="tcp://localhost:61616"/> </transportConnectors> <persistenceAdapter> <kahaPersistenceAdapter dir="activemq-data" maxDataFileLength="33554432"/> </persistenceAdapter> </broker> |
如果将属性persistent设置为false,那么消息将采用内存式的存储方式。
每个kahadb实例都可以单独配置,如果没有指定目标队列支持filteredKahaDB,默认值将匹配每一个队列或主题。这将灵活的捕获所有,否则将会因为一个异常而创建失败。
配置方式如下
<broker brokerName="broker" ... >
<persistenceAdapter>
<mKahaDB directory="${activemq.base}/data/kahadb">
<filteredPersistenceAdapters>
<!-- match all queues -->
<filteredKahaDB queue=">">
<persistenceAdapter>
<kahaDB journalMaxFileLength="32mb"/>
</persistenceAdapter>
</filteredKahaDB>
<!-- match all destinations -->
<filteredKahaDB>
<persistenceAdapter>
<kahaDB enableJournalDiskSyncs="false"/>
</persistenceAdapter>
</filteredKahaDB>
</filteredPersistenceAdapters>
</mKahaDB>
</persistenceAdapter>
...
</broker>
Automatic per destination persistence adapter
如果filteredKahaDB的perDestination属性设置为true,那么匹配的目标队列将会得到自己对应的KahaDB实例。配置
When the perDestination boolean attribute is set to true on the catch all (no explicit destination set), filteredKahaDB. Each matching destination will get its own kahaDB instance.
<broker brokerName="broker" ... > <persistenceAdapter> <mKahaDB directory="${activemq.base}/data/kahadb"> <filteredPersistenceAdapters> <!-- kahaDB per destinations --> <filteredKahaDB perDestination="true" > <persistenceAdapter> <kahaDB journalMaxFileLength="32mb" /> </persistenceAdapter> </filteredKahaDB> </filteredPersistenceAdapters> </mKahaDB> </persistenceAdapter> ... </broker> |
Note:
Specifying
perDestination="true" and queue=">"
on the same line has not been verified to work and may result in
Reason: java.io.IOException: File '/opt/java/apache-activemq-5.9.0/data/mKahaDB/lock' could not be locked as lock is already held for this jvm.