Skip to main content

Configure WSO2 DSS with Cassandra

Here are the steps to setup DSS and Cassandra integration

Setup 1: download and install Cassandra
WSO2 DSS 3.5.0 is based on WSO2 Carbon 4.4.2 and Cassandra version 2.0 is recommended
WSO2 DSS 3.2.2 is based on WSO2 Carbon 4.2.0 and Cassandra version 2.0 is recommended

Step 2: download and install WSO2DSS
http://wso2.com/products/data-services-server/
https://docs.wso2.com/display/DSS322/WSO2+Data+Services+Server+Documentation

Step 3: configure following operations in DSS
Create Key space - UserKS
CREATE KEYSPACE UserKS WITH replication = {'class':'SimpleStrategy', 'replication_factor': 1}
Create column family - User (id, name, country)
CREATE TABLE UserKS.User (id text, name text, country text, PRIMARY KEY (id))
addUser
INSERT INTO UserKS.User (id, name, country) values (?,?,?)
getUsers
SELECT * FROM UserKS.User
updateUser
UPDATE UserKS.User SET country = ? WHERE id =?
deleteUser
DELETE FROM UserKS.User WHERE id = ?

You can try the above command using cqlsh tool resides in cassandra/bin

Option1: Going through the WSO2DSS Management Console Wizard and configure
Option2: Use Developer Studio, create a CAR file and deploy it on WSO2DSS.

https://docs.wso2.com/display/DVS371/Creating+Data+Services+Server+Artifacts

Note: DSS generates a .dbs file which contains all the configurations, which you can find out in wso2dss-3.2.2\repository\deployment\server\dataservices location

Step 4: execute Cassandra queries from Soap UI
Get the WSDL from the WSO2DSS Management console, add it to the Soap UI and invoke

Contents of .dbs file
<data name="UserDS" transports="http https local">
    <config id="UserDataSource">
        <property name="cassandraServers">localhost</property>
    </config>
    <query id="createKeySpace" useConfig="UserDataSource">
        <expression>CREATE KEYSPACE UserKS WITH replication = {'class':'SimpleStrategy', 'replication_factor': 1}</expression>
    </query>
    <query id="dropKeySpace" useConfig="UserDataSource">
        <expression>DROP KEYSPACE UserKS</expression>
    </query>
    <query id="createUserTable" useConfig="UserDataSource">
        <expression>CREATE TABLE UserKS.User (id text, name text, country text, PRIMARY KEY (id))</expression>
    </query>
    <query id="addUser" useConfig="UserDataSource">
        <expression>INSERT INTO UserKS.User (id, name, country) values (?,?,?)</expression>
        <param name="id" ordinal="1" sqlType="STRING"/>
        <param name="name" ordinal="2" sqlType="STRING"/>
        <param name="country" ordinal="3" sqlType="STRING"/>
    </query>
    <query id="getUsers" useConfig="UserDataSource">
        <expression>SELECT * FROM UserKS.User</expression>
        <result element="Users" rowName="User">
            <element column="id" name="id" xsdType="string"/>
            <element column="name" name="name" xsdType="string"/>
            <element column="country" name="country" xsdType="string"/>
        </result>
    </query>
    <query id="updateUser" useConfig="UserDataSource">
        <expression>UPDATE UserKS.User SET country = ? WHERE id =?</expression>
        <param name="country" sqlType="STRING"/>
        <param name="id" sqlType="STRING"/>
    </query>
    <query id="deleteUser" useConfig="UserDataSource">
        <expression>DELETE FROM UserKS.User WHERE id = ?</expression>
        <param name="id" sqlType="STRING"/>
    </query>
    <query id="getUserById" useConfig="UserDataSource">
        <expression>SELECT * FROM UserKS.User where id = ?</expression>
        <result element="Users" rowName="User">
            <element column="id" name="id" xsdType="string"/>
            <element column="name" name="name" xsdType="string"/>
            <element column="country" name="country" xsdType="string"/>
        </result>
        <param name="id" sqlType="STRING"/>
    </query>
    <operation name="createKeySpace">
        <call-query href="createKeySpace"/>
    </operation>
    <operation name="dropKeySpace">
        <call-query href="dropKeySpace"/>
    </operation>
    <operation name="createUserTable">
        <call-query href="createUserTable"/>
    </operation>
    <operation name="addUser">
        <call-query href="addUser">
            <with-param name="id" query-param="id"/>
            <with-param name="name" query-param="name"/>
            <with-param name="country" query-param="country"/>
        </call-query>
    </operation>
    <operation name="getUsers">
        <call-query href="getUsers"/>
    </operation>
    <operation name="updateUser">
        <call-query href="updateUser">
            <with-param name="country" query-param="country"/>
            <with-param name="id" query-param="id"/>
        </call-query>
    </operation>
    <operation name="deleteUser">
        <call-query href="deleteUser">
            <with-param name="id" query-param="id"/>
        </call-query>
    </operation>
    <operation name="getUserById">
        <call-query href="getUserById">
            <with-param name="id" query-param="id"/>
        </call-query>
    </operation>
    <resource method="GET" path="user/get">
        <call-query href="getUsers"/>
    </resource>
    <resource method="GET" path="user/get/{id}">
        <call-query href="getUserById">
            <with-param name="id" query-param="id"/>
        </call-query>
    </resource>
    <resource method="PUT" path="user/add/{id}/{name}/{country}">
        <call-query href="addUser">
            <with-param name="id" query-param="id"/>
            <with-param name="name" query-param="name"/>
            <with-param name="country" query-param="country"/>
        </call-query>
    </resource>
    <resource method="POST" path="user/update/{country}/{id}">
        <call-query href="updateUser">
            <with-param name="country" query-param="country"/>
            <with-param name="id" query-param="id"/>
        </call-query>
    </resource>
    <resource method="DELETE" path="user/delete/{id}">
        <call-query href="deleteUser">
            <with-param name="id" query-param="id"/>
        </call-query>
    </resource>
