0

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;
            }
        });
Abirami
  • 87
  • 7
  • If you know all the devices beforehand may be you can send all heartbeats in the same queue but before the devices originally send heartbeats. Or maybe initiate another datastream and join it with the rabbitmq source stream, since you can control your own initialization stream, send your data before anything comes through? – Biplob Biswas Aug 02 '17 at 09:49
  • Yes, I am initializing inventory devices in a data stream and joining it with rabbitmq. source stream. – Abirami Aug 04 '17 at 05:49

0 Answers0