flink 不在 std 输出中打印对象 [英] flink don't print the object in the std output
问题描述
我正在 flink 中做一个简单的程序,但它不会在 std 输出中打印任何字符串.我已经尝试在流上使用 print() 方法,并在其结果上使用 reduce 函数和 after print() 方法.这是一个代码:
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:
公共类 StreamingJob {
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;
}
}
}
}
推荐答案
所以每当你使用 println()
或 print()
打印流数据/对象时,它实际上打印在控制台上.
So whenever you use println()
or print()
to print the stream data/object, it actually prints on the console.
- 当您在本地
IDE
中执行代码时,它会在IDE 控制台
中打印流数据/对象,但 - 当您将代码部署为
Flink Job
时,您可以在 Flink 目录中的.out
文件中看到打印的输出.在下图中,您可以看到flink-keshavlodhi-taskexecutor-0-Keshavs-MacBook-Pro.local.out
文件.
- When you execute code in local
IDE
it prints the stream data/object inIDE 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 seeflink-keshavlodhi-taskexecutor-0-Keshavs-MacBook-Pro.local.out
file.
您可以在系统中找到 Flink 日志目录,您将 Flink tar 文件解压到该目录中.例如
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/
注意:每当您使用任何 logger
API 打印该时间时,您都可以在 .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屋!