Home > Database > Mysql Tutorial > body text

JMS消息持久化,将ActiveMQ消息持久化到mySql数据库中_MySQL

WBOY
Release: 2016-06-01 13:13:59
Original
1412 people have browsed it

ActiveMQ5.8.0版本采用kahadb作为默认的消息持久化方式。使用默认的持久化机制,我们不容易直接看到消息究竟是如何持久的。ActiveMQ提供的JDBC持久化机制,能够将持久化信息存储到数据库。通过查看数据库中ActiveMQ生成的表结构和存储的数据,能够帮助我们更好的了解消息的持久化机制。现在介绍如何配置activemq,将数据持久化到mysql中。

1.配置activeMQ需要的mySql数据源

为了能够使用JDBC访问mysql数据库,显然必须要配置消息服务器的数据库源。在activemq/apache-activemq-5.8.0/conf/activemq.xml进行配置

<!-- MySQL DataSource -->	<bean id="mysqlDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">		<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>		<property name="url" value="jdbc:mysql://127.0.0.1:3306/amq_db?relaxAutoCommit=true"></property>		<property name="username" value="root"></property>		<property name="password" value="root"></property>		<property name="poolPreparedStatements" value="true"></property>	</bean>
Copy after login
在结点之后,增加数据源的配置

2.改变activeMQ默认的持久化方式

在activemq.xml中注释掉默认的kahadb,使用jdbc持久化

<!--		<persistenceAdapter>			<kahaDB directory="${activemq.data}/kahadb"/>		</persistenceAdapter>		-->				<persistenceadapter>			<jdbcpersistenceadapter datasource="#mysqlDataSource"></jdbcpersistenceadapter>		</persistenceadapter>
Copy after login
3.提供mysql的驱动程序

由于activeMQ消息服务器,没有自带mysql数据库的驱动程序。我们需要手动将mysql驱动添加到消息服务器。

方法是将驱动拷贝到apache-activemq-5.8.0/lib/目录下。

经过上面的三步配置,我们重新启动消息服务器,就可以发现activeMQ在数据库中新建了3张表

activemq_acks  ,activemq_lock  ,activemq_msgs 。至此数据库持久化完成。后续博客会继续介绍这3张表的含义和使用,目前我还不清楚。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!