Apache Flink - 如何使用AWS Kinesis

时间:2017-03-19 10:22:01

标签: pojo apache-flink amazon-kinesis flink-streaming

我想用Flink消费来自Kinesis的POJO 有没有关于如何正确发送和反序列化消息的标准?

由于

1 个答案:

答案 0 :(得分:1)

我解决了它:

DataStream<SamplePojo> kinesis = see.addSource(new FlinkKinesisConsumer<>(
        "my-stream",
        new POJODeserializationSchema(),
        kinesisConsumerConfig));

public class POJODeserializationSchema extends AbstractDeserializationSchema<SamplePojo> {
    private ObjectMapper mapper;

    @Override
    public SamplePojo deserialize(byte[] message) throws IOException {
        if (mapper == null) {
            mapper = new ObjectMapper();
        }

        SamplePojo retVal = mapper.readValue(message, SamplePojo.class);

        return retVal;
    }

    @Override
    public boolean isEndOfStream(SamplePojo nextElement) {
        return false;
    }
}