1. Preface
ActiveMQ is the most popular, powerful, open source messaging bus that Apache has produced. ActiveMQ is a JMS provider implementation that fully supports the JMS1.1 and the Java EE 1.4 specification, although the JMS specification has been around for a long time, but JMS still plays a special role in the middle of today's Java EE applications.
For more information about ACTIVEMQ, please refer to:Http://baike.baidu.com/view/433374.htm?fr=aladdin
For more information on JMS, please refer to:Http://baike.baidu.com/subview/157103/12665866.htm?fr=aladdin
ACTIVEMQ provides a variety of data persistence methods: It can be persisted to a file, or it can be persisted to a database, where the database can support two types of MySQL and Oracle.
The default is to persist to a file in a way that is in the Activemq.xml file:
<persistenceAdapter>
<KAHADB directory= "${activemq.base}/data/kahadb"/>
</persistenceAdapter>
2. Steps
The focus of this article is on how to configure persistence to MySQL:
2.1 Adding MySQL Drivers
First need to put the MySQL driver into the activemq Lib directory, I use the file name is: Mysql-connector-java-5.1.30-bin.jar
2.2 Modifying the configuration file Activemq.xml
This section of the configuration will be:
<persistenceAdapter>
<KAHADB directory= "${activemq.base}/data/kahadb"/>
</persistenceAdapter>
Modify it to the following paragraph:
<persistenceAdapter>
<jdbcpersistenceadapter datasource= "#derby-ds"/>
</persistenceAdapter>
It is also necessary to define a bean with ID derby-ds above the broker node, as follows:
<beanid= "Derby-ds" class= "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close" >
<propertyname= "Driverclassname" value= "Com.mysql.jdbc.Driver"/>
<property name= "url" value= "Jdbc:mysql://localhost:3306/test_mq?relaxautocommit=true"/>
<propertyname= "username" value= "root"/>
<propertyname= "Password" value= "root"/>
<propertyname= "maxactive" value= "/>"
<propertyname= "Poolpreparedstatements" value= "true"/>
</bean>
2.3 New Database
As you can see from the configuration, the name of the database is TEST_MQ and you need to manually create a new TEST_MQ empty database in MySQL.
At this point, restart MQ, you will find the TEST_MQ library more than three tables: Activemq_acks,activemq_lock,activemq_msgs,ok, the description has been persistent success!
Apache ActiveMQ Simple configuration for persistent to MySQL database