Use SpringBoot to Deploy ActiveMQ Broker to Tomcat 3/3

ActiveMQ supports LeaseDatabaseLocker in its recent releases to increase its reliability when handling database failover. With the previous default database locker, the master broker holds the lock until it initiates a request to release the lock. This is problematic when database fails or the network is disconnected abruptly. In such cases, the master can not properly release the lock anymore therefore neither the master nor the slave, until the brokers are restarted, can own the lock after the database comes back. This is often not desirable in production environment.

LeaseDatabaseLocker is implemented to overcome this weakness. With this, the master essentially creates a row in the activemq_lock table and uses it as a lock. The lock is only effective for a period of time. If it is not renewed/refreshed before expiry, any broker can take over the lock ownership when the database becomes accessible.

The code to configure the LeaseDatabaseLocker looks like

  @Bean
  public PersistenceAdapter persistenceAdapter(DataSource dataSource,
      @Value("${activemq.broker.name}") String brokerName) throws Exception {
    JDBCPersistenceAdapter jdbcPersistenceAdapter =
        new JDBCPersistenceAdapter(dataSource, new OpenWireFormat());
    broker.setPersistenceAdapter(jdbcPersistenceAdapter);
    LeaseDatabaseLocker locker = new LeaseDatabaseLocker();
    locker.setDataSource(dataSource);
    locker.setLeaseHolderId(brokerName);
    // TODO: externalize the value into application.properties
    //This value must be greater than the LockKeepAlivePeriod
    locker.setLockAcquireSleepInterval(5000);
    jdbcPersistenceAdapter.setLocker(locker);
    // TODO: externalize the value into application.properties
    jdbcPersistenceAdapter.setLockKeepAlivePeriod(1000);
    broker.start();
    return jdbcPersistenceAdapter;
  }

Notice how the lock holding period and the refresh period are configured by the setLockAcquireSleepInterval() and setLockKeepAlivePeriod() respectively.

Please be aware that you’d better to use DBCP2 connection pool to manage the data source connections for this application. If Tomcat pool manager is used, you may experience database blocking problem. The full configuration can be found from the source code.

You can find the two earlier posts related to this one: part1 and part2.

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

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

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

  2. Pingback: Use SpringBoot to Deploy ActiveMQ Broker to Tomcat 1/3 | 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