这里主要是案例,后续要结合实际业务做更复杂的场景,比如条件是否可以从redis里面获取???
完整案例:
import org.apache.flink.api.common.typeinfo.TypeInformation; import org.apache.flink.cep.CEP; import org.apache.flink.cep.PatternFlatSelectFunction; import org.apache.flink.cep.PatternStream; import org.apache.flink.cep.pattern.Pattern; import org.apache.flink.cep.pattern.conditions.IterativeCondition; import org.apache.flink.streaming.api.TimeCharacteristic; import org.apache.flink.streaming.api.datastream.DataStream; import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; import org.apache.flink.streaming.api.functions.IngestionTimeExtractor; import org.apache.flink.streaming.api.windowing.time.Time; import org.apache.flink.util.Collector; import java.util.List; import java.util.Map; public class CEPMonitoring { private static final double TEMPERATURE_THRESHOLD = 100; private static final int MAX_RACK_ID = 10; private static final long PAUSE = 100; private static final double TEMPERATURE_RATIO = 0.5; private static final double POWER_STD = 10; private static final double POWER_MEAN = 100; private static final double TEMP_STD = 20; private static final double TEMP_MEAN = 80; public static void main(String[] args) throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); // Use ingestion time => TimeCharacteristic == EventTime + IngestionTimeExtractor env.setStreamTimeCharacteristic(TimeCh