I am using Flink 1.2 CEP to detect missing Heart beat event from a device. I read Heart beat events from RabbitMQ source and using following Pattern to detect missing heart beat of device keyed by serial number by timeout function.
This pattern stream works for the cases where at least single heart beat is sent from the device. But I also need to handle the use case of detecting missing heart beat of a device which has not initiated even a single heart beat after the application start.
For this I need to initialize the input heart beat stream with all the devices init Heart Beat event. If I initialize the stream this will take care of devices which has not receiving its first heart beat also to timeout and raise an alert.
How do I initialize the data stream with init heart beat data for all devices even before listening from RMQSource Function?
//Reading heart beat of device from RabbitMQ queue
DataStream<HeartBeatEvent> heartBeatStream=
env.addSource(rmqSource).assignTimestampsAndWatermarks(new
IngestionTimeExtractor<String>());
//Pattern to detect missing heartbeat
Pattern<HeartBeanEvent, ?> heartBeatEventPattern = Pattern.<
HeartBeanEvent >begin("first")
.subtype(HeartBeanEvent.class)
.next("second")
.subtype(HeartBeanEvent.class)
.within(Time.seconds(360));
DataStream<Either< HeartBeanEvent, String>> result =
CEP.pattern(heartBeatStream.keyBy(serialNum),
heartBeatEventPattern).
select(new PatternTimeoutFunction< HeartBeanEvent, HeartBeanEvent >() {
public HeartBeanEvent timeout(Map<String, HeartBeanEvent >
pattern, long timeoutTimestamp) throws Exception {
System.out.println("Missing heart beat:" +
pattern.get("first").getSerialNum() + ":" +
pattern.get("first").getEventTime());
return pattern.get("first");
}
},new PatternSelectFunction< HeartBeanEvent, String>() {
public String select(Map<String, HeartBeanEvent > pattern) {
return null;
}
});