ActiveMQ in Action(3)

2.3 Persistence
2.3.1 AMQ Message Store
    AMQ Message Store是ActiveMQ5.0 缺省的持久化存储。Message commands被保存到transactional journal(由rolling data logs组成)。Messages被保存到data logs中,同时被reference store进行索引以提高存取速度。Date logs由一些单独的data log文件组成,缺省的文件大小是32M,如果某个消息的大小超过了data log文件的大小,那么可以修改配置以增加data log文件的大小。如果某个data log文件中所有的消息都被成功消费了,那么这个data log文件将会被标记,以便在下一轮的清理中被删除或者归档。以下是其配置的一个例子:

Xml代码 复制代码
  1. < broker   brokerName = "broker"   persistent = "true"   useShutdownHook = "false" >   
  2.    < persistenceAdapter >   
  3.       < amqPersistenceAdapter   directory = "${activemq.base}/data"   maxFileLength = "32mb" />   
  4.    </ persistenceAdapter >   
  5. </ broker >   
Xml代码
  1. < broker   brokerName = "broker"   persistent = "true"   useShutdownHook = "false" >   
  2.   < persistenceAdapter >   
  3.      < amqPersistenceAdapter   directory = "${activemq.base}/data"   maxFileLength = "32mb" />   
  4.   </ persistenceAdapter >   
  5. </ broker >   
Property name Default value Comments
directoryactivemq-datathe path to the directory to use to store the message store data and log files
useNIOtrueuse NIO to write messages to the data logs
syncOnWritefalsesync every write to disk
maxFileLength32mba hint to set the maximum size of the message data logs
persistentIndextrueuse a persistent index for the message logs. If this is false, an in-memory structure is maintained
maxCheckpointMessageAddSize4kbthe maximum number of messages to keep in a transaction before automatically committing
cleanupInterval30000time (ms) before checking for a discarding/moving message data logs that are no longer used
indexBinSize1024default number of bins used by the index. The bigger the bin size - the better the relative performance of the index
indexKeySize96the size of the index key - the key is the message id
indexPageSize16kbthe size of the index page - the bigger the page - the better the write performance of the index
directoryArchivearchivethe path to the directory to use to store discarded data logs
archiveDataLogsfalseif true data logs are moved to the archive directory instead of being deleted

 

2.3.2 Kaha Persistence
    Kaha Persistence 是一个专门针对消息持久化的解决方案。它对典型的消息使用模式进行了优化。在Kaha中,数据被追加到data logs中。当不再需要log文件中的数据的时候,log文件会被丢弃。以下是其配置的一个例子:

Xml代码 复制代码
  1. < broker   brokerName = "broker"   persistent = "true"   useShutdownHook = "false" >   
  2.        < persistenceAdapter >   
  3.          < kahaPersistenceAdapter   directory = "activemq-data"   maxDataFileLength = "33554432" />   
  4.        </ persistenceAdapter >   
  5. </ broker >   
Xml代码
  1. < broker   brokerName = "broker"   persistent = "true"   useShutdownHook = "false" >   
  2.       < persistenceAdapter >   
  3.         < kahaPersistenceAdapter   directory = "activemq-data"   maxDataFileLength = "33554432" />   
  4.       </ persistenceAdapter >   
  5. </ broker >   

 

2.3.3 JDBC Persistence
    目前支持的数据库有Apache Derby, Axion, DB2, HSQL, Informix, MaxDB, MySQL, Oracle, Postgresql, SQLServer, Sybase。
    如果你使用的数据库不被支持,那么可以调整StatementProvider 来保证使用正确的SQL方言(flavour of SQL)。通常绝大多数数据库支持以下adaptor:

  • org.activemq.store.jdbc.adapter.BlobJDBCAdapter
  • org.activemq.store.jdbc.adapter.BytesJDBCAdapter
  • org.activemq.store.jdbc.adapter.DefaultJDBCAdapter
  • org.activemq.store.jdbc.adapter.ImageJDBCAdapter

   也可以在配置文件中直接指定JDBC adaptor,例如:

Xml代码 复制代码
  1. < jdbcPersistenceAdapter    adapterClass = "org.apache.activemq.store.jdbc.adapter.ImageBasedJDBCAdaptor" />   
Xml代码
  1. < jdbcPersistenceAdapter    adapterClass = "org.apache.activemq.store.jdbc.adapter.ImageBasedJDBCAdaptor" />   
    以下是其配置的一个例子:

 

Xml代码 复制代码
  1. < persistence >   
  2.        < jdbcPersistence   dataSourceRef = " mysql-ds" />   
  3. </ persistence >   
  4.   
  5. < bean   id = "mysql-ds"   class = "org.apache.commons.dbcp.BasicDataSource"   destroy-method = "close" >   
  6.        < property   name = "driverClassName"   value = "com.mysql.jdbc.Driver" />   
  7.        < property   name = "url"   value = "jdbc:mysql://localhost/activemq?relaxAutoCommit=true" />   
  8.        < property   name = "username"   value = "activemq" />   
  9.        < property   name = "password"   value = "activemq" />   
  10.        < property   name = "poolPreparedStatements"   value = "true" />   
  11. </ bean >   
Xml代码
  1. < persistence >   
  2.       < jdbcPersistence   dataSourceRef = " mysql-ds" />   
  3. </ persistence >   
  4.   
  5. < bean   id = "mysql-ds"   class = "org.apache.commons.dbcp.BasicDataSource"   destroy-method = "close" >   
  6.       < property   name = "driverClassName"   value = "com.mysql.jdbc.Driver" />   
  7.       < property   name = "url"   value = "jdbc:mysql://localhost/activemq?relaxAutoCommit=true" />   
  8.       < property   name = "username"   value = "activemq" />   
  9.       < property   name = "password"   value = "activemq" />   
  10.       < property   name = "poolPreparedStatements"   value = "true" />   
  11. </ bean >   

    需要注意的是,如果使用MySQL,那么需要设置relaxAutoCommit 标志为true。

 

2.3.4 Disable Persistence
    以下是其配置的一个例子:

Xml代码 复制代码
  1. < broker   persistent = "false" >   
  2. </ broker >   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值