[Flume传数据案例]: Kafka Source接收Avro Sink发送, Avro Source接收 FileRoll Sink记录下来

Apache Flume

flume官方用户指南网址

Kafka Source -->Avro Sink–>Avro Source -->FileRoll Sink

案例原理图:
在这里插入图片描述

启动flume

[root@Centos ~]#  cd /usr/apache-flume-1.9.0-bin/
[root@Centos apache-flume-1.9.0-bin]#  ./bin/flume-ng version
Flume 1.9.0
Source code repository: https://git-wip-us.apache.org/repos/asf/flume.git
Revision: d4fcab4f501d41597bc616921329a4339f73585e
Compiled by fszabo on Mon Dec 17 20:45:25 CET 2018
From source with checksum 35db629a3bda49d23e9b3690c80737f9

写好配置文件example10.properties

[root@Centos conf]# vim example10.properties
# 声明基本组件 Source Channel Sink example10.properties
a1.sources = s1
a1.sinks = sk1
a1.channels = c1
# 配置Source组件,从Socket中接收⽂本数据
a1.sources.s1.type = org.apache.flume.source.kafka.KafkaSource
a1.sources.s1.batchSize = 100
a1.sources.s1.batchDurationMillis = 2000
a1.sources.s1.kafka.bootstrap.servers = Centos:9092
a1.sources.s1.kafka.topics = topic01
a1.sources.s1.kafka.consumer.group.id = g1
# 配置Sink组件,将接收数据打印在⽇志控制台
a1.sinks.sk1.type = avro
a1.sinks.sk1.hostname = Centos
a1.sinks.sk1.port = 44444
# 配置Channel通道,主要负责数据缓冲
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# 进⾏组件间的绑定
a1.sources.s1.channels = c1
a1.sinks.sk1.channel = c1
# 声明基本组件 Source Channel Sink example10.properties
a2.sources = s1
a2.sinks = sk1
a2.channels = c1
# 配置Source组件,从Socket中接收⽂本数据
a2.sources.s1.type = avro
a2.sources.s1.bind = Centos
a2.sources.s1.port = 44444
# 配置Sink组件,将接收数据打印在⽇志控制台
a2.sinks.sk1.type = file_roll
a2.sinks.sk1.sink.directory = /root/baizhi/file_roll
a2.sinks.sk1.sink.rollInterval = 0
# 配置Channel通道,主要负责数据缓冲
a2.channels.c1.type = memory
a2.channels.c1.capacity = 1000
a2.channels.c1.transactionCapacity = 100
# 进⾏组件间的绑定
a2.sources.s1.channels = c1
a2.sinks.sk1.channel = c1

Avro Sink服务端口和Avro Source客户端口问题

注意:Avro Sink输出端口号是44444,所以接收的Avro Source端口号也必须是44444
两者端口必须一致才能写入

启动

注意必须先启动a2

[root@Centos apache-flume-1.9.0-bin]# ./bin/flume-ng agent --conf conf/ --conf-file conf/example10.properties --name a2

再启动a1

[root@Centos apache-flume-1.9.0-bin]# ./bin/flume-ng agent --conf conf/ --conf-file conf/example10.properties --name a1

观察FileRoll Sink端输出数据情况

[root@Centos file_roll]# tail -f 1590487149213-1
hello beautiful girl zhang jiaYang
how are you
i miss you


启动kafka输入端输入数据

别忘记启动zookeeper kafka

[root@Centos zookeeper-3.4.12]# ./bin/zkServer.sh start zoo.cfg
[root@Centos zookeeper-3.4.12]# cd /usr/kafka_2.11-2.2.0/
[root@Centos kafka_2.11-2.2.0]# ./bin/kafka-server-start.sh -daemon config/server.properties
[root@Centos kafka_2.11-2.2.0]# ./bin/kafka-console-producer.sh --broker-list Centos:9092 --topic topic01
>this is a demo
>hello zhang jia yang
>i miss you
>^C[root@Centos kafka_2.11-2.2.0]# ./bin/kafka-console-producer.sh --broker-list Centos:9092 --topic topic01
>hello beautiful girl zhang jiaYang
>how are you
>i miss you
>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值