Flink 实战系列Flink 消费多个 Topic 数据利用侧流输出完成分流功能

Posted JasonLee实时计算

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flink 实战系列Flink 消费多个 Topic 数据利用侧流输出完成分流功能相关的知识,希望对你有一定的参考价值。

Flink 消费多个 Topic 数据利用侧流输出完成分流功能

需求

Flink 程序消费多个 Topic 的数据,需要根据不同的 Topic 走不同的处理逻辑,仔细分析这个需求,实际上可以分为两个小问题:

  1. 如何获取 Kafka 的元数据信息(Topic,时间戳等)
  2. 如何实现分流功能?

实现思路

关于第一个问题,获取 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

以上是关于Flink 实战系列Flink 消费多个 Topic 数据利用侧流输出完成分流功能的主要内容,如果未能解决你的问题,请参考以下文章