不能创造Cassandra Pojo Sink

时间:2017-02-01 20:40:29

标签: java cassandra apache-flink cassandra-3.0

我正在使用Flink 1.1.3,Cassandra 3.8,我想为一个简化的工作创建一个CassandraSink,所以我必须使用POJO,这是我得到的:

public class StreamingJob {

    public static void main(String[] args) throws Exception {
        // set up the streaming execution environment
        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();


    Properties properties = new Properties();
    //properties to connect with kafka

    DataStream<String> stream = env.addSource(/*kafka connection*/);

    CassandraSink.addSink(stream)
            .setClusterBuilder(new ClusterBuilder() {
                @Override
                public Cluster buildCluster(Cluster.Builder builder) {
                    return builder.addContactPoint("127.0.0.1").build();
                }
            })
            .build();
    //print messages
    stream.rebalance()
            .flatMap(new DeserializeJson())
            .filter(new EventFilter())
            .<Tuple2<String, String>>project(2, 5)
            .keyBy(0)
            .print();
    // execute program


    env.execute("Streaming Job");
}

表格

@Table(keyspace = "flinktest", name = "eventos")
public class Eventos implements Serializable {
    @Column(name = "ad_id")
    private byte[] adId;
    @Column(name = "event_time")
    private String eventTime;

    public Eventos(byte[] adId, String eventTime){
        this.adId = adId;
        this.eventTime = eventTime;
    }

    public byte[] getAdId() {
        return adId;
    }

    public void setId(byte[] adId) {
        this.adId = adId;
    }

    public String getEventTime() {
        return eventTime;
    }

    public void setEventTime(String eventTime) {
        this.eventTime = eventTime;
    }
}

当我在没有CassandraSink的情况下运行它时,我没有遇到任何问题,而且这项工作通常来自kafka。当我添加接收器时,我收到了这个错误:

java.lang.RuntimeException: Cannot create CassandraPojoSink with input: String
at org.apache.flink.streaming.connectors.cassandra.CassandraPojoSink.open(CassandraPojoSink.java:53)
at org.apache.flink.api.common.functions.util.FunctionUtils.openFunction(FunctionUtils.java:38)
at org.apache.flink.streaming.api.operators.AbstractUdfStreamOperator.open(AbstractUdfStreamOperator.java:91)
at org.apache.flink.streaming.runtime.tasks.StreamTask.openAllOperators(StreamTask.java:376)
at org.apache.flink.streaming.runtime.tasks.StreamTask.invoke(StreamTask.java:256)
at org.apache.flink.runtime.taskmanager.Task.run(Task.java:585)
at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.IllegalArgumentException: @Table annotation was not found on type java.lang.String
at com.datastax.driver.mapping.AnnotationChecks.getTypeAnnotation(AnnotationChecks.java:39)
at com.datastax.driver.mapping.AnnotationParser.parseEntity(AnnotationParser.java:50)
at com.datastax.driver.mapping.MappingManager.getMapper(MappingManager.java:154)
at com.datastax.driver.mapping.MappingManager.mapper(MappingManager.java:110)
at org.apache.flink.streaming.connectors.cassandra.CassandraPojoSink.open(CassandraPojoSink.java:51)

我不知道为什么&#34; @表&#34;导致问题,因为它是从另一个库(datastax)导入的。关于如何解决这个问题的任何线索?它变得很烦人,因为我无法使用cassandra Sink和我发现的examples并没有多大帮助。

0 个答案:

没有答案