Cassandra connector

Cassandra is a distributed, low-latency NoSQL database. It is a key value-based database. Many high-throughput applications use Cassandra as their primary database. Cassandra works with distributed cluster mode, where there is no master-slave architecture. Reads and writes can be felicitated by any node. For more information about Cassandra, visit http://cassandra.apache.org.

Apache Flink provides a connector that can write data to Cassandra. In many applications, people may want to store streaming data from Flink in Cassandra.

Like other connectors, to get this we need to add it as a Maven dependency:

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-cassandra_2.11</artifactId>
<version>1.1.4</version>
</dependency>

Once the dependency is added, add the Cassandra sink with its configurations, as follows:

In Java:

CassandraSink.addSink(input)
.setQuery("INSERT INTO cep.events (id, message) values (?, ?);")
.setClusterBuilder(new ClusterBuilder() {
@Override
public Cluster buildCluster(Cluster.Builder builder) {
return builder.addContactPoint("127.0.0.1").build();
}
})
.build()

In Scala:

The preceding code writes stream of data into a table called events. The table expects an event ID and a message:

CassandraSink.addSink(input)
.setQuery("INSERT INTO cep.events (id, message) values (?, ?);")
.setClusterBuilder(new ClusterBuilder() {
@Override
public Cluster buildCluster(Cluster.Builder builder) {
return builder.addContactPoint("127.0.0.1").build();
}
)
.build();
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset