• 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
  • 相关阅读:
    又见斐波那契 矩阵快速幂 线性代数 转移矩阵构造
    Sticks POJ
    四则运算表达式求值——中缀表达式转后缀及计算
    D. Who killed Cock Robin 湖北省大学程序设计竞赛
    B. Salty Fish Go! -期望题(瞎搞题)
    A. Srdce and Triangle 几何题
    H. GSS and Simple Math Problem 高精度乘法模板
    小国的复仇 想法题/数学题附数论模板
    【作业】用栈模拟dfs
    KMP算法
  • 原文地址:https://www.cnblogs.com/noyouth/p/13094059.html
Copyright © 2020-2023  润新知