Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The syntax of the JDBC message store can be different depending on whether you connect to the database using a connection pool, or using a datasource. Click on the relevant tab to view the syntax based on how you want to connect to the database.

Localtabgroup
Localtab
activetrue
titleSyntax to connect using a connection pool
Code Block
languagexml
<messageStore class="org.apache.synapse.message.store.jdbc.JDBCMessageStore" name="MyStore">
     
<parameter name="store.jdbc.driver"/>
<parameter name="store.jdbc.connection.url"/>
<parameter name="store.jdbc.username"/>
<parameter name="store.jdbc.password"/>
<parameter name="store.jdbc.table"/>
     
</messageStore>

 

Following are the parameters that should be specified and the description for each:

ParameterDescriptionRequired
store.jdbc.driver The class name of the database driver.YES
store.jdbc.connection.url The database URL.YES
store.jdbc.username The user name to access the database.YES
store.jdbc.password The password to access the database.NO
store.jdbc.table Table name of the database. If not specified, it is assumed that a table named jdbc_message_store exists.NOYES
Localtab
titleSyntax to connect using an external datasource
Code Block
languagexml
<messageStore class="org.apache.synapse.message.store.jdbc.JDBCMessageStore" name="MyStore">

<parameter name="store.jdbc.dsName"/>
<parameter name="store.jdbc.table"/>

</messageStore>

 

Following are the parameters that should be specified and the description for each:
ParameterDescriptionRequired
store.jdbc.dsName The name of the datasource to be looked upYES
store.jdbc.table The table name of the database. If not specified, it is assumed that a table named jdbc_message_store exists.NOYES

 

UI Configuration

The UI of the JDBC Message Store that is displayed can vary depending on whether you connect to the database using a connection pool, or using a datasource. Click on the relevant tab to view the UI that is displayed based on how you want to connect to the database.

 

Localtabgroup
Localtab
titleConnect to the database via a connection pool

When adding a JDBC message store, if you select Pool as the Connection Information, the following screen appears:

Image RemovedImage Added

 

Following are descriptions of the fields that are displayed:

FieldDescription
NameThe name of the message store
Database TableThe name of the database table. If not specified, the value will be set to jdbc_message_store.
DriverThe class name of the database driver.
UrlThe JDBC URL of the database that the data will be written to.
UserThe user name used to connect to the database.
PasswordThe password used to connect to the database.

If you need to ensure guaranteed delivery when you store incoming messages to a JDBC message store, and then deliver them to a particular backend, click Show Guaranteed Delivery Parameters and specify values for the following parameters:

  • Enable Producer Guaranteed Delivery (store.producer.guaranteed.delivery.enable) - Whether it is required to enable guaranteed delivery on the producer side. Set this to True if you need to ensure guaranteed delivery.
  • Failover Message Store (store.failover.message.store.name) - The message store to which the store mediator should send messages when the original message store fails.

For instructions on adding a required type of message store via the ESB Management Console, see Adding a Message Store.

 

Localtab
titleConnect to the database via an external datasource

When adding a JDBC message store, if you select Carbon Datasource as the Connection Information, the following screen appears:

Image RemovedImage Added

To make sure that the datasource appears in the Datasource Name list, you need to expose it as a JNDI datasource. For information on configuring a JNDI datasources, see Configuring a JNDI Datasource

Following are descriptions of the fields that are displayed:

FieldDescription
NameThe name for the message store
Database TableThe name of the database table. If not specified, the value will be set to jdbc_message_store
Datasource NameThe class name of the datasource.

If you need to ensure guaranteed delivery when you store incoming messages to a JDBC message store, and then deliver them to a particular backend, click Show Guaranteed Delivery Parameters and specify values for the following parameters:

  • Enable Producer Guaranteed Delivery (store.producer.guaranteed.delivery.enable) - Whether it is required to enable guaranteed delivery on the producer side. Set this to True if you need to ensure guaranteed delivery.
  • Failover Message Store (store.failover.message.store.name) - The message store to which the store mediator should send messages when the original message store fails.

For instructions on adding a required type of message store via the ESB Management Console, see Adding a Message Store.

 

