config.host=<HOST>
config.port=<PORT>
config.keyspace=<KEY_SPACE>
config.username=<USERNAME>
config.password=<PASSWORD>
Cassandra Studio Configuration - Mule 4
To configure Anypoint Connector for Cassandra (Cassandra Connector) in Anypoint Studio:
-
Add the connector to your project.
-
Configure the connector.
-
Configure an input source for the connector.
Add the Connector to Your Studio Project
Anypoint Studio provides two ways to add the connector to your Studio project: from the Exchange button in the Studio taskbar or from the Mule Palette view.
Add the Connector Using Exchange
-
In Studio, create a Mule project.
-
Click the Exchange icon (X) in the upper-left of the Studio task bar.
-
In Exchange, click Login and supply your Anypoint Platform username and password.
-
In Exchange, search for "cassandra".
-
Select the connector and click Add to project.
-
Follow the prompts to install the connector.
Authentication
If a Cassandra database has authentication enabled, you must provide credentials when accessing it from Cassandra Connector. Cassandra supports basic authentication only. To provide credentials to a Cassandra database, enter the corresponding values in the Cassandra Connector global element.
Create a Cassandra Keyspace using Studio
This example creates a Cassandra keyspace that groups column families, and then creates a Cassandra table.
Create a Keyspace
-
Create a new Mule Project in Anypoint Studio and fill in the Cassandra credentials in:
src/main/resources/mule-app.properties
. -
Drag an HTTP connector onto the canvas and leave the default values for
Host
andPort
, then set the path to:/test/createKeyspace
. -
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 2.0 output application/java --- { "keyspaceName": payload.keyspaceName, "replicationFactor": payload.replicationFactor, "replicationStrategyClass": payload.replicationStrategyClass } as Object { class: "org.mule.modules.cassandradb.api.CreateKeyspaceInput" }
-
Drag a Cassandra component for Create Keyspace onto the canvas.
Field Description Host
Enter a host name, or IP address of a Cassandra node.
Port
Enter a port number. The default port is 9042.
Keyspace
Enter the Cassandra keyspace. A keyspace groups column families.
Username
Enter a Cassandra user name if you enabled PasswordAuthenticator in the Cassandra YAML file. If
AllowAllAuthenticator
is enabled, leave this value blank.Password
Enter the password if you enabled
PasswordAuthenticator
. Otherwise leave this value blank. -
Click the Test Connection option to confirm that Mule can connect with the Cassandra instance. If the connection is successful, click OK to save the configuration. Otherwise, review and correct any invalid parameters and retest.
-
Run the application. In a browser, use the following URL to enter a query parameter for the keyspace name
ks_name
, replication factorrf
, and replication strategy classrs_class
:http://localhost:8081/simple?ks_name=simple_keyspace&rf=3&rs_class=SimpleStrategy
Create a Cassandra Table
-
Create a new Mule Project in Anypoint Studio and fill in the Cassandra credentials in
src/main/resources/mule-app.properties
.config.host=<HOST> config.port=<PORT> config.keyspace=<KEY_SPACE> config.username=<USERNAME> config.password=<PASSWORD>
-
Drag an HTTP connector onto the canvas and leave the default values for
Host
andPort
and set the path to/test/createTable
. -
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 2.0 output application/java --- { "columns": payload.columns, "tableName": payload.tableName, "keyspaceName": payload.keyspaceName } as Object { class : "org.mule.modules.cassandradb.api.CreateTableInput" }
-
Drag a Cassandra component for the Create Table operation onto the canvas.
Field Description Host
Enter a host name, or IP address, of a Cassandra node.
Port
Enter a port number. The default port is
9042
.Keyspace
Enter the Cassandra keyspace. A keyspace groups column families.
Username
Enter a Cassandra user name if you enabled
PasswordAuthenticator
in the Cassandra YAML file. IfAllowAllAuthenticator
is enabled, leave this value blank.Password
Enter the password if you enabled
PasswordAuthenticator
; otherwise, leave this value blank. -
Click Test Connection to confirm that Mule can connect with the Cassandra instance. If the client test is successful, click OK to save the configuration. Otherwise, review and correct any invalid parameters and retest.
-
Run the Mule app. In Postman, select POST. Select Body > Raw, select the JSON (application/json) MIME type, and enter the following table description using uppercase for data types.
{ "tableName": "users", "keyspaceName": "Excelsior", "columns": [ { "name": "id", "type": "INT", "primaryKey": "true" }, { "name": "username", "type": "TEXT", "primaryKey": "true" }, { "name": "name", "type": "TEXT", "primaryKey": "false" }, { "name": "email", "type": "TEXT", "primaryKey": "false" } ] }
-
In Postman, click Send, and look for Status:
200 OK
.