ActiveMQ持久化消息的三种方式

http://www.cnblogs.com/tommyli/archive/2010/09/13/1825205.html

1:前言

     这一段给公司开发消息总线有机会研究ActiveMQ,今天撰文给大家介绍一下他的持久化消息。本文只介绍三种方式,分别是持久化为文件,MYSql,Oracle。下面逐一介绍。

A:持久化为文件

     这个你装ActiveMQ时默认就是这种,只要你设置消息为持久化就可以了。涉及到的配置和代码有

  
    
< persistenceAdapter >
< kahaDB directory = " ${activemq.base}/data/kahadb " />
</ persistenceAdapter >

producer.Send(request, MsgDeliveryMode.Persistent, level, TimeSpan.MinValue);

B:持久化为MySql

     你首先需要把MySql的驱动放到ActiveMQ的Lib目录下,我用的文件名字是:mysql-connector-java-5.0.4-bin.jar

     接下来你修改配置文件

  
    
< persistenceAdapter >
< jdbcPersistenceAdapter dataDirectory = " ${activemq.base}/data " dataSource = " #derby-ds " />
</ persistenceAdapter >

在配置文件中的broker节点外增加

复制代码
  
    
< bean id = " derby-ds " class = " org.apache.commons.dbcp.BasicDataSource " destroy - method = " close " >
< property name = " driverClassName " value = " com.mysql.jdbc.Driver " />
< property name = " url " value = " jdbc:mysql://localhost/activemq?relaxAutoCommit=true " />
< property name = " username " value = " activemq " />
< property name = " password " value = " activemq " />
< property name = " maxActive " value = " 200 " />
< property name = " poolPreparedStatements " value = " true " />
</ bean >
复制代码

从配置中可以看出数据库的名称是activemq,你需要手动在MySql中增加这个库。

然后重新启动消息队列,你会发现多了3张表

1:activemq_acks

2:activemq_lock

3:activemq_msgs

C:持久化为Oracle

    和持久化为MySql一样。这里我说两点

1;在ActiveMQ安装文件夹里的Lib文件夹中增加Oracle的JDBC驱动。驱动文件位于Oracle客户端安装文件中的product\11.1.0\client_1\jdbc\lib文件夹下。

2:

复制代码
  
    
< bean id = " derby-ds " class = " org.apache.commons.dbcp.BasicDataSource " destroy - method = " close " >
< property name = " driverClassName " value = " oracle.jdbc.driver.OracleDriver " />
< property name = " url " value = " jdbc:oracle:thin:@10.53.132.47:1521:cmfudv1 " />
< property name = " username " value = " qdcommu " />
< property name = " password " value = " qdcommu " />
< property name = " maxActive " value = " 200 " />
< property name = " poolPreparedStatements " value = " true " />
</ bean >
复制代码

这里的jdbc:oracle:thin:@10.53.132.47:1521:cmfudv1按照自己实际情况设置一下就可以了,特别注意的是cmfudv1是SID即服务名称而不是TNS中配置的节点名。各位同学只需要替换IP,端口和这个SID就可以了。

后记:

这篇文章就是简单的记录一下操作过程,避免后来的同学走弯路。

你可能感兴趣的:(activemq)