Search in sources :

Example 1 with ClusterBuilder

use of org.apache.flink.streaming.connectors.cassandra.ClusterBuilder in project flink by apache.

the class CassandraPojoSinkExample method main.

public static void main(String[] args) throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStreamSource<Message> source = env.fromCollection(messages);
    CassandraSink.addSink(source).setClusterBuilder(new ClusterBuilder() {

        @Override
        protected Cluster buildCluster(Builder builder) {
            return builder.addContactPoint("127.0.0.1").build();
        }
    }).build();
    env.execute("Cassandra Sink example");
}
Also used : Builder(com.datastax.driver.core.Cluster.Builder) ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder) ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)

Example 2 with ClusterBuilder

use of org.apache.flink.streaming.connectors.cassandra.ClusterBuilder in project flink by apache.

the class CassandraTupleSinkExample method main.

public static void main(String[] args) throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStreamSource<Tuple2<String, Integer>> source = env.fromCollection(collection);
    CassandraSink.addSink(source).setQuery(INSERT).setClusterBuilder(new ClusterBuilder() {

        @Override
        protected Cluster buildCluster(Builder builder) {
            return builder.addContactPoint("127.0.0.1").build();
        }
    }).build();
    env.execute("WriteTupleIntoCassandra");
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) Builder(com.datastax.driver.core.Cluster.Builder) ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder) ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)

Example 3 with ClusterBuilder

use of org.apache.flink.streaming.connectors.cassandra.ClusterBuilder in project flink by apache.

the class CassandraTupleWriteAheadSinkExample method main.

public static void main(String[] args) throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(1);
    env.enableCheckpointing(1000);
    env.setRestartStrategy(RestartStrategies.fixedDelayRestart(1, 1000));
    env.setStateBackend(new FsStateBackend("file:///" + System.getProperty("java.io.tmpdir") + "/flink/backend"));
    CassandraSink<Tuple2<String, Integer>> sink = CassandraSink.addSink(env.addSource(new MySource())).setQuery("INSERT INTO example.values (id, counter) values (?, ?);").enableWriteAheadLog().setClusterBuilder(new ClusterBuilder() {

        private static final long serialVersionUID = 2793938419775311824L;

        @Override
        public Cluster buildCluster(Cluster.Builder builder) {
            return builder.addContactPoint("127.0.0.1").build();
        }
    }).build();
    sink.name("Cassandra Sink").disableChaining().setParallelism(1).uid("hello");
    env.execute();
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder) ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) FsStateBackend(org.apache.flink.runtime.state.filesystem.FsStateBackend)

Example 4 with ClusterBuilder

use of org.apache.flink.streaming.connectors.cassandra.ClusterBuilder in project flink by apache.

the class BatchExample method main.

/*
	 *	table script: "CREATE TABLE test.batches (number int, strings text, PRIMARY KEY(number, strings));"
	 */
public static void main(String[] args) throws Exception {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(1);
    ArrayList<Tuple2<Integer, String>> collection = new ArrayList<>(20);
    for (int i = 0; i < 20; i++) {
        collection.add(new Tuple2<>(i, "string " + i));
    }
    DataSet<Tuple2<Integer, String>> dataSet = env.fromCollection(collection);
    dataSet.output(new CassandraOutputFormat<Tuple2<Integer, String>>(INSERT_QUERY, new ClusterBuilder() {

        @Override
        protected Cluster buildCluster(Builder builder) {
            return builder.addContactPoints("127.0.0.1").build();
        }
    }));
    env.execute("Write");
    DataSet<Tuple2<Integer, String>> inputDS = env.createInput(new CassandraInputFormat<Tuple2<Integer, String>>(SELECT_QUERY, new ClusterBuilder() {

        @Override
        protected Cluster buildCluster(Builder builder) {
            return builder.addContactPoints("127.0.0.1").build();
        }
    }), TupleTypeInfo.of(new TypeHint<Tuple2<Integer, String>>() {
    }));
    inputDS.print();
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) TypeHint(org.apache.flink.api.common.typeinfo.TypeHint) Builder(com.datastax.driver.core.Cluster.Builder) ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder) ArrayList(java.util.ArrayList) ClusterBuilder(org.apache.flink.streaming.connectors.cassandra.ClusterBuilder) TypeHint(org.apache.flink.api.common.typeinfo.TypeHint) Tuple2(org.apache.flink.api.java.tuple.Tuple2)

Aggregations

ClusterBuilder (org.apache.flink.streaming.connectors.cassandra.ClusterBuilder)4 Builder (com.datastax.driver.core.Cluster.Builder)3 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)3 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)3 ArrayList (java.util.ArrayList)1 TypeHint (org.apache.flink.api.common.typeinfo.TypeHint)1 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)1 FsStateBackend (org.apache.flink.runtime.state.filesystem.FsStateBackend)1