Sample scenario

In this sample:

  • The client sends requests to a proxy service.
  • The proxy service stores the messages in a JDBC message store. 
  • The back-end service is invoked by a message forwarding processor, which picks the messages stored in the JDBC message store. 
Prerequisites:
  1. Setup the database.
    • If you are setting up a MySQL database, the DB script to create the required table is as follows: 

      Code Block
      languagesql
      CREATE TABLE jdbc_message_store(
      indexId BIGINT( 20 ) NOT NULL AUTO_INCREMENT ,
      msg_id VARCHAR( 200 ) NOT NULL ,
      message BLOB NOT NULL ,
      PRIMARY KEY ( indexId )
      )
    • If you are setting up a H2 database, the DB the DB script to create the required table is as follows: 

      Code Block
      languagesql
      CREATE TABLE jdbc_message_store(
      indexId BIGINT( 20 ) NOT NULL AUTO_INCREMENT ,
      msg_id VARCHAR( 200 ) NOT NULL ,
      message BLOB NOT NULL ,
      PRIMARY KEY ( indexId )
      )
      Info
      titleNote

      You can create a similar script based on the database you want to set up.

  2. Add the relevant database driver into the repository/components/lib folder. 
Configure the sample
  1. Create a proxy service that stores messages to the JDBC message store.
  2. Create a JDBC message store.
  3. Create a message forwarding processor to consumes the messages stored in the message store.

    Code Block
    languagexml
    titleSample configuration that uses a MySQL database named sampleDB and the database table jdbc_message_store
    <proxy xmlns="http://ws.apache.org/ns/synapse"
          name="MessageStoreProxy"
          transports="https http"
          startOnLoad="true"
          trace="disable">
      <description/>
      <target>
         <inSequence>
            <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
            <property name="OUT_ONLY" value="true"/>
            <property name="target.endpoint" value="StockQuoteServiceEp"/>
            <store messageStore="SampleStore"/>
         </inSequence>
      </target>
      <publishWSDL uri="http://localhost:9000/services/SimpleStockQuoteService?wsdl"/>
    </proxy>
     
    <messageStore xmlns="http://ws.apache.org/ns/synapse"
                 class="org.apache.synapse.message.store.impl.jdbc.JDBCMessageStore"
                 name="SampleStore">
      <parameter name="store.jdbc.password"/>
      <parameter name="store.jdbc.username">root</parameter>
      <parameter name="store.jdbc.driver">com.mysql.jdbc.Driver</parameter>
      <parameter name="store.jdbc.table">jdbc_message_store</parameter>
      <parameter name="store.jdbc.connection.url">jdbc:mysql://localhost:3306/sampleDB</parameter>
    </messageStore>
     
    <messageProcessor xmlns="http://ws.apache.org/ns/synapse"
                     class="org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor"
                     name="ScheduledProcessor"
                     messageStore="SampleStore">
      <parameter name="max.delivery.attempts">5</parameter>
      <parameter name="interval">10</parameter>
      <parameter name="is.active">true</parameter>
    </messageProcessor>
Configure the back-end service
  1. Deploy the SimpleStockQuoteService client by navigating to <ESB_HOME>/samples/axis2Server/src/SimpleStockQuoteService, and running the ant command in the command prompt or shell script. This will build the sample and deploy the service for you. For more information on sample back-end services, see Deploying sample back-end services.
  2. WSO2 ESB comes with a default Axis2 server, which you can use as the back-end service for this sample. To start the Axis2 server, navigate to<ESBto <ESB_HOME>/samples/axis2server, and run axis2Server.sh (on Linux) or axis2Server.bat (on Windows).Point your browser to run axis2Server.sh on Linux or axis2Server.bat on Windows.
  3. Go to http://localhost:9000/services/SimpleStockQuoteService?wsdl and verify that the service is running.
Execute the sample

To invoke the proxy service, navigate to <ESB_HOME>/repository/samples/axis2client

/ directory

, and execute the following command:

 

 

Code Block
ant stockquote -Daddurl=http://localhost:8280/services/MessageStoreProxy