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 |
|---|---|---|---|---|---|
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 | ||
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 | Required The keyspace (the Cassandra name for a database) that holds the tables of | string | customers | ||
Query | Required The CQL statement to run for each message, such as an INSERT, UPDATE or DELETE. Write | string | INSERT INTO accounts (id, username, city) VALUES (?, ?, ?) | ||
Consistency Level | How many replicas must store a write before it counts as done. Enum values: * ANY * ONE * TWO * THREE * QUORUM * ALL * LOCAL_QUORUM * EACH_QUORUM * LOCAL_ONE | string | ANY | ||
Local Datacenter | The name of the Cassandra datacenter that the nodes in | string | dc-east | ||
Extra Type Codecs | An extra conversion between Cassandra and Java types to turn on, such as 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 | |||
JSON Array Body | If true, the body is read as a JSON array that holds the values of the | boolean | true | ||
Password | The password of the Cassandra user | string | |||
Prepare Statements | Whether | boolean | true | ||
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"]