使用postgresql作为flink接收器,连接可以';通过kyro序列化PGT连接?
我编写了一个postgresql接收器:使用postgresql作为flink接收器,连接可以';通过kyro序列化PGT连接?,postgresql,apache-flink,Postgresql,Apache Flink,我编写了一个postgresql接收器: class PGTwoPhaseCommitSinkFunction extends TwoPhaseCommmitSinkFunction[Row,PgConnection,Void](new KryoSerializer[PgConnection](classOf[PgConnection]),new ExecutionConfig), VoidSerialize
class PGTwoPhaseCommitSinkFunction
extends TwoPhaseCommmitSinkFunction[Row,PgConnection,Void](new
KryoSerializer[PgConnection](classOf[PgConnection]),new ExecutionConfig),
VoidSerializer.INSTANCE)
但是,当我使用它时,发现PgConnection无法序列化
例外情况是:
com.esotericsoftware.kryo.KryoException: Error constructing instance of class: sun.nio.cs.UTF_8"
我怎么办?谢谢指定为第二个泛型参数的事务对象首先应该是可序列化的,我认为使用
PgConnection
是不对的。相反,它应该是一些自定义的轻量级事务状态对象,保存像id这样的事务元数据-例如,下面是FlinkKafkaProducer
事务状态的示例:
/**
*处理事务的状态。
*/
@可视性测试
@内部的
静态类KafkaTransactionState{
私人最终过渡FlinkKafkaInternalProducer-producer;
@可空
最终字符串transactionalId;
最终长产物;
最后短时期;
KafkaTransactionState(字符串事务ID,FlinkKafkaInternalProducer){
这是(transactionalId,producer.getProducerId(),producer.getEpoch(),producer);
}
卡夫卡通州(FlinkKafkaInternalProducer){
这个(null,-1,(short)-1,producer);
}
卡夫卡塔ransactionState(
@可为空的字符串transactionalId,
长期生产,
短时期,
Flinkkafkainternal(生产商){
this.transactionalId=transactionalId;
this.producerId=producerId;
this.epoch=epoch;
this.producer=生产者;
}
布尔IsTransaction(){
返回transactionalId!=null;
}
...
但是,正如前面所指出的,编写和维护两阶段提交接收器是一项棘手且非常困难的任务,最好将表API与JDBC connector plus postgres驱动程序一起使用
是将数据写入postgres的管道示例