flink dataStream 在aggregateFunction 不能使用metrics

在aggregateFunction 不能使用metrics

  1. 在aggregateFunction 由于没有继承richFunction, 没有open方法,无法使用getRuntimeContext()获取RuntimeContext对象
    1. 使用richAggregateFunction,存在open方法和getRuntimeContext()
    • 结果报错:
      Exception in thread "main" java.lang.UnsupportedOperationException: This aggregation function cannot be a RichFunction.
            	at org.apache.flink.streaming.api.datastream.WindowedStream.aggregate(WindowedStream.java:289)
      
    1. 此问题暂时 没有解决方法
    • 通过flink官网 可以得知,metrics的使用是需要使用继承RichFunction的类
      在这里插入图片描述

    • 使用getRuntimeContext().getMetricGroup()将metrics注册到flink

    • 由上述问题可知,使用richAggregateFunction启动会抛出异常,This aggregation function cannot be a RichFunction

    最后结论

    • 放弃在aggregateFunction中收集metricsaggregate只做数据的简单处理后将数据收集成一个batch,后面接一个RichFlatMapFunction调用外部方法 ,在这获取RuntimeContext收集数据的metrics
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值