开发者社区 > 大数据与机器学习 > 实时计算 Flink > 正文

请大家帮我看看下列问题是什么情况?

55e4ae8fbcf5776df58ec44b96b9a5d2.png为啥我这个窗口函数里面的 log一直没数据呢。上面那个有输出。 logger.info("kafkaStream Window....."); 没有。b6201aefc771a9013987fd7f7ce84913.png 看起来是执行了。

展开
收起
圆葱猪肉包 2023-03-27 13:46:40 202 0
2 条回答
写回答
取消 提交回答
  • /** *todo: 2023/3/20 23:14 九师兄 * * 测试数据 {"id":"11","name":"akka","password":"123","password1":"123","age":1} * 输出结果:1 分钟内收集到 student 的数据条数是:7 **/ public void timeWindowAll() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); env.setStreamTimeCharacteristic(TimeCharacteristic.ProcessingTime); //2.定义加载或创建数据源(source),监听9000端口的socket消息 DataStream textStream9000 = env.socketTextStream("localhost", 9992, "\n");

    SingleOutputStreamOperator<Student> student = textStream9000.map(string -> JSONObject.parseObject(string, Student.class));
    
    
    student.timeWindowAll(Time.seconds(5)).apply(new AllWindowFunction<Student, List<Student>, TimeWindow>() {
        @Override
        public void apply(TimeWindow window, Iterable<Student> values, Collector<List<Student>> out) throws Exception {
            ArrayList<Student> students = Lists.newArrayList(values);
            if (students.size() > 0) {
                System.out.println("1 分钟内收集到 student 的数据条数是:" + students.size());
                out.collect(students);
            }
        }
    }).print();
    
    env.execute("flink learning connectors kafka");
    

    }我测试是可以的 你对比一下。此回答整理自钉群“【③群】Apache Flink China社区”

    2023-03-28 10:54:30
    赞同 展开评论 打赏
  • GitHub https://github.com/co63oc/cloud

    Flink中如何使用TimeWindowAll https://www.yisu.com/zixun/525527.html

    2023-03-27 21:57:41
    赞同 展开评论 打赏

实时计算Flink版是阿里云提供的全托管Serverless Flink云服务,基于 Apache Flink 构建的企业级、高性能实时大数据处理系统。提供全托管版 Flink 集群和引擎,提高作业开发运维效率。

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载