Kamelet Catalog

cassandra sink Cassandra Sink

Provided by: "Apache Software Foundation"

Support Level for this Kamelet is: "Stable"

Runs a CQL statement, such as an INSERT, in an Apache Cassandra keyspace for each message, with the values of its ? markers taken from the JSON array in the body.

Use it to store events or records as rows of a Cassandra table, for example each reading of a sensor or each order that arrives on a Kafka topic.

Input: the body is a JSON array, as text, with one value for each ? in query, in the same order: for INSERT INTO accounts (id, username, city) VALUES (?, ?, ?) the body [1,"oscerd","Rome"]. With jsonPayload set to false, the body is used as it is, as the one value of a statement with a single ?.

Output: the body afterwards is an empty List for an INSERT, UPDATE or DELETE.

Good to know: with jsonPayload true, the default, a message fails when its body is not a JSON array, such as a JSON object. The values are sent apart from the statement, so the content of a message cannot change it. ANY, the default consistencyLevel, is the weakest level: a write counts as done even before a replica has stored it. When the datacenter of the cluster is not called datacenter1, set datacenter to its name, or the Kamelet fails to start with No node was available to execute the query. The Kamelet connects without TLS, so a cluster that accepts only TLS connections refuses it.

Configuration Options

The following table summarizes the configuration options available for the cassandra-sink Kamelet:

Property Name Description Type Default Example

connectionHost

Hosts

Required The host name or IP address of one or more Cassandra nodes, separated by commas. The other nodes of the cluster are found from them.

string

cassandra1.example.com,cassandra2.example.com

connectionPort

Port

Required The port the Cassandra nodes listen on for CQL clients, the same for all hosts. Cassandra uses 9042 unless it was set up otherwise.

string

9042

keyspace

Keyspace

Required The keyspace (the Cassandra name for a database) that holds the tables of query.

string

customers

query

Query

Required The CQL statement to run for each message, such as an INSERT, UPDATE or DELETE. Write ? for each value that comes from the body.

string

INSERT INTO accounts (id, username, city) VALUES (?, ?, ?)

consistencyLevel

Consistency Level

How many replicas must store a write before it counts as done. ANY is the fastest and the least safe; QUORUM or LOCAL_QUORUM waits for a majority of the replicas.

Enum values:

* ANY * ONE * TWO * THREE * QUORUM * ALL * LOCAL_QUORUM * EACH_QUORUM * LOCAL_ONE

string

ANY

datacenter

Local Datacenter

The name of the Cassandra datacenter that the nodes in connectionHost belong to, as the Datacenter line of nodetool status shows it. The Kamelet runs the statements only on the nodes of this datacenter. When it is not set, datacenter1 is used, the name a Cassandra installed with its default settings uses. A name that does not match makes the Kamelet fail to start with No node was available to execute the query, or each message fail with it when prepareStatements is false.

string

dc-east

extraTypeCodecs

Extra Type Codecs

An extra conversion between Cassandra and Java types to turn on, such as TIMESTAMP_UTC or BLOB_TO_ARRAY. Needed only when a column type does not map to a value of the body by default.

Enum values:

* BLOB_TO_ARRAY * BOOLEAN_LIST_TO_ARRAY * BYTE_LIST_TO_ARRAY * SHORT_LIST_TO_ARRAY * INT_LIST_TO_ARRAY * LONG_LIST_TO_ARRAY * FLOAT_LIST_TO_ARRAY * DOUBLE_LIST_TO_ARRAY * TIMESTAMP_UTC * TIMESTAMP_MILLIS_SYSTEM * TIMESTAMP_MILLIS_UTC * ZONED_TIMESTAMP_SYSTEM * ZONED_TIMESTAMP_UTC * ZONED_TIMESTAMP_PERSISTED * LOCAL_TIMESTAMP_SYSTEM * LOCAL_TIMESTAMP_UTC

string

jsonPayload

JSON Array Body

If true, the body is read as a JSON array that holds the values of the ? markers. If false, the body is passed as it is, as the one value of query.

boolean

true

password

Password

The password of the Cassandra user username.

string

prepareStatements

Prepare Statements

Whether query is prepared once by Cassandra and then run with the values of each message, which is faster. Set it to false to send the statement as a new one each time.

boolean

true

username

Username

The Cassandra user to log in as. Leave it empty for a cluster that does not ask for a login.

string

Dependencies

At runtime, the cassandra-sink Kamelet relies upon the presence of the following dependencies:

  • camel:jackson3

  • camel:kamelet

  • camel:cassandraql

Camel JBang usage

Prerequisites

  • You’ve installed JBang.

  • You have executed the following command:

jbang app install camel@apache/camel

Supposing you have a file named route.yaml with this content:

- route:
    from:
      uri: "kamelet:timer-source"
      parameters:
        period: 10000
        message: 'test'
      steps:
        - to:
            uri: "kamelet:cassandra-sink"

You can now run it directly through the following command

camel run route.yaml

Cassandra Sink Kamelet Description

Authentication methods

The Kamelet supports username/password authentication.

The Kamelet has no TLS option. It connects without TLS, so a cluster that accepts only TLS connections refuses it.

The local datacenter

The Kamelet connects to the nodes in connectionHost as members of one datacenter, the local datacenter, and runs the statements only on the nodes of that datacenter. It is datacenter1 unless datacenter says otherwise, the name a Cassandra installed with its default settings uses. When the datacenter of the cluster has another name, set datacenter to it, or the Kamelet fails to start with No node was available to execute the query (with prepareStatements false, it starts and each message fails with that error instead).

The name of the datacenter is on the Datacenter: line of nodetool status, or in the data_center column of SELECT data_center FROM system.local in cqlsh.

For example, for a cluster whose datacenter is called dc-east:

connectionHost: cassandra1.example.com,cassandra2.example.com
connectionPort: 9042
keyspace: customers
datacenter: dc-east
query: INSERT INTO accounts (id, username, city) VALUES (?, ?, ?)

Payload

With jsonPayload set to true, the default, the body must be a JSON array that holds the values of the ? markers of query, in their order. A JSON object fails. With jsonPayload set to false, the body is passed as it is, as the one value of a statement with a single ?.

For example, with the query INSERT INTO accounts (id, username, city) VALUES (?, ?, ?), the body is:

[1, "oscerd", "Rome"]