Use SpringBoot to Deploy ActiveMQ Broker to Tomcat-2/3

This post is to continue the first part of the same topic. It mainly covers:

  1. Use commercial database as the data store
  2. Use the embedded Tomcat to manage the data source connection pool

Background

Despite the fact that the ActiveMQ buildin Kaha database is more efficient when handling messages, we sometimes need to take other consideration too. For example, if your production environment prefers to database based backup and disaster recovery than NAS, you have to consider database.

Use MS-SQL-Server as the data store

There are many ways to create a datasource for ActiveMQ. This post creates one with SpringBoot and pass it to Tomcat for pool management.

Step#1: Add dependency spring-boot-starter-jdbc into the build file, and then add the following section into the application.properties file

spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=jms
spring.datasource.username=user
spring.datasource.password=password

Step#2: Disable broker auto-start. You need to ensure the broker is started after the data source is injected. This is done by calling

BrokerFactory.setStartDefault(false);

in the SpringBoot main() method, and then explicitly start it after setting the persistent adapter for the broker:

broker.setPersistenceAdapter(jdbcPersistenceAdapter);
broker.start();

Use Tomcat to manage the connection pool

This can be easily done by adding the following into application.properties file

#Tomcat connection pool
spring.datasource.tomcat.max-active=10
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.validation_query=SELECT 1
spring.datasource.tomcat.log_abandonded=true
spring.datasource.tomcat.remove_abandonded=true
spring.datasource.tomcat.remove_abandonded_timeout=60

Source Code

The source code can be viewed or downloaded from here.

Special Notes

You may see build error due to missing mssql jdbc driver. You need to specify your repository that hosts the driver artifact, or put it into your local gradle cache.

You can find the next related post here.

Advertisements
This entry was posted in Java and tagged , , , , . Bookmark the permalink.

One Response to Use SpringBoot to Deploy ActiveMQ Broker to Tomcat-2/3

  1. Pingback: Use SpringBoot to Deploy ActiveMQ Broker to Tomcat 1/2 | SW Notes

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s