LibraryToggle FramesPrintFeedback

Basics of Using the JDBC Persistence Adapter

Overview

For long term persistence you may want to use a relational database as your persistent message store. Fuse MQ Enterprise's default database when using the JDBC persistence adapter is Apache Derby. Fuse MQ Enterprise also supports most major SQL databases. You can enable other databases by properly configuring the JDBC connection in the broker's configuration file.

You can use the JDBC persistence adapter either with or without journaling. Using the journal provides two main benefits. First, it improves the speed of the message store. Second, it provides support for JMS transactions.

Supported databases

Fuse MQ Enterprise is known to work with the following databases:

  • Apache Derby

  • Axion

  • DB2

  • HSQL

  • Informix

  • MaxDB

  • MySQL

  • Oracle

  • Postgresql

  • SQLServer

  • Sybase

In addition, Fuse MQ Enterprise supports a number of generic JDBC providers.

Specifying the type of JDBC store to use

Fuse MQ Enterprise support two types of JDBC store:

  • A journaled JDBC store:

    The journaled JDBC store is specified using the journalPersistenceAdapterFactory element inside the persistenceFactory element. For more details see Using JDBC with the High Performance Journal.

  • A non-journaled JDBC store:

    The non-journaled store is specified using the jdbcPersistenceAdapter element inside the persistenceAdapter element. For more details see Using JDBC without the Journal.

The journaled JDBC store features better performance than the plain JDBC store.

[Warning]Warning

The journaled JDBC store is incompatible with the JDBC master/slave failover pattern—see Shared JDBC Master/Slave in Fault Tolerant Messaging

Prerequisites

Before you can use one of the JDBC persistence stores, you need to ensure that the following items are installed in the broker's container:

  • The org.apache.servicemix.bundles.commons-dbcp bundle

  • The appropriate JDBC driver for the database used

[Note]Note

Depending on the database used, you may need to wrap the driver in an OSGi bundle by using the wrap: URI prefix when adding it to the container.

Configuring your JDBC driver

Fuse MQ Enterprise autodetects the JDBC driver that is in use at start-up. For the supported databases, the JDBC adapter automatically adjusts the SQL statements and JDBC driver methods to work with the driver. If you want to customize the names of the database tables or work with an unsupported database, you can modify both the SQL statements and the JDBC driver methods. See Customizing the SQL statements used by the adapter for information about modifying the SQL statements. See Using generic JDBC providers for information about changing the JDBC methods.

JDBC configuration for Apache Derby

Fuse MQ Enterprise provides sample configurations of various JDBC databases in InstallDir/conf/activemq-jdbc.xml. Example 6 shows the configuration for using the default JDBC database (Apache Derby).

Example 6. Configuration for the Apache Derby Database

<beans ...>
  <broker xmlns="http://activemq.apache.org/schema/core"
          brokerName="localhost">
    ...
    <persistenceAdapter>
       <jdbcPersistenceAdapter
            dataDirectory="${activemq.base}/data"
            dataSource="#derby-ds"/>
    </persistenceAdapter>
    ...
  </broker>
 
  <!-- Embedded Derby DataSource Sample Setup -->
  <bean id="derby-ds" class="org.apache.derby.jdbc.EmbeddedDataSource">
    <property name="databaseName" value="derbydb"/>
    <property name="createDatabase" value="create"/>
  </bean>

</beans>

JDBC configuration for Oracle

Example 7 shows the configuration for using the Oracle JDBC driver. The persistence adapter configuration refers to the Spring bean element that configures the JDBC driver.

Example 7. Configuration for the Oracle JDBC Driver

<beans ... >
  <broker xmlns="http://activemq.apache.org/schema/core"
          brokerName="localhost">
    ...
    <persistenceAdapter>
       <jdbcPersistenceAdapter
            dataDirectory="${activemq.base}/data"
            dataSource="#oracle-ds"/>
    </persistenceAdapter>
    ...
  </broker>
 
  <!-- Oracle DataSource Sample Setup -->
  <bean id="oracle-ds"
        class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
    <property name="url" value="jdbc:oracle:thin:@localhost:1521:AMQDB"/>
    <property name="username" value="scott"/>
    <property name="password" value="tiger"/>
    <property name="maxActive" value="200"/>
    <property name="poolPreparedStatements" value="true"/>
  </bean>

</beans>

The JDBC drivers are configured using a Spring bean element. The id attribute specifies the name by which you will refer to the driver when configuring the JDBC persistence adapter. The class attribute specifies the class that implements the data source used to interface with the JDBC driver. The destroy-method attribute specifies the name of the method to call when the JDBC driver is shutdown.

In addition to the bean element, the JDBC driver configuration includes a number of property elements. Each property element specifies a property required by the JDBC driver. For information about the configurable properties refer to your JDBC driver's documentation.

Comments powered by Disqus