在kafka客户端或Spark中,他们可以使用ConsumerRecord获取每个记录的主题名称或主题偏移量。但是如何在flink中做同样的事情?
我的伪代码,如
FlinkKafkaConsumer kafkaConsumer = new FlinkKafkaConsumer<>(topicList, newSchemaUtils.MyDeserializeSchema(), properties);
DataStream<MyKafkaPkg> input = env.addSource(kafkaConsumer);
SingleOutputStreamOperator<MyKafkaPkg> mainDataStream = input
.process(...)
public static class MyDeserializeSchema implements DeserializationSchema<MyKafkaPkg> {
public MyKafkaPkgdeserialize(byte[] message) throws IOException{
MyKafkaPkg event = MyKafkaPkg.parseFrom(message);
return event;
}
public boolean isEndOfStream(MyKafkaPkg nextElement){
return false;
}
public TypeInformation<MyKafkaPkg> getProducedType(){
return TypeInformation.of(MyKafkaPkg.class);
}
}