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

阅读更多

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

 

Why use Siddhi:

  • It is 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依赖


    org.wso2.siddhi
    siddhi-core
    4.2.0



    org.wso2.siddhi
    siddhi-query-api
    4.2.0



    org.wso2.siddhi
    siddhi-query-compiler
    4.2.0

 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();

 

你可能感兴趣的:(java,大数据)