Using a JDBC Store for ArtemisMQ

The release 1.4.0 of ArtemisMQ added experimental support for JDBC Store. Although this support needs some more improvements before you can throw it in production, it’s worth learning this option especially if you are migrating existing ActiveMQ installations.

Let’s see how to configure it. First of all, ArtemisMQ JDBC Store is available now with a limited set of DB Vendors which include:

  • Postgres 9.4
  • Derby Embedded DB 10.11
  • MySQL 5.7

In this example, we will show how to configure it with Postgres 9.4 Database. The first step will be copying the JDBC Driver into the lib folder of your ArtemisMQ installation:

$ cp postgresql-9.4-1204.jdbc4.jar /usr/apache/apache-artemis-1.4.0/lib

Next, we will need including the JDBC configuration into the broker.xml file of your ArtemisMQ instance. Here’s an example:

<?xml version='1.0'?>

<configuration xmlns="urn:activemq"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">

   <jms xmlns="urn:activemq:jms">
      <queue name="DLQ"/>
      <queue name="ExpiryQueue"/>

   </jms>

   <core xmlns="urn:activemq:core">

      <name>0.0.0.0</name>

      <persistence-enabled>true</persistence-enabled>

      <!-- this could be ASYNCIO or NIO
       -->
      <journal-type>ASYNCIO</journal-type>

      <paging-directory>./data/paging</paging-directory>

      <bindings-directory>./data/bindings</bindings-directory>

      <journal-directory>./data/journal</journal-directory>

      <large-messages-directory>./data/large-messages</large-messages-directory>

      <journal-min-files>2</journal-min-files>

      <journal-pool-files>-1</journal-pool-files>

      <journal-buffer-timeout>119999</journal-buffer-timeout>

      <disk-scan-period>5000</disk-scan-period>

      <max-disk-usage>90</max-disk-usage>

      <global-max-size>104857600</global-max-size>

      <store>
         <database-store>
            <jdbc-connection-url>jdbc:postgresql://user:pass@localhost</jdbc-connection-url>
            <bindings-table-name>BINDINGS_TABLE</bindings-table-name>
            <message-table-name>MESSAGE_TABLE</message-table-name>
            <large-message-table-name>LARGE_MESSAGES_TABLE</large-message-table-name>
            <jdbc-driver-class-name>org.postgresql.Driver</jdbc-driver-class-name>
         </database-store>
      </store>


      <acceptors>
         <acceptor name="artemis">tcp://0.0.0.0:61616?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576</acceptor>

         <!-- AMQP Acceptor.  Listens on default AMQP port for AMQP traffic.-->
         <acceptor name="amqp">tcp://0.0.0.0:5672?protocols=AMQP</acceptor>

         <!-- STOMP Acceptor. -->
         <acceptor name="stomp">tcp://0.0.0.0:61613?protocols=STOMP</acceptor>

         <!-- HornetQ Compatibility Acceptor.  Enables HornetQ Core and STOMP for legacy HornetQ clients. -->
         <acceptor name="hornetq">tcp://0.0.0.0:5445?protocols=HORNETQ,STOMP</acceptor>

         <!-- MQTT Acceptor -->
         <acceptor name="mqtt">tcp://0.0.0.0:1883?protocols=MQTT</acceptor>

      </acceptors>


      <security-settings>
         <security-setting match="#">
            <permission type="createNonDurableQueue" roles="guest"/>
            <permission type="deleteNonDurableQueue" roles="guest"/>
            <permission type="createDurableQueue" roles="guest"/>
            <permission type="deleteDurableQueue" roles="guest"/>
            <permission type="consume" roles="guest"/>
            <permission type="browse" roles="guest"/>
            <permission type="send" roles="guest"/>
            <!-- we need this otherwise ./artemis data imp wouldn't work -->
            <permission type="manage" roles="guest"/>
         </security-setting>
      </security-settings>

      <address-settings>
         <!--default for catch all-->
         <address-setting match="#">
            <dead-letter-address>jms.queue.DLQ</dead-letter-address>
            <expiry-address>jms.queue.ExpiryQueue</expiry-address>
            <redelivery-delay>0</redelivery-delay>
            <!-- with -1 only the global-max-size is in use for limiting -->
            <max-size-bytes>-1</max-size-bytes>
            <message-counter-history-day-limit>10</message-counter-history-day-limit>
            <address-full-policy>PAGE</address-full-policy>
         </address-setting>
      </address-settings>
   </core>
</configuration>

That’s it. Start ArtemisMQ and thr Broker will create automatically the tables required to run the JDBC Persistence.

Please note that further improvements are coming in future releases of ArtemisMQ. As you can see from this JIRA, in the release 1.5.0 there will be support of passing as argument a Datasource: https://issues.apache.org/jira/browse/ARTEMIS-714 This will be the foundation for embedding this feature in the application server WildFly.

Found the article helpful? if so please follow us on Socials