1) Create MySQL database.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> show databases; | |
+--------------------+ | |
| Database | | |
+--------------------+ | |
| information_schema | | |
| mysql | | |
| performance_schema | | |
| phpmyadmin | | |
+--------------------+ | |
4 rows in set (0.00 sec) | |
mysql> create database activemq; | |
Query OK, 1 row affected (0.00 sec) | |
mysql> show databases; | |
+--------------------+ | |
| Database | | |
+--------------------+ | |
| information_schema | | |
| activemq | | |
| mysql | | |
| performance_schema | | |
| phpmyadmin | | |
+--------------------+ | |
5 rows in set (0.00 sec) | |
mysql> use activemq; | |
Database changed | |
mysql> show tables; | |
Empty set (0.00 sec) | |
mysql> |
3) Edit
4) Add following configuration.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<beans ...> | |
<bean id="mysql-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:3306/activemq?relaxAutoCommit=true"/> | |
<property name="username" value="root"/> | |
<property name="password" value="root"/> | |
<property name="poolPreparedStatements" value="true"/> | |
</bean> | |
<broker ...> | |
<!-- | |
Configure message persistence for the broker. The default persistence | |
mechanism is the KahaDB store (identified by the kahaDB tag). | |
For more information, see: | |
http://activemq.apache.org/persistence.html | |
--> | |
<persistenceAdapter> | |
<!--kahaDB directory="${activemq.data}/kahadb"/--> | |
<jdbcPersistenceAdapter dataSource="#mysql-ds"/> | |
</persistenceAdapter> | |
</broker> | |
</beans> |
6) Start ActiveMQ server using $ ./activemq start ( To stop the server use ./activemq stop )
7) Log in to activeMQ management console using http://localhost:8161/ with admin:admin credentials.
8) Create a queue and send a message to the queue with persistence enabled.
9) You can see the message in database.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql> | |
mysql> show tables; | |
+--------------------+ | |
| Tables_in_activemq | | |
+--------------------+ | |
| ACTIVEMQ_ACKS | | |
| ACTIVEMQ_LOCK | | |
| ACTIVEMQ_MSGS | | |
+--------------------+ | |
3 rows in set (0.00 sec) | |
mysql> select * from ACTIVEMQ_MSGS; | |
+----+-------------------+-----------------------------------------------+-----------+------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+------+ | |
| ID | CONTAINER | MSGID_PROD | MSGID_SEQ | EXPIRATION | MSG | PRIORITY | XID | | |
+----+-------------------+-----------------------------------------------+-----------+------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+------+ | |
| 1 | queue://TestQueue | ID:hasitha-laptop-48562-1415139260206-3:1:1:1 | 1 | 0 | � { )ID:hasitha-laptop-48562-1415139260206-3:1 d TestQueue n{ )ID:hasitha-laptop-48562-1415139260206-3:1 I|�� | |
Hello world. I|�� | 0 | NULL | | |
+----+-------------------+-----------------------------------------------+-----------+------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+------+ | |
1 row in set (0.00 sec) | |
mysql> |
No comments:
Post a Comment