Advertise with us

Search Mastertheboss

Our eBooks

Using the ActiveMQ journal with a JDBC Store

In this tutorial we have described how to configure the JDBC Store with ActiveMQ: Using a JDBC Store with ActiveMQ . We will see now how we can improve the performance of it by using the ActiveMQ journal.

Using the ActiveMQ journal can improve the performance of the JDBC store as messages can be stored locally on the filesystem before being committed to the database. On the other hand, it cannot be used on a Master-Slave scenario as there is no guarantee that messages are exactly replicated if one of the Broker fails.

Here is the configuration of the Journal, which uses the MySQL JDBC datasource:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd   http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
 
       . . .
 
   <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">
      <destinationPolicy>
        . . . .
      </destinationPolicy>
      <managementContext>
         . . .
      </managementContext>
 
      <persistenceAdapter>
         <jdbcPersistenceAdapter dataDirectory="${activemq.base}/data" dataSource="#mysql-ds" />
      </persistenceAdapter>
 
      <systemUsage>
        . . . .
      </systemUsage>
      <transportConnectors>
         . . .
         
      </transportConnectors>
 
      <shutdownHooks>
         <bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
      </shutdownHooks>
    <persistenceFactory>      
      <journalPersistenceAdapterFactory
        journalLogFiles="4"
        journalLogFileSize="32768"
        useJournal="true"
        useQuickJournal="true"
        dataSource="#mysql-ds"
        dataDirectory="activemq-data" />
    </persistenceFactory>
   </broker>
   <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/activemq?relaxAutoCommit=true" />
      <property name="username" value="francesco" />
      <property name="password" value="francesco" />
      <property name="maxActive" value="200" />
      <property name="poolPreparedStatements" value="true" />
   </bean>
   <import resource="jetty.xml" />
</beans>
© 2020 mastertheboss.com. All Rights Reserved.

Please publish modules in offcanvas position.