In addition to the Carbon database, WSO2 Message Broker (WSO2 MB) requires a separate database for storing data that is specific to WSO2 MB. By default, WSO2 MB is shipped with an embedded H2 database (WSO2MB_DB.ht.db
) for this purpose. These databases are stored in the <MB_HOME>/repository/database
directory.
For instructions on changing the default Carbon database, see Changing the Carbon Database in the WSO2 Product Administration Guide.
Given below are the steps you need to follow in order to change the default WSO2 MB database.
Setting up the database
You can set up one of the following databases for storing WSO2 MB data:
Creating the datasource connection
A datasource is used to establish the connection to a database. By default, the WSO2_MB_STORE_DB
datasource is configured in the master-
datasources.
xml file for the purpose of connecting to the default H2 database that stores MB-specific data.
After setting up the MySQL database to replace the default H2 database, either change the default configurations of the WSO2_MB_STORE_DB
datasource, or configure a new datasource to point it to the new database as explained below.
Follow the steps below.
Open the <
PRODUCT_HOME>/repository/conf/datasources/m
aster-datasources.xml
file and locate the<datasource>
configuration element.You simply have to update the url pointing to your MySQL database, the username and password required to access the database and the MySQL driver details as shown below. Further, be sure to set the
<defaultAutoCommit>
element tofalse
for the MB database. Optionally, you can update the other elements for your database connection.
Optional DB configurations
Element | Description |
---|---|
url | The URL of the database. The default port for MySQL is 3306 |
username and password | The name and password of the database user |
driverClassName | The class name of the database driver |
maxActive | The maximum number of active connections that can be allocated at the same time from this pool. Enter any negative value to denote an unlimited number of active connections. |
maxWait | The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception. You can enter zero or a negative value to wait indefinitely. |
minIdle | The minimum number of active connections that can remain idle in the pool without extra ones being created, or enter zero to create none. |
testOnBorrow | The indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, it will be dropped from the pool, and another attempt will be made to borrow another. |
validationQuery | The SQL query that will be used to validate connections from this pool before returning them to the caller. |
validationInterval | The indication to avoid excess validation, and only run validation at the most, at this frequency (time in milliseconds). If a connection is due for validation but has been validated previously within this interval, it will not be validated again. |
For more information on other parameters that can be defined in the <PRODUCT_HOME>/repository/conf/
datasources/ master-datasources.xml
file, see Tomcat JDBC Connection Pool.
Updating other configuration files
- Open the
<MB_HOME>/repository/conf/broker.xml
file. This is the root configuration file of WSO2 MB. The changes made to this file must be done in all the MB nodes. In the
broker.xml
file we need to use the Oracle message store and Andes context store. To do this, uncomment or add the following configuration.... <messageStore class="org.wso2.andes.store.rdbms.RDBMSMessageStoreImpl"> <property name="dataSource">WSO2MBStoreDB</property> </messageStore> <andescontextStore class="org.wso2.andes.store.rdbms.RDBMSAndesContextStoreImpl"> <property name="dataSource">WSO2MBStoreDB</property> </andescontextStore>
The elements in the above configuration are described below.
The fully qualified name of the respective implementation class should be defined under the class attributes of
messageStore
andandesContextStore
elements. This implementation class will be used by MB to persist relevant information.The
<property>
elements are used to define different properties for each store. The minimal property for starting each store is thedataSource
property. Depending on the implementation, the required properties may differ.
Creating database tables
To create the database tables, connect to the database that you created earlier and run the following scripts: