To Create a Keyspace

This procedure shows how to create a keyspace using SimpleStrategy on a single Cassandra node. To create a keyspace using NetworkTopologyStrategy, see the Cassandra Connector Operators Reference.

  1. Start Cassandra and Anypoint Studio.

  2. Create a new Anypoint Studio project, and in the Package Explorer, open mule-app-properties. Assuming you installed Cassandra locally, add connection properties and values. For example:

  3. Create a flow by dragging an HTTP connector from the Mule palette to the canvas, select the connector, and set the Path in Basic Properties to /simple. In Connector Configuration, click Plus control.

  4. In HTTP Listener Configuration, set the following options:

    • Host =

    • Port = 8081

  5. Drag a Transform Message component from the Mule palette to the right (process) side of the flow, select the component, and set the output payload. For example:

    %dw 1.0
    %output application/java
      keyspaceName: inboundProperties."http.query.params".ks_name,
      replicationFactor: inboundProperties."http.query.params".rf,
      replicationStrategyClass: inboundProperties."http.query.params".rs_class
    } as :object {
      class : "com.mulesoft.mule.cassandradb.metadata.CreateKeyspaceInput"

    DataWeave code in the properties window

  6. Drag a Cassandra connector from the Mule palette to the right of the Transform Message component, and select the connector. In Operation, select Create Keyspace, and click Plus control.

  7. In CassandraDB Username/Password Connection, set the following options to placeholder values, and test the connection:

    • Username: ${username}

    • Password: ${password}

    • Host: ${host}

    • Port: ${port}

  8. Run the app. In a browser, use the following URL to enter query parameter for the keyspace name (ks_name), replication factor (rf), and replication strategy class (rs_class):


  9. On the cqlsh command line, check that the app created the keyspace:

    describe schema

    Cassandra output:

    cassandra@cqlsh> describe schema
    CREATE KEYSPACE simple_keyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3'}  AND durable_writes = true;

In this topic: