谷歌优化 网站建设,如何选择免费网站建设,哪个网站做的效果图好,dede+营销型网站1.新建-项目-新建项目 注意位置是将来打包文件存放的位置#xff0c;即我们打包好的文件在这/export/data个目录下寻找
2. 在maven项目中导入依赖
Pom.xml文件中写入
dependencies dependency groupIdorg.apache.flume/groupId artifa…1.新建-项目-新建项目 注意位置是将来打包文件存放的位置即我们打包好的文件在这/export/data个目录下寻找
2. 在maven项目中导入依赖
Pom.xml文件中写入
dependencies dependency groupIdorg.apache.flume/groupId artifactIdflume-ng-core/artifactId version1.9.0/version /dependency /dependencies 3.创建包scr-main-java右键-新建-软件包 4.创建Java类右键包名-新建-java类 5. 继承implements)flume 的拦截器接口
//键入implements Interceptor{} 光标定位到Interceptor alt enter键选择导入类导入flume的Interceptor即可 import org.apache.flume.interceptor.Interceptor; //此时会报错点击红色灯泡选择 实现方法 就会在下文写出需要Override的四个抽象类 6.实现方法
public class MyInterceptor implements Interceptor {Override//初始化方法public void initialize() {}//单个事件拦截//需求在event的头部信息中添加标记//提供给channel selector 选择发送给不同的channelOverridepublic Event intercept(Event event)//Map也需要alt enter 导入MapString, String headers event.getHeaders();//输入even.getHeaders().var回车即可自行填充等号前面的变量信息String log new String(event.getBody());//envent.getBody().var自行判断变量类型为byte,为方便使用改为String类型// 键入new String(envent.getBody()).var回车然后根据需要自行修改变量名//判断log开头的第一个字符字母则发到channel1数字则发到channel2char c log.charAt(0);//log.charAt(0).var回车即可自行填充等号前面的变量信息if(c 0 c 9){headers.put(type,number);}else if ((c A c Z) || (c a c z)){// 注意字符串类型要使用需要用单引号而不能用双引号headers.put(type,letter);}//因为头部信息属性是一个引用数据类型 直接修改对象即可也可以不调用以下的set方法 event.setHeaders(headers);//返回eventreturn event;}//批量事件拦截(处理多个event,系统调用这个方法)Overridepublic ListEvent intercept(ListEvent list) {for (Event event : list){intercept(event);}return list;}//重写静态内部类BuilderOverridepublic void close() {}public static class Builder implements Interceptor.Builder{//创建一个拦截器对象Overridepublic Interceptor build() {return new MyInterceptor();}//配置方法Overridepublic void configure(Context context) {}}}
7.打包idea右侧菜单栏maven-生命周期-package 打包完成在idea左侧菜单栏 target 中可以看到我们的包 8.将建好的包复制到flume家目录下的lib中即可使用
cp /export/data/flume-interceptor-demo/target/flume-interceptor-demo-1.0-SNAPSHOT.jar $FLUME_HOME/lib 9.测试 9.1 编辑 flume 配置文件 vim flume1.conf # agent a1.sources r1 a1.sinks k1 k2 a1.channels c1 c2 # Describe/configure the source a1.sources.r1.type netcat a1.sources.r1.bind node1 a1.sources.r1.port 44444 # channel selector: multiplexing 多路复用 默认为replicating 复制 a1.sources.r1.selector.type multiplexing # 填写相应inerceptor的header上的key a1.sources.r1.selector.header type # 分配不同value发送到的channel,number到c2letter到 c1 a1.sources.r1.selector.mapping.number c2 a1.sources.r1.selector.mapping.letter c1 #如果匹配不上默认选择的channel a1.sources.r1.selector.default c2 #interceptor a1.sources.r1.interceptors i1 a1.sources.r1.interceptors.i1.type com.ljr.flume.MyInterceptor$Builder # Describe the sink a1.sinks.k1.type avro a1.sinks.k1.hostname node1 a1.sinks.k1.port 4545 a1.sinks.k2.type avro a1.sinks.k2.hostname node1 a1.sinks.k2.port 4546 # Use a channel which buffers events in memory a1.channels.c1.type memory a1.channels.c1.capacity 1000 a1.channels.c1.transactionCapacity 100 a1.channels.c2.type memory a1.channels.c2.capacity 1000 a1.channels.c2.transactionCapacity 100 # Bind the source and sink to the channel a1.sources.r1.channels c1 c2 # 接收c1中的数据 a1.sinks.k1.channel c1 # 接收c2中的数据 a1.sinks.k2.channel c2 vim flume2.conf a2.sources r2 a2.sinks k2 a2.channels c2 # Describe/configure the source a2.sources.r2.type avro a2.sources.r2.bind node1 # flume1 中sink的输出端口 a2.sources.r2.port 4545 # Describe the sink a2.sinks.k2.type logger # Use a channel which buffers events in memory a2.channels.c2.type memory a2.channels.c2.capacity 1000 a2.channels.c2.transactionCapacity 100 # Bind the source and sink to the channel a2.sources.r2.channels c2 a2.sinks.k2.channel c2
vim flume3.conf a3.sources r3 a3.sinks k3 a3.channels c3 # Describe/configure the source a3.sources.r3.type avro a3.sources.r3.bind node1 # flume1 中sink的输出端口 a3.sources.r3.port 4546 # Describe the sink a3.sinks.k3.type logger # Use a channel which buffers events in memory a3.channels.c3.type memory a3.channels.c3.capacity 1000 a3.channels.c3.transactionCapacity 100 # Bind the source and sink to the channel a3.sources.r3.channels c3 a3.sinks.k3.channel c3
9.2测试 打开四个窗口前三个分别运行flume1.conf、flume2.conf、flume3.conf 配置的进程
第四个窗口启用necat,输入内容进行测试
flume-ng agent -c conf/ -f /export/server/flume/job/group2-multiplexing-test/flume1.conf -n a1
flume-ng agent -c conf/ -f /export/server/flume/job/group2-multiplexing-test/flume2.conf -n a2
flume-ng agent -c conf/ -f /export/server/flume/job/group2-multiplexing-test/flume3.conf -n a3
nc nc node1 44444 (flume1.conf中 source 填的主机名或IP地址 和端口号) 第一个窗口报错 ConnectException: 拒绝连接 可先忽略运行二、三窗口后即可连接 在窗口4中输入数字、字母、符号 分别在窗口二看到输出字母窗口三输出数字和符号 恭喜Interceptor起作用
文章转载自: http://www.morning.gprzp.cn.gov.cn.gprzp.cn http://www.morning.jikuxy.com.gov.cn.jikuxy.com http://www.morning.tknqr.cn.gov.cn.tknqr.cn http://www.morning.gidmag.com.gov.cn.gidmag.com http://www.morning.mqfw.cn.gov.cn.mqfw.cn http://www.morning.lmnbp.cn.gov.cn.lmnbp.cn http://www.morning.wbxtx.cn.gov.cn.wbxtx.cn http://www.morning.tqdlk.cn.gov.cn.tqdlk.cn http://www.morning.wpcfh.cn.gov.cn.wpcfh.cn http://www.morning.tkrwm.cn.gov.cn.tkrwm.cn http://www.morning.kdldx.cn.gov.cn.kdldx.cn http://www.morning.rfqkx.cn.gov.cn.rfqkx.cn http://www.morning.fgsqz.cn.gov.cn.fgsqz.cn http://www.morning.pypbz.cn.gov.cn.pypbz.cn http://www.morning.qblcm.cn.gov.cn.qblcm.cn http://www.morning.lbrrn.cn.gov.cn.lbrrn.cn http://www.morning.nrzkg.cn.gov.cn.nrzkg.cn http://www.morning.rsjng.cn.gov.cn.rsjng.cn http://www.morning.wkpfm.cn.gov.cn.wkpfm.cn http://www.morning.nlmm.cn.gov.cn.nlmm.cn http://www.morning.kzhxy.cn.gov.cn.kzhxy.cn http://www.morning.yxnfd.cn.gov.cn.yxnfd.cn http://www.morning.tlbdy.cn.gov.cn.tlbdy.cn http://www.morning.ljxps.cn.gov.cn.ljxps.cn http://www.morning.szoptic.com.gov.cn.szoptic.com http://www.morning.dhqg.cn.gov.cn.dhqg.cn http://www.morning.bccls.cn.gov.cn.bccls.cn http://www.morning.tnjz.cn.gov.cn.tnjz.cn http://www.morning.ngjpt.cn.gov.cn.ngjpt.cn http://www.morning.rlbg.cn.gov.cn.rlbg.cn http://www.morning.cgtrz.cn.gov.cn.cgtrz.cn http://www.morning.gnwse.com.gov.cn.gnwse.com http://www.morning.hjsrl.cn.gov.cn.hjsrl.cn http://www.morning.rbrhj.cn.gov.cn.rbrhj.cn http://www.morning.kczkq.cn.gov.cn.kczkq.cn http://www.morning.jrslj.cn.gov.cn.jrslj.cn http://www.morning.kpwdt.cn.gov.cn.kpwdt.cn http://www.morning.ldzxf.cn.gov.cn.ldzxf.cn http://www.morning.bmtkp.cn.gov.cn.bmtkp.cn http://www.morning.sqxr.cn.gov.cn.sqxr.cn http://www.morning.trqzk.cn.gov.cn.trqzk.cn http://www.morning.mdpkf.cn.gov.cn.mdpkf.cn http://www.morning.rhmpk.cn.gov.cn.rhmpk.cn http://www.morning.mnsmb.cn.gov.cn.mnsmb.cn http://www.morning.khpx.cn.gov.cn.khpx.cn http://www.morning.gcftl.cn.gov.cn.gcftl.cn http://www.morning.wblpn.cn.gov.cn.wblpn.cn http://www.morning.yybcx.cn.gov.cn.yybcx.cn http://www.morning.c7627.cn.gov.cn.c7627.cn http://www.morning.fpngg.cn.gov.cn.fpngg.cn http://www.morning.qkwxp.cn.gov.cn.qkwxp.cn http://www.morning.lrzst.cn.gov.cn.lrzst.cn http://www.morning.lmmh.cn.gov.cn.lmmh.cn http://www.morning.tbkqs.cn.gov.cn.tbkqs.cn http://www.morning.rpwm.cn.gov.cn.rpwm.cn http://www.morning.pqnkg.cn.gov.cn.pqnkg.cn http://www.morning.nckjk.cn.gov.cn.nckjk.cn http://www.morning.tfzjl.cn.gov.cn.tfzjl.cn http://www.morning.bnlkc.cn.gov.cn.bnlkc.cn http://www.morning.ngcw.cn.gov.cn.ngcw.cn http://www.morning.dnphd.cn.gov.cn.dnphd.cn http://www.morning.qmtzq.cn.gov.cn.qmtzq.cn http://www.morning.bmfqg.cn.gov.cn.bmfqg.cn http://www.morning.fhbhr.cn.gov.cn.fhbhr.cn http://www.morning.ykklw.cn.gov.cn.ykklw.cn http://www.morning.wztlr.cn.gov.cn.wztlr.cn http://www.morning.neletea.com.gov.cn.neletea.com http://www.morning.xhlpn.cn.gov.cn.xhlpn.cn http://www.morning.xxlz.cn.gov.cn.xxlz.cn http://www.morning.dhmll.cn.gov.cn.dhmll.cn http://www.morning.zjqwr.cn.gov.cn.zjqwr.cn http://www.morning.rrpsw.cn.gov.cn.rrpsw.cn http://www.morning.hqykb.cn.gov.cn.hqykb.cn http://www.morning.lhzqn.cn.gov.cn.lhzqn.cn http://www.morning.pinngee.com.gov.cn.pinngee.com http://www.morning.ctqlq.cn.gov.cn.ctqlq.cn http://www.morning.yhtnr.cn.gov.cn.yhtnr.cn http://www.morning.rdng.cn.gov.cn.rdng.cn http://www.morning.btjyp.cn.gov.cn.btjyp.cn http://www.morning.cmqrg.cn.gov.cn.cmqrg.cn