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.
-
Start Cassandra and Anypoint Studio.
-
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:
username=cassandra password=cassandra host=localhost keyspace=Excelsior port=9042
+ . 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 . . In HTTP Listener Configuration, set the following options:
+ * Host = 0.0.0.0 * Port = 8081
+ . 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" }
+
+ . 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 . . In CassandraDB Username/Password Connection, set the following options to placeholder values, and test the connection:
+ * Username: ${username} * Password: ${password} * Host: ${host} * Port: ${port}
+ . 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):
+
http://localhost:8081/simple?ks_name=simple_keyspace&rf=3&rs_class=SimpleStrategy
+ . 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; ...