内容
1.目的
Event Serializer用于将Flume事件转换为另一种输出格式。 在本文中,将介绍Flume Event Serializer的概念。 另外,将了解几种类型的Flume Event Serializer来很好地理解这个概念。
——add picture here —–
Apache Flume Event Serializers – Introduction
2. Types of Flume Event Serializers
Body Text Serializer
别名:text
不做任何转换或修改, Body Text Serializer interceptor直接将事件的Boday(主体)写入输出流。 所有的event header都被忽略。
见下表Body Text Flume Event Serializers,配置选项:
示例如下:
a1.sinks = k1 a1.sinks.k1.type = file_roll a1.sinks.k1.channel = c1 a1.sinks.k1.sink.directory = /var/log/flume a1.sinks.k1.sink.serializer = text a1.sinks.k1.sink.serializer.appendNewline = false
Flume Event Avro Event Serializer
别名:avro_event
Avro Event Serializer interceptor会将Flume事件序列化为Avro Container文件。 该模式与在Avro RPC机制中用于Flume Event的模式相同。此序列化类继承AbstractAvroEventSerializer类。
请参阅下面的Flume Event Avro Event Serializer,配置选项:
示例如下:
a1.sinks.k1.type = hdfs a1.sinks.k1.channel = c1 a1.sinks.k1.hdfs.path = /flume/events/%y-%m-%d/%H%M/%S a1.sinks.k1.serializer = avro_event a1.sinks.k1.serializer.compressionCodec = snappy
Avro Event Serializer
Avro Event Serializer没有别名。必须使用类名称类名来指定。
Avro Event Serializer将Flume事件序列化为Avro Container文件,如“Flume Event”Avro Event Serializer,但记录模式是可配置的。 记录模式可以指定为Flume配置属性,也可以在事件头 (Event Header)中进行传递。
如果要将记录模式作为Flume配置的一部分进行传递,使用下面列出的属性schemaURL。
如要在事件头(Event Header)中传递记录模式,指定包含模式的JSON格式表示的事件flume.avro.schema.literal或使用模式URL(hdfs)指定的flume.avro.schema.url 。
该序列化类继承自AbstractAvroEventSerializer类。
请参阅下面的Avro Flume Event Serializer,配置选项:
示例如下:
a1.sinks.k1.type = hdfs a1.sinks.k1.channel = c1 a1.sinks.k1.hdfs.path = / flume / events /%y-%m-%d /%H%M /%S a1.sinks.k1.serializer = org.apache.flume.sink.hdfs.AvroEventSerializer $ Builder a1.sinks.k1.serializer.compressionCodec = snappy a1.sinks.k1.serializer.schemaURL = hdfs://namenode/path/to/schema.avsc
xxxxx