LibraryLink ToToggle FramesPrintFeedback

Chapter 5. Making Endpoints Stateful

FUSE ESB JMS endpoints typically do not store any state information. You can, however, configure them to store a copy of the current JMS message being sent. The message can be stored either in memory or in a JDBC configured database.

Having the endpoint store a copy of the current JMS message can aid in recovery from failures. For example, if your application is deployed in a cluster of FUSE ESB containers you can configure your endpoints to fail over in the event of a failure. If your endpoints are configured to store state in a JDBC database, they can then resend any request that was in process.

You configure an endpoint to save a copy of the current message by setting its stateless attribute to false.

By default, JMS endpoints uses a memory based message store. The memory based message store is a simple hash map that is stored in active memory. It cannot persist in the event of a failure. It also does not support transactions or access by multiple members of a cluster.

If you need to use a more robust message store, you can configure a provider endpoint to use a JDBC accessible database as a message store. A JDBC message store can be shared among a cluster of endpoints, can be persisted in the event of a failure, and, depending on the database, be enlisted in transactions.

To configure an endpoint to use a JDBC accessible datastore you configure its storeFactory attribute to reference a bean configuring an instance of the org.apache.servicemix.store.jdbc.JdbcStoreFactory class. Table 5.1 list the properties you can set for the JDBC store factory.


[Note]Note

The values for dataSource and adapter will depend on the database you are using and the JDBC adapter you are using.

The fragment in Example 5.1 shows the configuration needed for a statefull JMS provider endpoint using MySQL as a JDBC accessible datastore.

Example 5.1. Configuring a Statefull JMS Provider Endpoint

<jms:provider service="tns:widgetServer"
              endpoint="widgetPort"
              storeFactory="#storeFactory"> 1
              stateless="false" /> 2

<bean id="storeFactory" 3
      class="org.apache.servicemix.store.jdbc.JdbcStoreFactory">
  <property name="clustered" value="true"/>
  <property name="dataSource">
    <ref local="mysql-ds"/>
  </property>
</bean>

<bean id="mysql-ds" 4
      class="com.mchange.v2.c3p0.ComboPooledDataSource"
      destroy-method="close">
  <property name="driverClass" value="com.mysql.jdbc.Driver"/>
  <property name="jdbcUrl"
            value="jdbc:mysql://localhost:3306/activemq?relaxAutoCommit=true"/>
  <property name="user" value="activemq"/>
  <property name="password" value="activemq"/>
  <property name="minPoolSize" value="5"/>
  <property name="maxPoolSize" value="10"/>
  <property name="acquireIncrement" value="3"/>
  <property name="autoCommitOnClose" value="false"/>
</bean>

The fragment in Example 5.1 does the following:

1

Configures the endpoint's store factory by providing a reference to the bean configuring the factory.

2

Configures the endpoint to store a copy of the current message in the datastore.

3

Configures the JDBC factory store to create a datastore that can be accessed by a cluster of endpoints.

4

Configures the MySQL JDBC driver.