【Flink 实战系列】Flink 消费多个 Topic 数据利用侧流输出完成分流功能
Flink 消费多个 Topic 数据利用侧流输出完成分流功能
需求
Flink 程序消费多个 Topic 的数据,需要根据不同的 Topic 走不同的处理逻辑,仔细分析这个需求,实际上可以分为两个小问题:
- 如何获取 Kafka 的元数据信息(Topic,时间戳等)
- 如何实现分流功能?
实现思路
关于第一个问题,获取 Kafka 的 Topic 信息,我们可以直接使用 Flink 内置的反序列类 JSONKeyValueDeserializationSchema 来获取,但是我们通常不会选择使用它,为什么呢?我们先来看下它的源码就明白了。
JSONKeyValueDeserializationSchema
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file