Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Chapter 20. Cassandra
Camel Cassandra Component Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Available as of Camel 2.15
Apache Cassandra is an open source NoSQL database designed to handle large amounts on commodity hardware. Like Amazon's DynamoDB, Cassandra has a peer-to-peer and master-less architecture to avoid a single point of failure and guarantee high availability. Like Google's BigTable, Cassandra data is structured using column families that can be accessed through the Thrift RPC API or a SQL-like API called CQL.
This component aims at integrating Cassandra 2.0+ using the CQL3 API (not the Thrift API). It is based on Cassandra Java Driver provided by DataStax.
Maven users must add the following dependency to their
pom.xml
:
URI format Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The endpoint can initiate the Cassandra connection or use an existing one.
URI | Description |
---|---|
cql:localhost/keyspace
|
Single host, default port, usual for testing |
cql:host1,host2/keyspace
|
Multi host, default port |
cql:host1,host2:9042/keyspace
|
Multi host, custom port |
cql:host1,host2
|
Default port and keyspace |
cql:bean:sessionRef
|
Provided Session reference |
cql:bean:clusterRef/keyspace
|
Provided Cluster reference |
To fine tune the Cassandra connection (SSL options, pooling options, load balancing policy, retry policy, reconnection policy), create your own cluster instance and give it to the Camel endpoint.
Endpoint Options Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Option | Default | Description |
---|---|---|
clusterName
|
Cluster name
|
|
username and password
|
Session authentication
|
|
cql
|
CQL query. Can be overriden with a message header.
|
|
consistencyLevel
|
ANY , ONE , TWO , QUORUM , LOCAL_QUORUM ...
|
|
prepareStatements
|
true
|
Use prepared statement (default) or not |
resultSetConversionStrategy
|
ALL
|
How is ResultSet converted and transformed into message body
ALL , ONE , LIMIT_10 , LIMIT_100 ...
|
Messages Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Incoming Message Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The Camel Cassandra endpoint expects a bunch of simple objects (
Object
or Object[]
or Collection<Object>
) that will be bound to the CQL statement as query parameters. If the message body is null or empty, then the CQL query is executed without binding parameters.
Headers:
CamelCqlQuery
(optional,String
orRegularStatement
): CQL query either as a plain String or built using theQueryBuilder
.
Outgoing Message Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The Camel Cassandra endpoint produces one or many Cassandra Row objects depending on the
resultSetConversionStrategy
:
List<Row>
ifresultSetConversionStrategy
isALL
orLIMIT_[0-9]+
- Single
Row
ifresultSetConversionStrategy
isONE
- Anything else, if
resultSetConversionStrategy
is a custom implementation of theResultSetConversionStrategy
Repositories Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Cassandra can be used to store message keys or messages for the idempotent and aggregation EIP.
Cassandra might not be the best tool for queuing use cases yet, read Cassandra anti-patterns queues and queue like datasets. It is advised to use LeveledCompaction and a small GC grace setting for these tables to allow tombstoned rows to be removed quickly.
Idempotent repository Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The
NamedCassandraIdempotentRepository
stores message keys in a Cassandra table like this:
This repository implementation uses lightweight transactions (also known as Compare and Set) and requires Cassandra 2.0.7+.
Alternatively, the
CassandraIdempotentRepository
does not have a NAME
column and can be extended to use a different data model.
Option | Default | Description |
---|---|---|
table
|
CAMEL_IDEMPOTENT
|
Table name |
pkColumns
|
NAME , KEY
|
Primary key columns |
name
|
Repository name, value used for NAME column
|
|
ttl
|
Key time to live | |
writeConsistencyLevel
|
Consistency level used to insert/delete key: ANY , ONE , TWO , QUORUM , LOCAL_QUORUM …
|
|
readConsistencyLevel
|
Consistency level used to read/check key: ONE , TWO , QUORUM , LOCAL_QUORUM …
|
Aggregation repository Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The
NamedCassandraAggregationRepository
stores exchanges by correlation key in a Cassandra table like this:
Alternatively, the
CassandraAggregationRepository
does not have a NAME
column and can be extended to use a different data model.
Option | Default | Description |
---|---|---|
table
|
CAMEL_AGGREGATION
|
Table name |
pkColumns
|
NAME ,KEY
|
Primary key columns |
exchangeIdColumn
|
EXCHANGE_ID
|
Exchange Id column |
exchangeColumn
|
EXCHANGE
|
Exchange content column |
name
|
Repository name, value used for NAME column
|
|
ttl
|
Exchange time to live | |
writeConsistencyLevel
|
Consistency level used to insert/delete exchange: ANY , ONE , TWO , QUORUM , LOCAL_QUORUM …
|
|
readConsistencyLevel
|
Consistency level used to read/check exchange: ONE , TWO , QUORUM , LOCAL_QUORUM …
|