You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

 

Camel Cassandra Component

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 single point of failure and garanty high availability. Like Google's BigTable, Cassandra data is structured using column families which 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's based on Cassandra Java Driver provided by DataStax.

Maven users will need to add the following dependency to their pom.xml for this component:

pom.xml
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-cassandraql</artifactId>
    <version>x.y.z</version>
    <!-- use the same version as your Camel core version -->
</dependency>

URI format

The endpoint can initiate the Cassandra connection or use an existing one.

URIDescription
cql:localhost/keyspaceSingle host, default port, usual for testing
cql:host1,host2/keyspaceMulti host, default port
cql:host1,host2:9042/keyspaceMulti host, custom port
cql:host1,host2Default port and keyspace
cql:bean:sessionRefProvided Session reference
cql:bean:clusterRef/keyspaceProvided 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

OptionDescription

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

resultSetConversionStrategy

How is ResultSet converted transformed into message body ALL, ONE, LIMIT_10, LIMIT_100...

Incoming Message

The Camel Cassandra endpoint expects a bunch of simple objects (Object[] or Collection<Object>) which will be bound to the CQL statement as query parameters.

Headers:

  • CamelCqlQuery (optional, String): CQL query

Outgoing Message

The Camel Cassandra endpoint produces one or many a Cassandra Row objects depending on the resultSetConversionStrategy:

 

  • List<Row> if resultSetConversionStrategy is ALL or LIMIT_10
  • Single Row if resultSetConversionStrategy is ONE
  • Anything else, if resultSetConversionStrategy is a custom implementation of the ResultSetConversionStrategy

Repositories

Cassandra can be used to store messages 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's advised to use LeveledCompaction and a small GC grace setting for these tables to allow tombstoned rows to be removed quickly.

Idempotent repository

The NamedCassandraIdempotentRepository stores messages keys in a Cassandra table like this:

CAMEL_IDEMPOTENT.cql
CREATE TABLE CAMEL_IDEMPOTENT (
  NAME varchar,   -- Repository name
  KEY varchar,    -- Message key
  PRIMARY KEY (NAME, KEY)
);

The CassandraIdempotentRepository can be extended to use a different data model.

Aggregation repository

The name NamedCassandraAggregationRepository stores messages by correlation key in a Cassandra table like this:

CAMEL_AGGREGATION.cql
CREATE TABLE CAMEL_AGGREGATION (
  NAME varchar,        -- Repository name
  KEY varchar,         -- Correlation id
  EXCHANGE_ID varchar, -- Exchange id
  EXCHANGE blob,       -- Serialized exchange
  PRIMARY KEY (NAME, KEY)
);

The CassandraAggregationRepository can be extended to use a different data model.

  • No labels