flink不要在std输出中打印对象 [英] flink don't print the object in the std output

查看:195
本文介绍了flink不要在std输出中打印对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用flink做一个简单的程序,但是它不会在std输出中显示任何字符串.我已经尝试在流上使用print()方法,并在其结果上使用reduce函数和print()方法.这是一个代码:

公共类StreamingJob {

  public static void main(String [] args)引发异常{最后的StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();env.enableCheckpointing(10000);env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);env.getConfig().setAutoWatermarkInterval(200L);List< Oggetto>对象= produciValori();DataStream< Oggetto>流= env.fromCollection(对象);溪流./*timeWindowAll(Time.seconds(5)).reduce(new Reduce()).*/打印();env.execute("Flink Streaming Java Quickstart Mio");}私有静态List< Oggetto>produciValori(){List< Oggetto>objects = new ArrayList<>();int prop1 = 0;整数prop2 = 1000;字符串stringa1 ="stringa1:" + prop1;字符串stringa2 ="stringa2:" + prop2;对于(int i = 0; i< 1000; i ++){prop1 = prop1 +1;prop2 = prop2 +1;stringa1 ="stringa1:" + prop1;stringa2 ="stringa2:" + prop2;Oggetto o =新的Oggetto(prop1,prop2,stringa1,stringa2);objects.add(o);}返回对象;}私有静态类Reduce实现org.apache.flink.api.common.functions.ReduceFunction< Oggetto>.{@Override公共Oggetto reduce(Oggetto oggetto,Oggetto t1)引发异常{如果(oggetto.getPropInt1()< = t1.getPropInt1()){返回oggetto;}别的 {返回t1;}}} 

}

解决方案

因此,每当您使用 println() print()打印流数据/对象时,它实际上会在控制台上打印.

  • 在本地 IDE 中执行代码时,它将在 IDE控制台中打印流数据/对象,但是
  • 当您将代码作为 Flink Job 部署时,您可以在Flink目录的 .out 文件中看到打印的输出.在下图中,您可以看到 flink-keshavlodhi-taskexecutor-0-Keshavs-MacBook-Pro.local.out 文件.

您可以在系统中找到Flink tar文件的目录中找到Flink日志目录.例如

 /Users/keshavlodhi/softwares/flink-1.10.0/log/ 

注意:每当您使用任何 logger API打印该时间时,都可以在 .log 文件中找到流数据/对象./p>

i'm doing a simple program in flink, but it doesn't print any string in the std output. I have tried both using a print() method on the stream and using a reduce function and after print() method on its result. this is a code:

public class StreamingJob {

public static void main(String[] args) throws Exception {
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.enableCheckpointing(10000);
    env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);
    env.getConfig().setAutoWatermarkInterval(200L);
    List<Oggetto> objects = produciValori();
    DataStream<Oggetto> stream = env.fromCollection(objects);
    stream./*
    timeWindowAll(Time.seconds(5)).reduce(new Reduce()).*/
    print();
    env.execute("Flink Streaming Java Quickstart Mio");
}

private static List<Oggetto> produciValori() {
    List<Oggetto> objects = new ArrayList<>();
    int prop1 = 0;
    int prop2 = 1000;
    String stringa1 = "stringa1: " + prop1;
    String stringa2 = "stringa2: " + prop2;
    for (int i = 0; i < 1000; i++) {
        prop1 = prop1 + 1;
        prop2 = prop2 + 1;
        stringa1 = "stringa1: " + prop1;
        stringa2 = "stringa2: " + prop2;
        Oggetto o = new Oggetto(prop1, prop2, stringa1, stringa2);
        objects.add(o);
    }
    return objects;
}

private static class Reduce implements org.apache.flink.api.common.functions.ReduceFunction<Oggetto> {
    @Override
    public Oggetto reduce(Oggetto oggetto, Oggetto t1) throws Exception {
        if (oggetto.getPropInt1() <= t1.getPropInt1()){
            return oggetto;
        }else {
            return t1;
        }
    }
}

}

解决方案

So whenever you use println() or print() to print the stream data/object, it actually prints on the console.

  • When you execute code in local IDE it prints the stream data/object in IDE console but
  • When you deploy the code as a Flink Job you can see the printed output in .out file in your Flink directory. In the below image you can see flink-keshavlodhi-taskexecutor-0-Keshavs-MacBook-Pro.local.out file.

You can find Flink log directory in your system where you have extracted the Flink tar file. e.g

/Users/keshavlodhi/softwares/flink-1.10.0/log/

Note: Whenever you use any logger APIs to print that time you can find your stream data/object in .log files.

这篇关于flink不要在std输出中打印对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