CEP(siddhi)复杂事件流程引擎_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > CEP(siddhi)复杂事件流程引擎

CEP(siddhi)复杂事件流程引擎

 2018/8/27 18:47:33  shangboz  程序员俱乐部  我要评论(0)
  • 摘要:Siddhi是一个轻量级的,简单的开源的复杂事件流程引擎。它使用类SQL的语言描述事件流任务,可以很好的支撑开发一个可扩展的,可配置的流式任务执行引擎。传统设计之中,为了支持不同的告警规则类型,我们需要编写不同的业务逻辑代码,但是使用了Siddhi之后,我们只需要配置不同的流任务Siddhiql,即可以支持不同的告警业务。WhyuseSiddhi:Itisfast.UBERusesittoprocess20Billioneventsperday(300,000eventspersecond)
  • 标签:事件 流程

Siddhi是一个轻量级的,简单的开源的复杂事件流程引擎。它使用类SQL的语言描述事件流任务,可以很好的支撑开发一个可扩展的,可配置的流式任务执行引擎。传统设计之中,为了支持不同的告警规则类型,我们需要编写不同的业务逻辑代码,但是使用了Siddhi之后,我们只需要配置不同的流任务Siddhiql,即可以支持不同的告警业务。

?

Why use Siddhi:

  • It isclass="Apple-converted-space">?fast.?UBER?uses it to process 20 Billion events per day (300,000 events per second).?
  • It is?lightweight?(<2MB), and embeddable in Android and RaspberryPi.
  • It has?over 40?Siddhi Extensions
  • It is?used by over 60 companies including many Fortune 500 companies?in production. Following are some examples:
    • WSO2?uses Siddhi for the following purposes:
      • To provide stream processing capabilities in their products such as?WSO2 Stream Processor.
      • As the?edge analytics?library of?WSO2 IoT Server.
      • As the core of?WSO2 API Manager's throttling.?
      • As the core of?WSO2 products'?analytics.
    • UBER?uses Siddhi for fraud analytics.
    • Apache Eagle?uses Siddhi as a policy engine.
  • Solutions based on Siddhi have been?finalists at?ACM DEBS Grand Challenge Stream Processing competitions?in 2014, 2015, 2016, 2017.
  • Siddhi has been?the basis of many academic research projects?and has?over 60 citations.

Overview

?

?1.maven依赖

<dependency>
    <groupId>org.wso2.siddhi</groupId>
    <artifactId>siddhi-core</artifactId>
    <version>4.2.0</version>
</dependency>

<dependency>
    <groupId>org.wso2.siddhi</groupId>
    <artifactId>siddhi-query-api</artifactId>
    <version>4.2.0</version>
</dependency>

<dependency>
    <groupId>org.wso2.siddhi</groupId>
    <artifactId>siddhi-query-compiler</artifactId>
    <version>4.2.0</version>
</dependency>

?2、siddhi代码执行实例

// Creating Siddhi Manager
SiddhiManager siddhiManager = new SiddhiManager();

String siddhiApp = "define stream cseEventStream (symbol string, price float, volume long); " +
        "" +
        "@info(name = 'query1') " +
        "from cseEventStream#window.length(0) " +
        "select symbol, price, avg(price) as ap, sum(price) as sp, count(price) as cp " +
        "group by symbol " +
        "output first every 4000 milliseconds "+
        "insert into outputStream;";

// Generating runtime
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
// Starting event processing
siddhiAppRuntime.start();
// Adding callback to retrieve output events from query
siddhiAppRuntime.addCallback("query1", new QueryCallback()
{
    @Override
    public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents)
    {
        System.out.println("============query callback============");
        EventPrinter.print(timeStamp, inEvents, removeEvents);
        /*System.out.println(timeStamp);
        System.out.println(inEvents);*/
    }
});
siddhiAppRuntime.addCallback("cseEventStream", new StreamCallback() {
    @Override
    public void receive(Event[] events) {
        System.out.println("============input stream callback============");
        EventPrinter.print(events);
    }
});


// Retrieving InputHandler to push events into Siddhi
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");


int i = 1;
while (i <= 10) {
    float p = i*10;
    inputHandler.send(new Object[]{"WSO2", p, 100});
    System.out.println("\"WSO2\", " + p);
    inputHandler.send(new Object[] {"IBM", p, 100});
    System.out.println("\"IBM\", " + p);
    Thread.sleep(1000);
    i++;
}

// Shutting down the runtime
siddhiAppRuntime.shutdown();

// Shutting down Siddhi
siddhiManager.shutdown();

?

上一篇: Siddhi Query Language 下一篇: 没有下一篇了!
发表评论
用户名: 匿名