</data>

Comments

Popular posts from this blog

Create Application in WSO2 App Cloud via REST API

This blog post gives you some examples on how to use createApplication REST API correctly in WSO2 App Cloud  https://docs.wso2.com/display/AppCloud/Published+APIs Before invoke createApplication API, you need to login to the WSO2 App Cloud and get the session cookie. curl -c cookies -v -k -X POST -k https://apps.cloud.wso2.com/appmgt/site/blocks/user/login/ajax/login.jag -d 'action=login&userName=amalka.wso2.com@<tenant>&password=<password>’ This are some basic example to create applications in WSO2 App Cloud. Create application via upload from file system curl -v -k -b cookies -X POST https://apps.cloud.wso2.com/appmgt/site/blocks/application/application.jag -F action=createApplication -F applicationName=SampleFile -F applicationDescription=desc -F runtime=1 -F appTypeName=war -F applicationRevision=1.0.0 -F uploadedFileName=sample.war -F runtimeProperties=[] -F tags=[]  -F fileupload=@/home/amalka/Downloads/sample.war -F isFileAttached=t...

How to generate random unique number in SOAP UI request

eg 1: ${=System.currentTimeMillis() + ((int)(Math.random()*10000))} eg 2: ${=java.util.UUID.randomUUID()} ${=java.util.UUID.randomUUID()} ${=System.currentTimeMillis() + ((int)(Math.random()*10000))} - See more at: http://tryitnw.blogspot.com/2014/03/generating-random-unique-number-in-soap.html#sthash.m2S4tUFu.dpuf ${=System.currentTimeMillis() + ((int)(Math.random()*10000))} - See more at: http://tryitnw.blogspot.com/2014/03/generating-random-unique-number-in-soap.html#sthash.m2S4tUFu.dpuf ${=System.currentTimeMillis() + ((int)(Math.random()*10000))} - See more at: http://tryitnw.blogspot.com/2014/03/generating-random-unique-number-in-soap.html#sthash.m2S4tUFu.dpuf

Send email via WSO2 ESB with several attachments

WSO2 ESB Mail transport allows you to send a email only with 1 attachment. If you want to send number of attachments here's the solution. Scenario: Here I want to extract some content from the input message and attach to the email as two different attachment. Solution:  You can achieve this requirement using Gmail connector. Steps:  Add the Gmail connector to the ESB and enable it. You can download the esb connector here https://storepreview.wso2.com/store/assets/esbconnector/a1fba975-89fb-4bb0-a1b9-9f9d061fb31c Add it to the ESB and enable it https://docs.wso2.com/display/ESB481/Managing+Connectors+in+Your+ESB+Instance Gmail connector documentation https://docs.wso2.com/display/ESBCONNECTORS/Gmail+Connector Setup the scenario: split the input message and send it with an email using two different attachments. Input message I used <email>         <username>sender@gmail.com<...