We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flink的CEP解决了什么样的问题: 比如:
主要分为两个步骤:
DataStream<Event> input = ... Pattern<Event, ?> pattern = Pattern.<Event>begin("start").where( new SimpleCondition<Event>() { @Override public boolean filter(Event event) { return event.getId() == 42; } } ).next("middle").subtype(SubEvent.class).where( new SimpleCondition<SubEvent>() { @Override public boolean filter(SubEvent subEvent) { return subEvent.getVolume() >= 10.0; } } ).followedBy("end").where( new SimpleCondition<Event>() { @Override public boolean filter(Event event) { return event.getName().equals("end"); } } ); PatternStream<Event> patternStream = CEP.pattern(input, pattern); DataStream<Alert> result = patternStream.process( new PatternProcessFunction<Event, Alert>() { @Override public void processMatch( Map<String, List<Event>> pattern, Context ctx, Collector<Alert> out) throws Exception { out.collect(createAlertFrom(pattern)); } });
模拟电商网站用户搜索的数据来作为数据的输入源,然后查找其中重复搜索某一个商品的人,发送一条告警消息
public static void main(String[] args) throws Exception{ final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(1); DataStreamSource source = env.fromElements( //浏览记录 Tuple3.of("Marry", "外套", 1L), Tuple3.of("Marry", "帽子",1L), Tuple3.of("Marry", "帽子",2L), Tuple3.of("Marry", "帽子",3L), Tuple3.of("Ming", "衣服",1L), Tuple3.of("Marry", "鞋子",1L), Tuple3.of("Marry", "鞋子",2L), Tuple3.of("LiLei", "帽子",1L), Tuple3.of("LiLei", "帽子",2L), Tuple3.of("LiLei", "帽子",3L) ); //定义Pattern,寻找连续搜索帽子的用户 Pattern<Tuple3<String, String, Long>, Tuple3<String, String, Long>> pattern = Pattern .<Tuple3<String, String, Long>>begin("start") .where(new SimpleCondition<Tuple3<String, String, Long>>() { @Override public boolean filter(Tuple3<String, String, Long> value) throws Exception { return value.f1.equals("帽子"); } }) //.timesOrMore(3); .next("middle") .where(new SimpleCondition<Tuple3<String, String, Long>>() { @Override public boolean filter(Tuple3<String, String, Long> value) throws Exception { return value.f1.equals("帽子"); } }); KeyedStream keyedStream = source.keyBy(0); PatternStream patternStream = CEP.pattern(keyedStream, pattern); SingleOutputStreamOperator matchStream = patternStream.select(new PatternSelectFunction<Tuple3<String, String, Long>, String>() { @Override public String select(Map<String, List<Tuple3<String, String, Long>>> pattern) throws Exception { List<Tuple3<String, String, Long>> middle = pattern.get("middle"); return middle.get(0).f0 + ":" + middle.get(0).f2 + ":" + "连续搜索两次帽子!"; } }); matchStream.printToErr(); env.execute("execute cep"); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Flink的CEP解决了什么样的问题:
比如:
程序结构
主要分为两个步骤:
官网案例:
实战案例
模拟电商网站用户搜索的数据来作为数据的输入源,然后查找其中重复搜索某一个商品的人,发送一条告警消息
The text was updated successfully, but these errors were encountered: