The ActiveMQ5.8.0 version uses KAHADB as the default message persistence method. Using the default persistence mechanism, it is not easy to see exactly how the message lasts. ACTIVEMQ provides a JDBC persistence mechanism to store persistent information in a database. By looking at the table structure and stored data generated by ACTIVEMQ in the database, you can help us better understand the persistence mechanism of the message. Now we'll show you how to configure ACTIVEMQ to persist data to MySQL.
1. Configure the MySQL data source required by the ACTIVEMQ
To be able to access the MySQL database using JDBC, it is clear that you must configure the database source for the messaging server. Configuring in 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 name = "url" value= "jdbc:mysql://127.0.0.1:3306/amq_db?relaxautocommit=true"/><property name= "username" value= " Root "/><property name=" password "value=" root "/><property name=" poolpreparedstatements "value=" true "/ ></bean>
After the </broker> node, increase the configuration of the data source
2. Change the ACTIVEMQ default persistence mode
Commenting out the default kahadb in Activemq.xml , using JDBC persistence
<!-- <persistenceAdapter> <kahadb directory= "${activemq.data}/kahadb"/> </ Persistenceadapter>--><persistenceadapter><jdbcpersistenceadapter dataSource= "#mysqlDataSource"/ ></persistenceAdapter>
3. Provide the MySQL driver
Because of the ACTIVEMQ messaging server, there is no driver for the MySQL database. We need to manually add the MySQL driver to the messaging server.
The method is to copy the driver to the Apache-activemq-5.8.0\lib\ directory.
With the three-step configuration above, we restart the messaging server and we can see that ACTIVEMQ has created 3 new tables in the database.
activemq_acks ,activemq_lock , Activemq_msgs. This completes the database persistence. The follow-up blog will continue to describe the meaning and use of these 3 tables, and I am not sure yet.