Versions Compared

Key

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

...

The JDBC message store implementation is a variation of the already existing synapse message store implementation and is designed in a manner similar to the WSO2 ESB JMS message store. The JDBC message store uses a JDBC connector to connect to external relational databases.

When you use a JDBC The advantages of using a JDBC message store instead of any other message store , you can easily benefit from the following advantagesare as follows:

  • Easy to connect – You only need to have a JDBC connector to connect to an external relational database.
  • Supports more operations on data – For example, JDBC message stores support  random message selection and has operations very close to in-memory stores.
  • Quick transactions – JDBC message stores are capable of handling about 2300 transactions per second.
  • Ability to work with a high capacity for a long period of time – Since JDBC Stores use databases as the medium to store data, it can store terabytes of data and is capable of handling data for a longer period of time.

Configuring the JDBC message store

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

Localtabgroup
Localtab
activetrue
titleConnection PoolSyntax 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>

 

 

Parameter Name

Value

Required

store.jdbc.driver

Database driver

the class name of the database driver

YES

store.jdbc.connection.urlDatabase

The database URL

YES

store.jdbc.username

Username for access Database

The user name to access the database

YES

store.jdbc.password

Password for access Database

The password to access the database

NO

store.jdbc.table

Table name of the database. If not specified, assumes table with name "it is assumed that a table named jdbc_message_store" exists.

NO

Localtab
titleExternal DatasourceSyntax 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>

 

 

Parameter Name

Value

Required

store.jdbc.dsName

The name of the

Datasource

datasource to be looked up

YES

store.jdbc.table

Table

The table name of the database. If not specified,

assumes table with name "

it is assumed that a table named jdbc_message_store

"

exists.

NO

 

UI Configuration

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

 

Localtabgroup

The following UI is displayed when you select the Pool option for the Connection Information parameter, indicating that you want the connection to be made via a connection pool.

JDBC_Store_Pool_DS.pngImage Removed

The parameters available to configure the JDBC Message Store are as follows.

 

Name for
Localtab
titleConnection Pool

Parameter Name

Description

Name

Connect 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:

JDBC_Store_Pool_DS.pngImage Added

 

Following are descriptions of the fields that are displayed:

 

Field

Description

Name

The name of the message store

Database Table

Table The name of the database table. If not specified, assumes table with name "the value will be set to jdbc_message_store" exists.

Driver

The class name of the database driver.

Url

The JDBC URL of the database that the data will be written to.

User

The user name used to connect to the database.

Password

The password used to connect to the database.

Switch to this by selecting “Carbon Datasource”

Please refer documentation on Creating Datasource. To appear the datasource in the
Localtab
titleExternal Datasource
Connect 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:

JDBC_Store_External_DS.pngImage 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 Datasource.

JDBC_Store_External_DS.pngImage Removed

 

Parameter Name

datasources, see Configuring a JNDI Datasource 


Following are descriptions of the fields that are displayed:

Field

Description

Name

Name

The name for the message store

Database Table

Table The name of the database table. If not specified, assumes table with name "the value will be set to jdbc_message_store" exists.

Datasource Name

The class name of the datasource.

 

Example


Initially you need to setup a database to suite for this.


DB Scripts to create table :


For MySQL :

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 )
)


 


For H2 :

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 )
)

 

You can create similar SQL script according to your database type.


You need to put the relevant database driver into repository/components/lib folder. This sample is based on a MySQL database name “sampleDB” and table “jdbc_message_store”.

 

Code Block
languagexml
<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>

 

Use axis2 client as follows to send messages to the proxy:


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


Refer documentation on working with axis2-stockquote client.