||
Skip to end of metadata
Go to start of metadata

You can access Cassandra to display data using a Jaggery function. Within that function you can query the database and retrieve the required data The steps below demonstrates an example on accessing Cassandra using Jaggery.

  1. Download cassandra-jdbc-1.1.1.wso2v1.jar file and place it in <BAM_HOME>/repository/components/lib/ directory.
  2. Add below datasource to <BAM_HOME>/repository/conf/datasources/master-datasources.xml file ad edit the configurations as required.  

    <datasource>
    <name>Cassandra_Query</name>
    <description>The datasource used for connect to cassandra db</description>
    <definition type="RDBMS">
    <configuration>
    <url>jdbc:cassandra://localhost:9160/EVENT_KS</url>
    <username>admin</username>
    <password>admin</password>
    <driverClassName>org.apache.cassandra.cql.jdbc.CassandraDriver</driverClassName>
    <maxActive>50</maxActive>
    <maxWait>60000</maxWait>
    <testOnBorrow>true</testOnBorrow>
    <validationQuery>SELECT COUNT(*) from system.local</validationQuery>
    <validationInterval>30000</validationInterval>
    </configuration>
    </definition>
    </datasource>

    The JDBC Cassandra driver used in the above configuration allows you to connect to one Cassandra node. Thereby, it does not support configuring multiple connections to several nodes in a Cassandra cluster.

  3. Add the below code snippet as a Jaggery file in <BAM_HOME>/repository/deployment/server/jaggeryapps/ directory, to access and query the Cassandra datasource. 

    var db = new Database("Cassandra_Query");
    var result;
    
    try{
    result = db.query("SELECT * FROM org_wso2_ticket_service");
            print(result);
        }
        catch(e){
        }
        finally{
            db.close();
        } 

    In the above code snippet, Cassandra_Query is the name of the datasource, which you created above, and org_wso2_ticket_service is the name of the column family.

  • No labels