JMS message Persistence, persisting ACTIVEMQ messages to MySQL database

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.