简体   繁体   English

如何更新/刷新 Flink 应用程序中的参数

[英]How to update/refresh a parameter in Flink application

I have a Flink application on AWS Kinesis Analytics service.我在 AWS Kinesis Analytics 服务上有一个 Flink 应用程序。 I need to filter some values on a data stream based on a threshold.我需要根据阈值过滤数据 stream 上的一些值。 Also, I'm passing the threshold parameter using AWS Systems Manager Parameter Store service.此外,我正在使用 AWS Systems Manager Parameter Store 服务传递阈值参数。 For now, I got this:现在,我得到了这个:

  • In my Main class:在我的主要 class 中:
val threshold: Int = ssmParameter.getParameterRequest(ssmClient, "/kinesis/threshold").toInt

val kinesis_deserialization_schema = new KinesisDeserialization[ID]
            val KinesisConsumer = new FlinkKinesisConsumer[ID](
                "Data-Stream",
                kinesis_deserialization_schema,
                consumerProps
            )
            val KinesisSource = env.addSource(KinesisConsumer).name(s"Kinesis Data")
val valid_data = KinesisSource
          .filter(new MyFilter[ID](threshold))
          .name("FilterData")
          .uid("FilterData")
  • Filter class:过滤器 class:
import cl.mydata.InputData
import org.apache.flink.api.common.functions.FilterFunction

class MyFilter[ID <: InputData](
                                  threshold: Int
                                ) extends FilterFunction[ID] {
  override def filter(value: ID): Boolean = {
      value.myvalue > threshold
    }
  }
}

This works fine, the thing is that I need to update the threshold parameter every hour, because that value can be changed by my client.这很好用,问题是我需要每小时更新阈值参数,因为我的客户可以更改该值。

Perhaps you can implement the ProcessingTimeCallback interface in the MyFilter class, which supports timer operations, and you can update the threshold in the onProcessingTime function或许可以在支持定时器操作的MyFilter class中实现ProcessingTimeCallback接口,可以在onProcessingTime中更新阈值function

public class MyFilter extends FilterFunction<...> implements ProcessingTimeCallback { 
    int threshold;

    @Override
    public void open(Configuration parameters) throws Exception {
        scheduler.scheduleAtFixedRate(this, 1, 1, TimeUnit.HOURS);

        final long now = getProcessingTimeService().getCurrentProcessingTime();
        getProcessingTimeService().registerTimer(now + 3600000, this);
    }

    @Override
    public boolean filter(IN xxx) throws Exception {
        return xxx > threshold;
    }

    @Override
    public void onProcessingTime(long timestamp) throws Exception {
        threshold = XXXX;

        final long now = getProcessingTimeService().getCurrentProcessingTime();
        getProcessingTimeService().registerTimer(now + 3600000, this);
    }
}

You could turn the FilterFunction into a BroadcastProcessFunction , and broadcast new thresholds as they become available.您可以将FilterFunction转换为BroadcastProcessFunction ,并在新阈值可用时广播它们。

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

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