flume抽取kafka数据到kafka,数据无法从topicA抽取到topicB

最近做一个项目的时候,发现一个特别诡异的问题,kafka中有topicA,topicB两个主题,然后我通过flume抽取kafka中topicA中的数据,能够成功,flume的conf如下:

复制代码
tier1.sources = source1
tier1.channels = c1
tier1.sinks = k1
tier1.sources.source1.type = org.apache.flume.source.kafka.KafkaSource
tier1.sources.source1.channels = c1
tier1.sources.source1.batchSize = 100
tier1.sources.source1.kafka.bootstrap.servers = bigdata01:9092
tier1.sources.source1.kafka.topics = topicA
tier1.sources.source1.kafka.consumer.group.id = yuekao

tier1.sources.source1.kafka.consumer.auto.offset.reset=earliest

tier1.sources.source1.interceptors = i1
tier1.sources.source1.interceptors.i1.type = com.bigdata.YueKaoInterceptor$BuilderEvent

tier1.channels.c1.type = memory
tier1.channels.c1.capacity = 10000
tier1.channels.c1.transactionCapacity = 1000



tier1.sinks.k1.type = logger
tier1.sinks.k1.channel = c1

然后,接着将结果抽取到topicB中,配置文件如下:

复制代码
tier1.sources = source1
tier1.channels = c1
tier1.sinks = k1
tier1.sources.source1.type = org.apache.flume.source.kafka.KafkaSource
tier1.sources.source1.channels = c1
tier1.sources.source1.batchSize = 100
tier1.sources.source1.kafka.bootstrap.servers = bigdata01:9092
tier1.sources.source1.kafka.topics = topicA
tier1.sources.source1.kafka.consumer.group.id = yuekao3

tier1.sources.source1.kafka.consumer.auto.offset.reset=latest



tier1.channels.c1.type = memory
tier1.channels.c1.capacity = 100000
tier1.channels.c1.transactionCapacity = 10000
tier1.channels.c1.byteCapacityBufferPercentage = 20
tier1.channels.c1.byteCapacity = 800000

tier1.sinks.k1.channel = c1
tier1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
tier1.sinks.k1.kafka.topic = topicB
tier1.sinks.k1.kafka.bootstrap.servers = bigdata01:9092

发现一个问题:

flume将topicA中的数据抽取出来之后,继续发送给topicA,topicA自循环啦,topicB中压根没数据,于是发现官网中有这么一段解释:

也就是说如果想把结果发送topicB, 可以在event的header中添加 topic=topicB,

那就只剩两个办法啦,一个是自定义拦截器,一个是使用静态拦截器,自定义拦截器,步骤长,麻烦,可以使用静态拦截器,于是conf修改如下:

复制代码
tier1.sources = source1
tier1.channels = c1
tier1.sinks = k1
tier1.sources.source1.type = org.apache.flume.source.kafka.KafkaSource
tier1.sources.source1.channels = c1
tier1.sources.source1.batchSize = 100
tier1.sources.source1.kafka.bootstrap.servers = bigdata01:9092
tier1.sources.source1.kafka.topics = topicA
tier1.sources.source1.kafka.consumer.group.id = yuekao3

tier1.sources.source1.kafka.consumer.auto.offset.reset=latest

tier1.sources.source1.interceptors = i1
tier1.sources.source1.interceptors.i1.type = static
tier1.sources.source1.interceptors.i1.key = topic
tier1.sources.source1.interceptors.i1.preserveExisting = false
tier1.sources.source1.interceptors.i1.value = topicB

tier1.channels.c1.type = memory
tier1.channels.c1.capacity = 100000
tier1.channels.c1.transactionCapacity = 10000
tier1.channels.c1.byteCapacityBufferPercentage = 20
tier1.channels.c1.byteCapacity = 800000

tier1.sinks.k1.channel = c1
tier1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
tier1.sinks.k1.kafka.topic = topicB
tier1.sinks.k1.kafka.bootstrap.servers = bigdata01:9092

相当于添加了如下方法:

复制代码
tier1.sources.source1.interceptors = i1
tier1.sources.source1.interceptors.i1.type = static
tier1.sources.source1.interceptors.i1.key = topic
tier1.sources.source1.interceptors.i1.preserveExisting = false
tier1.sources.source1.interceptors.i1.value = topicB

问题解决!!!!

相关推荐
少废话h2 小时前
Flume Kafka源与汇的topic覆盖问题解决
java·linux·kafka·flume
西岭千秋雪_3 小时前
Kafka客户端参数(一)
java·分布式·后端·kafka·linq
paperxie_xiexuo3 小时前
七款 AI PPT 工具新解:智能驱动演示升级,解锁多元创作场景
大数据·人工智能·powerpoint·大学生·ppt
q***76664 小时前
显卡(Graphics Processing Unit,GPU)架构详细解读
大数据·网络·架构
九河云4 小时前
不同级别华为云代理商的增值服务内容与质量差异分析
大数据·服务器·人工智能·科技·华为云
阿里云大数据AI技术4 小时前
【跨国数仓迁移最佳实践 12】阿里云 MaxCompute 实现 BigQuery 10 万条 SQL 智能转写迁移
大数据·sql
Elastic 中国社区官方博客4 小时前
Elasticsearch:Microsoft Azure AI Foundry Agent Service 中用于提供可靠信息和编排的上下文引擎
大数据·人工智能·elasticsearch·microsoft·搜索引擎·全文检索·azure
DolphinScheduler社区5 小时前
结项报告完整版 | 为 Apache DolphinScheduler 添加 gRPC 插件
大数据·开源·apache·海豚调度·大数据工作流调度
Faith_xzc5 小时前
Doris内存问题指南:监控、原理与高频OOM解决方案
大数据·性能优化·doris