Flume整合kafka

很简单,大家不要感觉很高大上

写之前 小伙伴先确保自己的zk跟kafka集群可以用哈,不然运行下面的代码无效

在kafka/job/下创建文件 flumeTokafka.conf   

job是我的一个文件夹,这个conf文件 放在哪都行

# Name the components on this agent 
a1.sources = r1
a1.sinks = k1 
a1.channels = c1

# Describe/configure the source 
a1.sources.r1.type = netcat 
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444
# Describe the sink 
#a1.sinks.k1.type = logger
a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
a1.sinks.k1.topic = test01
a1.sinks.k1.brokerList = es2:9092
a1.sinks.k1.requiredAcks = 1
a1.sinks.k1.batchSize = 20

# Use a channel which buffers events in memory 
a1.channels.c1.type = memory 
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
a1.sources.r1.channels = c1 
a1.sinks.k1.channel = c1

kafka创建一个topic

./bin/kafka-topics.sh --create --zookeeper 192.168.244.160:2181,192.168.244.161:2181,192.168.244.162:2181 --partition 3 --replication-factor 3 --topic test01

然后开启消费者

./bin/kafka-console-consumer.sh --zookeeper 192.168.244.160:2181,192.168.244.161:2181,192.138.244.162:2181 --topic test01 --from-beginning

开启Flume

进入到flume的bin目录下

bin/flume-ng agent --conf conf/ --name a1 --conf-file job/flumeTokafka.conf   

再打开一个这台机器的窗口

telnet localhost 44444模仿系统向flume输入数据

输入a s ds s s然后kafka会消费到,Ok测试完成

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值