繁体   English   中英

Apache Flink(集群中的标准输出错误)

[英]Apache Flink (Error in stdout in cluster)

Apache Flink ,我无法在std out看到输出,但我的工作正在成功运行并且数据即将到来

当您在集群上运行您的作业时,DataStreams 被打印到 TaskManager 进程的标准输出。 这个 TaskManager stdout 被定向到 Flink 根目录的 ./log/ 目录中的一个 .out 文件。 我相信这是在这里您已经看到了您的输出。

我不知道是否可以更改 TaskManagers 的标准输出,但是,一个快速而肮脏的解决方案可能是将输出写入套接字:

output.writeToSocket(outputHost, outputPort, new SimpleStringSchema())
public static void main(String[] args) throws Exception {

    // the host and the port to connect to
    final String hostname = "192.168.1.73";
    final int port = 9000;

    final StreamExecutionEnvironment env = StreamExecutionEnvironment.createRemoteEnvironment("192.168.1.68", 6123);

    // get input data by connecting to the socket
    DataStream<String> text = env.socketTextStream(hostname, port, "\n");

    // parse the data, group it, window it, and aggregate the counts
    DataStream<WordWithCount> windowCounts = text

            .flatMap(new FlatMapFunction<String, WordWithCount>() {
                public void flatMap(String value, Collector<WordWithCount> out) {
                    for (String word : value.split("\\s")) {
                        out.collect(new WordWithCount(word, 1L));
                    }
                }
            })

            .keyBy("word").timeWindow(Time.seconds(5))

            .reduce(new ReduceFunction<WordWithCount>() {
                public WordWithCount reduce(WordWithCount a, WordWithCount b) {
                    return new WordWithCount(a.word, a.count + b.count);
                }
            });

    // print the results with a single thread, rather than in parallel
    windowCounts.print().setParallelism(1);

    env.execute("Socket Window WordCount");
}

public static class WordWithCount {

    public String word;
    public long count;

    public WordWithCount() {
    }

    public WordWithCount(String word, long count) {
        this.word = word;
        this.count = count;
    }

    @Override
    public String toString() {
        return word + " : " + count;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM