Contact Free trial Login

Cassandra - Examples - Mule 4

Use this example to create a Cassandra database table.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:cassandra-db="http://www.mulesoft.org/schema/mule/cassandra-db"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core
http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/cassandra-db
http://www.mulesoft.org/schema/mule/cassandra-db/current/mule-cassandra-db.xsd">

  <configuration-properties file="mule-app.properties" />
  <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config">
    <http:listener-connection host="0.0.0.0" port="8081" />
    </http:listener-config>
  <cassandra-db:config name="CassandraDB_Config" doc:name="CassandraDB Config">
    <cassandra-db:connection host="${config.host}" port="${config.port}" keyspace="${config.keyspace}" username="${config.username}" password="${config.password}"/>
	</cassandra-db:config>
  <flow name="HTMLForm">
    <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/"/>
    <parse-template doc:name="Parse Template" location="form.html"/>
  </flow>
  <flow name="CreateKeyspace">
    <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/createKeyspace"/>
    <ee:transform doc:name="Transform Message">
      <ee:message >
        <ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
{
  "keyspaceName": payload.keyspaceName,
  "replicationFactor": payload.replicationFactor,
  "replicationStrategyClass": payload.replicationStrategyClass
} as Object {
  class : "org.mule.modules.cassandradb.api.CreateKeyspaceInput"
}]]></ee:set-payload>
      </ee:message>
    </ee:transform>
    <cassandra-db:create-keyspace doc:name="Create keyspace" config-ref="CassandraDB_Config"/>
    <ee:transform doc:name="Transform Message">
      <ee:message >
        <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
      </ee:message>
    </ee:transform>
  </flow>
  <flow name="CreateTable">
    <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/createTable"/>
    <ee:transform doc:name="Transform Message">
      <ee:message>
        <ee:set-payload><![CDATA[%dw 2.0
output application/java
---
{
  "columns": payload.columns,
  "tableName": payload.tableName,
  "keyspaceName": payload.keyspaceName
} as Object {
  class : "org.mule.modules.cassandradb.api.CreateTableInput"
}]]></ee:set-payload>
      </ee:message>
    </ee:transform>
    <cassandra-db:create-table doc:name="Create table" config-ref="CassandraDB_Config"/>
    <ee:transform doc:name="Transform Message">
      <ee:message>
        <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
      </ee:message>
    </ee:transform>
  </flow>
</mule>

See Also

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.