Flink cep需求代码实践02

业务需求01: 

 

疑惑点:关于水印的环节,最后一条数据不进入cep触发计算。

初始operation_type=1且接下来的数据也是operation_type=1,且次数大于等于3,并且数据与数据之前的时间间隔要小于11000毫秒,且所有匹配数据的时间间隔必须在5分钟之内。

数据如下:

{"operation_type":"1","order_number":"1","device_code":"6f253e518373bcbe","create_date":"1616653174000"}
{"operation_type":"1","order_number":"2","device_code":"6f253e518373bcbe","create_date":"1616653274000"}
{"operation_type":"1","order_number":"3","device_code":"6f253e518373bcbe","create_date":"1616653374000"}
{"operation_type":"1","order_number":"4","device_code":"6f253e518373bcbe","create_date":"1616653474000"}
{"operation_type":"2","order_number":"5","device_code":"6f253e518373bcbe","create_date":"1616653574000"}
{"operation_type":"1","order_number":"6","device_code":"6f253e518373bcbe","create_date":"1616653674000"}

 

代码如下:

 

package com.test.yarn;

/**
 * @program: flink-cep_2.11
 * @description:
* @author: Mr.Wang
 * @create: 2020-12-09 09:58
 **/


import com.alibaba.fastjson.JSONObject;
import com.sjb.constant.Constants;
import com.sjb.schema.CustomerDeserializationSchema;
import com.sjb.test.HBaseWriter;
import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.api.common.functions.RichMapFunction;
import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.cep.CEP;
import org.apache.flink.cep.PatternSelectFunction;
import org.apache.flink.cep.PatternStream;
import org.apache.flink.cep.RichPatternFlatSelectFunction;
import org.apache.flink.cep.nfa.aftermatch.AfterMatchSkipStrategy;
import org.apache.flink.cep.pattern.Pattern;
import org.apache.flink.cep.pattern.conditions.RichIterativeCondition;
import org.apache.flink.cep.pattern.conditions.SimpleCondition;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.TimeCharacteristic;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.timestamps.AscendingTimestampExtractor;
import org.apache.flink.streaming.api.functions.timestamps.BoundedOutOfOrdernessTimestampExtractor;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;
import org.apache.flink.util.Collector;

import java.util.Iterato
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值