Flume中使用KafkaChannel时topic中存在异常奇怪字符

Kafkatopic中每一行前面都会有奇怪的字符,方框或者点或者问号等等,如图:

 ⬜I am row one.
  I am row two.
  I am row three.
 &I am the other row.

解决方案

flume中的配置文件.conf文件中的kafkaChannel的属性parseAsFlumeEvent默认为true,改为false即可。

如下:其中a1agent的名称,c1channel名称

a1.channels.c1.parseAsFlumeEvent = false

 

测试结果如下:^*^ OK啦!

I am row one.
I am row two.
I am row three.
I am the other row.

原因

Flume官网对该属性的解释是:

 

Property Name

Default

Description

parseAsFlumeEvent

true

Expecting Avro datums with FlumeEvent schema in the channel. This should be true if Flume source is writing to the channel and false if other producers are writing into the topic that the channel is using. Flume source messages to Kafka can be parsed outside of Flume by using org.apache.flume.source.avro.AvroFlumeEvent provided by the flume-ng-sdk artifact

 ^0^不翻译了,反正我也看不懂

 

该属性为true时会转成Flume Event,结果时把Flumeheaders中的信息混合着内容一起写入kafka的消息中,无论headers是否为空时都出现了奇怪的特殊字符(已测试)。

 

但是,该属性设置为false时,有些版本可能不起作用,因为这曾是一个BUG,后来修复了但不知是哪个版本之后了(懒得查),目前我用过的1.5.21.7.0都可以。 Flume1.7.0版本改进的列表包括:

[FLUME-2781] - A KafkaChannel defined as parseAsFlumeEvent=false cannot be correctly used by a Flumesource

上面内容的网址连接:https://issues.apache.org/jira/browse/FLUME-2781

 

主要内容:Implemented a tiny change so putting to the channel isconsistent with take, so if parseAsFlumeEvent is false it uses the event bodytext instead of an Avro Flume event object.

放入channel的内容与取时保持一致。theevents are written as text and not as an Avro object.

 

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flume使用Kafka作为Sink的步骤如下: 1. 安装Kafka:首先需要安装Kafka,可以从官网上下载最新版本:https://kafka.apache.org/downloads 2. 配置Kafka:配置Kafka的端口号、主题名称、副本数等参数。在config/server.properties文件进行配置。 3. 在Flume添加Kafka Sink:在Flume配置文件添加一个Kafka Sink,并配置它与Kafka的连接信息和主题等。 4. 启动KafkaFlume:启动KafkaFlume。 以下是一个示例Flume配置文件,使用Kafka作为Sink: ``` # Name the components on this agent agent.sources = source agent.sinks = kafkaSink agent.channels = memoryChannel # Describe/configure the source agent.sources.source.type = netcat agent.sources.source.bind = localhost agent.sources.source.port = 44444 # Describe the sink agent.sinks.kafkaSink.type = org.apache.flume.sink.kafka.KafkaSink agent.sinks.kafkaSink.brokerList = localhost:9092 agent.sinks.kafkaSink.topic = myTopic agent.sinks.kafkaSink.serializer.class = kafka.serializer.StringEncoder # Use a channel which buffers events in memory agent.channels.memoryChannel.type = memory agent.channels.memoryChannel.capacity = 1000 # Bind the source and sink to the channel agent.sources.source.channels = memoryChannel agent.sinks.kafkaSink.channel = memoryChannel ``` 在这个配置使用netcat作为源,监听本地的44444端口。在Kafka Sink,配置连接信息和主题名称等参数。同使用了一个内存间件,用于缓存事件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值