zoukankan      html  css  js  c++  java
  • Flume 自定义Sink

    自定义sink类,并将相关工程打包放在flume的lib目录下

    public class MySink extends AbstractSink implements Configurable {
    
        private static final Logger logger = LoggerFactory.getLogger(MySink.class);
    
        //全局变量,仅做演示,无实际意义
        private String prefix;
        private String suffix;
    
        @Override
        public void configure(Context context) {
    
            prefix = context.getString("prefix");
            suffix = context.getString("suffix","atguigu");
        }
    
        @Override
        public Status process() throws EventDeliveryException {
    
            Status status = null;
    
            Channel channel = getChannel();
            Transaction transaction = channel.getTransaction();
            transaction.begin();
    
            try {
                Event event = channel.take();
    
                //核心业务逻辑,输出到日志
                String body = new String(event.getBody());
                logger.info(prefix+body+suffix);
    
                transaction.commit();
                status = Status.READY;
    
            }catch (Exception e){
                transaction.rollback();
                status = Status.BACKOFF;
            }finally {
                transaction.close();
            }
    
    
    
            return status;
        }
    
    }

    flume配置文件

    # 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 = com.atguigu.sink.MySink
    a1.sinks.k1.prefix = sleep--
    a1.sinks.k1.suffix = --banzhang
    
    # 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
  • 相关阅读:
    English trip V1
    English trip V1
    第一类斯特林数
    bzoj 3601 一个人的数论
    bzoj 4407 于神之怒加强版
    bzoj 2693 jzptab
    bzoj 4184 shallot
    luogu P3920 [WC2014]紫荆花之恋
    bzoj 4269 再见Xor
    luogu P2183 [国家集训队]礼物
  • 原文地址:https://www.cnblogs.com/noyouth/p/13094059.html
Copyright © 2011-2022 走看看