Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Flink CEP event handling

Shulou Source: shulou.com Published: 2022-06-01 06:15:47 10月04日 Update

This article will explain in detail the handling of Flink CEP events for you. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

What is CEP?

Complex event processing that allows specific event models to be detected in unbounded data streams

Single mode

A single pattern refers to a pattern, which can be a singleton or a circular pattern.

Patterns are singleton and can be converted into circular patterns through quantifiers. Each pattern can have one or more conditions to decide which events to accept.

Quantifier

Pattern.oneOrMore (): expect a given event to occur one or more times

Pattern.times (# oftimes): a pattern that expects a given event to occur a certain number of times

Pattern.times (# fromTimes, # toTimes): expect a given event to occur between a minimum and a maximum

Pattern.greedy (): greedy algorithm, matching as many as possible, can not make the pattern group greedy

Pattern.optional (): become optional

Example: / / expect 4 times start.times (4); / / expect 0 or 4 times start.times (4) .optional (); / / expect 2, 3 or 4 times start.times (2, 4); / / expect 2, 3 or 4 times and repeat as many times as possible start.times (2, 4) .greedy () / expect 0, 2, 3 or 4 start.times (2, 4) .optional (); / expect 0, 2, 3 or 4 times, and repeat as many times as possible start.times (2, 4). Optional (). Greedy (); / expect 1 to multiple start.oneOrMore (); / / expect 1 to multiple times and repeat as many times as possible start.oneOrMore (). Greedy () / / expect 0 to multiple start.oneOrMore () .optional (); / / expect 0 to multiple times and repeat as many times as possible start.oneOrMore () .optional () .greedy (); / / expect 2 to multiple start.timesOrMore (2); / / expect 2 to multiple times and repeat as many times as possible start.timesOrMore (2) .greedy () / expect 0, 2 or more start.timesOrMore (2) .optional (); / / expect 0, 2 or more times and repeat as many times as possible start.timesOrMore (2) .optional () .greedy (); condition

The conditions for judging event attributes can be the following methods

Pattern.where ()

Pattern.or ()

Pattern.until ()

The input parameters of these methods can be IterativeCondition or SimpleCondition

The pattern.subtype method restricts acceptance that the event type is a subtype of the initial event.

Iterative condition IterativeCondition

Simple conditional SimpleCondition

Combinatorial conditions. Where (). Or (), etc.

Stop condition. Stop ()

Combination mode

FlinkCEP supports continuous policies between events in the following form

Strictly continuous: expect all matching events to occur strictly one after another, without any mismatch

Loose continuity: ignores mismatched events between matching events

Uncertain loose continuity: further loose continuity, allowing additional matches for some matching events to be ignored

1. Next () specifies strict continuous 2. FollowedBy () specifies loose continuous 3. FollowedByAny () uncertain loose continuous 4. NotNext () if you don't want to be directly followed by a specific event 5. NotFollowedBy (), if you don't want a particular event to occur anywhere between two events. Ps: a pattern sequence cannot end with notFollowedBy () A NOT pattern cannot be preceded by an optional pattern

Define a pattern with a valid time constraint: the pattern.within () method specifies that it occurs within the valid time.

Pattern sequences can only have one time limit, and if multiple times are limited to different patterns, the minimum time limit will be used.

The loop mode is loose contiguous by default, and if the combination is strictly continuous, it needs to be explicitly specified using the consecutive () method. If you want to use uncertain loose continuity, you can use the allowCombinations () method

= = example: consecutive==

Pattern.begin ("start") .where (new SimpleCondition () {@ Override public boolean filter (Event value) throws Exception {return value.getName () .equals ("c");}}) .followedBy ("middle") .where (new SimpleCondition () {@ Override public boolean filter (Event value) throws Exception {return value.getName () .equals ("a")) }}) .oneOrMore () .consecutive () .followedBy ("end1") .where (new SimpleCondition () {@ Override public boolean filter (Event value) throws Exception {return value.getName () .equals ("b");}}) Input: C D A1 A2A3 D A4B, the following output will be produced: if strict continuity is applied: {C A1 B}, {C A1 A 2B}, {C A1 A 2A 3 B}} does not impose strict continuity: {C A1 B}, {C A1 A 2B}, {C A1 A 2A 3 B}, {C A1 A 2A 3 A 4 B}

= = example: allowCombinations==

Pattern.begin ("start") .where (new SimpleCondition () {@ Override public boolean filter (Event value) throws Exception {return value.getName () .equals ("c");}}) .followedBy ("middle") .where (new SimpleCondition () {@ Override public boolean filter (Event value) throws Exception {return value.getName () .equals ("a")) }}) .oneOrMore () .allowCombinations () .followedBy ("end1") .where (new SimpleCondition () {@ Override public boolean filter (Event value) throws Exception {return value.getName () .equals ("b");}}) Input: C D A1 A2A3 D A4B, the output is as follows: if you use uncertain loose continuity: {C A1 B}, {C A1 A 2B}, {C A 1A 3 B}, {C A 1A 4 B}, {C A1 A 2A 3 B}, {C A1 A 3A 4 B}, {C A1 A 2A 3 A 4 B}, {C A1 A 2A 3 A 4 B}, if not used: {C A 1B}, {C A1 A 2B}, {C A1 A 2A 3B}, {C A1 A 2A 3A4B} mode group

Define a sequence of patterns as begin,followedBy,followedByAny and next conditions

This is the end of this article on "Flink CEP event handling". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Event pattern expectation loose condition number of times as much as possible method time limit processing between sequence example article loop minimum effective single multiple Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux vpn Apple Shulou Information Xiaomi