flume ng简单例子

来源:互联网 发布:二少捏脸数据 编辑:程序博客网 时间:2024/06/06 13:19

本例子来源于flume官方文档,主要演示部署flume agent单节点,接收信息然后控制台输出。

首先编辑配置文件,在conf目录中新建文件example.conf,然后添加以下内容:

# example.conf: A single-node Flume configuration# Name the components on this agenta1.sources = r1a1.sinks = k1a1.channels = c1# Describe/configure the sourcea1.sources.r1.type = netcata1.sources.r1.bind = localhosta1.sources.r1.port = 44444# Describe the sinka1.sinks.k1.type = logger# Use a channel which buffers events in memorya1.channels.c1.type = memorya1.channels.c1.capacity = 1000a1.channels.c1.transactionCapacity = 100# Bind the source and sink to the channela1.sources.r1.channels = c1a1.sinks.k1.channel = c1


配置文件中定义了一个单节点agent名为a1. a1有一个source监听来自端口444444的数据,有一个channel缓冲事件数据在内存中,之后通过一个sink打印出事件内容到控制台。配置文件中同时会定义各个组件自己特有的一些配置参数。


然后启动:

bin/flume-ng agent --conf conf --conf-file conf/example.conf --name a1 -Dflume.root.logger=INFO,console

最后打开另外一个终端,执行命令:

uanggang@huanggangdeMacBook-Pro:~/workspace/dafka-project$ telnet localhost 44444Trying ::1...telnet: connect to address ::1: Connection refusedTrying 127.0.0.1...Connected to localhost.Escape character is '^]'.hello worldOK

在之前启动flume agent的终端上就会显示刚才输出的内容:

2015-11-18 10:31:17,101 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:94)] Event: { headers:{} body: 68 65 6C 6C 6F 20 77 6F 72 6C 64 0D             hello world. }2015-11-18 10:38:03,428 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:94)] Event: { headers:{} body: 0D                                              . }



0 0
原创粉丝点击