我正在尝试使用 CassandraPojoSink 类编写Flink的Cassandra SINK连接器。我没有收到任何错误/异常,但没有记录提交到Cassandra表中。
我正在使用以下代码。
========= 接收器连接器代码快照 ==================
DataStream<Event> stream = eventStream.flatMap(new EventTransformation());
try {
stream.addSink(new CassandraPojoSink<>(Event.class, new ClusterBuilder() {
private static final long serialVersionUID = -2485105213096858846L;
@Override
public Cluster buildCluster(Cluster.Builder builder) {
return builder.addContactPoint("localhost").withPort(9042).build();
}
}));
} catch (Exception e) {
e.printStackTrace();
}
====== POJO CLASS ================
@Table(keyspace= "cloud", name = "event")
public class Event implements Serializable {
private static final long serialVersionUID = 3284839826384795926L;
@Column(name = "name")
private String name;
@Column(name = "msg")
private String msg;
public Event(){
}
//......
}
答案 0 :(得分:0)
Flink作业可能无法产生任何输出的原因有很多。一些常见的原因包括:
答案 1 :(得分:0)
在将POJO更改为Tuple时,添加时间戳水印代码工作正常。 我能够看到我的数据被写入Cassandra数据库。
的数据流中与GT; events = event_stream.flatMap(new EventTransformation())。assignTimestampsAndWatermarks( 新的AssignerWithPeriodicWatermarks&gt;(){
private static final long serialVersionUID = 1L;
private final long maxOutOfOrderness = 1_000L; // 1
// second
private long currentMaxTimestamp = 0;
@Override
public long extractTimestamp(Tuple3<String, String, Long> arg0,
long arg1) {
long timestamp = arg0.f3; // get
currentMaxTimestamp = Math.max(timestamp, currentMaxTimestamp);
return timestamp;
}
@Override
public Watermark getCurrentWatermark() {
return new Watermark(currentMaxTimestamp - maxOutOfOrderness);
}
});
event_stream.addSink(new CassandraTupleSink<Tuple3<String, String, Long>("INSERT INTO cloud.condition (name, msg, time) VALUES (?,?,?);", new ClusterBuilder() {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected Cluster buildCluster(Builder builder) {
return builder.addContactPoint("localhost").withPort(9042).build();
}
}));
env.setParallelism(2);
env.execute();