Contact Free trial Login

Cassandra Studio Configuration - Mule 4

To configure Anypoint Connector for Cassandra in Anypoint Studio:

  1. Install the connector.

  2. Configure the connector.

  3. Configure an input source for the connector.

Install the Connector

  1. In Studio, click the Anypoint Exchange icon in the Studio taskbar.

  2. In Exchange, click Login and supply your Anypoint Platform username and password.

  3. Search for the Cassandra connector, click on the connector in Exchange, and click Add to project.

  4. Follow the prompts.

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

  1. 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>
  2. Drag an HTTP connector onto the canvas and leave the default values for Host and Port, then set the path to: /test/createKeyspace.

  3. 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"
    }
  4. 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.

  5. 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.

  6. Run the application. In a browser, use the following URL to enter a 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

Create a Cassandra Table

  1. 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>
  2. Drag an HTTP connector onto the canvas and leave the default values for Host and Port and set the path to /test/createTable.

  3. 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"
    }
  4. 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. If AllowAllAuthenticator is enabled, leave this value blank.

    Password

    Enter the password if you enabled PasswordAuthenticator; otherwise, leave this value blank.

  5. 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.

  6. 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"
        }
      ]
    }
  7. In Postman, click Send, and look for Status: 200 OK.

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.