This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Configuring Hector-based Cassandra

This topic provides instructions on how to configure the WSO2 Message Broker nodes to point to a Hector-based Apache Cassandra ring.

Related links

The following instructions include all steps you must do on the Message Broker side.

  1. Open the <MB_HOME>/repository/conf/datasources/master-datasources.xml file. This is where datasources are configured to point to the databases used by the Message Broker. This file consists of commented out configurations for datasources. The datasource configuration for Apache Cassandra is among these. The changes made to this file must be done in both broker nodes.
  2. Uncomment the datasource configuration for external Hector-based Cassandra.

    Tip: You can alternatively add the following configuration into the file if you are not familiar with commenting out XML configurations.

     The sample configuration for this is as follows.

    <datasource>
        <name>HectorDS</name>
        <description>The datasource used for RSS metadata repository</description>
        <jndiConfig>
            <name>WSO2MBStoreDB</name>
        </jndiConfig>
        <definition type="HECTOR">
            <configuration>
                <hosts>localhost:9160</hosts>
                <username>admin</username>
                <password>admin</password>
                <clusterName>TestCluster</clusterName>
                <maxActive>200</maxActive>
                <enableSecurity>false</enableSecurity>
            </configuration>
        </definition>
    </datasource>

    You must update the URL for your database and enter the username and password for a Cassandra database user with the proper permissions.

  3. Uncomment the following configuration into the master-datasources.xml file under the providers tag. This ensures that Hector is used to read and write to Apache Cassandra.

    <provider>org.wso2.carbon.cassandra.datareader.hector.HectorBasedDataSourceReader</provider>

    About data readers

    When connecting to Apache Cassandra, there are different ways to read and write to databases. The two clients used for this are CQL and Hector. These client options are defined as data readers based on this configuration. This is relevant only if you use Cassandra and is not applicable for other databases. So, to read or write to Cassandra, you can either use Hector or CQL.

  4. Open the <MB_HOME>/repository/conf/broker.xml file. This is the root configuration file of Message Broker. The changes made to this file must be done in all the WSO2 Message Broker nodes.

  5. Uncommenting the following configuration ensures that the messageStore and contextStore are based on Hector.

    <messageStore class="org.wso2.andes.store.cassandra.cql.CQLBasedMessageStoreImpl">
        <property name="dataSource">WSO2MBStoreDB</property>
        <property name="strategyClass">org.apache.cassandra.locator.SimpleStrategy</property>
        <property name="replicationFactor">1</property>
        <property name="readConsistencyLevel">ONE</property>
        <property name="writeConsistencyLevel">ONE</property>
    </messageStore>
    <contextStore class="org.wso2.andes.store.cassandra.cql.CQLBasedAndesContextStoreImpl">
        <property name="dataSource">WSO2MBStoreDB</property>
        <property name="strategyClass">org.apache.cassandra.locator.SimpleStrategy</property>
        <property name="replicationFactor">1</property>
        <property name="readConsistencyLevel">ONE</property>
        <property name="writeConsistencyLevel">ONE</property>
    </contextStore>

    Make note of the following when using the above configuration.

      • The replication placement strategy (algorithm) to be used is defined in the strategyClass.

      • Add the following configuration for the GC grace seconds for Cassandra. This is the time to wait before garbage collecting commences in Cassandra.
        <property name="GCGraceSeconds">864000</property>

      • Specify the replicationFactor, readConsistencyLevel and writeConsistencyLevel. For more details on this, please read the Cassandra documentation on data consistency.