我正在尝试为Kafka InputStream实现一个非常简单的Apache Flink CEP。 Kafka生产者会生成一个简单的Double Value,然后通过Kafka主题将其作为字符串发送给消费者。目前,我正在使用Flink为CEP消费者编码。 到目前为止,这是我的书面代码:
public static void main(String[] args) throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.getConfig().disableSysoutLogging();
env.getConfig().setRestartStrategy(RestartStrategies.fixedDelayRestart(4, 10000));
env.setParallelism(3);
Properties properties = new Properties();
properties.setProperty("bootstrap.servers", "localhost:9092");
properties.setProperty("group.id", "flink_consumer");
DataStream<String> stream = env
.addSource(new FlinkKafkaConsumer09<>("temp", new SimpleStringSchema(), properties));
Pattern<String, ?> warning= Pattern.<String>begin("first")
.where(new IterativeCondition<String>() {
private static final long serialVersionUID = 1L;
@Override
public boolean filter(String value, Context<String> ctx) throws Exception {
return Double.parseDouble(value) >= 89.0;
}
})
.next("second")
.where(new IterativeCondition<String>() {
private static final long serialVersionUID = 1L;
@Override
public boolean filter(String value, Context<String> ctx) throws Exception {
return Double.parseDouble(value) >= 89.0;
}
})
.within(Time.seconds(10));
DataStream<String> temp = CEP.pattern(stream, warning).select(new PatternSelectFunction<String, String>() {
private static final long serialVersionUID = 1L;
@Override
public String select(Map<String, List<String>> pattern) throws Exception {
List warnung1 = pattern.get("first");
String first = (String) warnung1.get(1);
return first;
}
});
temp.print();
env.execute();
}
如果我尝试执行此代码,则为错误消息:
线程“ main”中的异常java.lang.NoSuchFieldError:NO_INDEX在 org.apache.flink.cep.PatternStream.select(PatternStream.java:102)在 CEPTest.main(CEPTest.java:50)
所以看来我用CEP模式生成的DataStream是错误的,但是我不知道该方法有什么问题。每个帮助都会很棒!
编辑:我尝试了其他一些示例,每次执行时,我都遇到相同的错误。所以我认为我的包裹有问题吗?