• 一个Esper入门实例


    1.新建一个java web项目,目录如图所示

    2.

    package com.test.esper;
    
    import com.test.esper.ScuRate;
    import com.espertech.esper.client.EPAdministrator;
    import com.espertech.esper.client.EPRuntime;
    import com.espertech.esper.client.EPServiceProvider;
    import com.espertech.esper.client.EPServiceProviderManager;
    import com.espertech.esper.client.EPStatement;
    import com.espertech.esper.client.EventBean;
    import com.espertech.esper.client.UpdateListener;
    
    public class test {
        public static void main(String[] args) throws InterruptedException {        
            EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();        
            EPAdministrator admin = epService.getEPAdministrator();        
            String product = ScuRate.class.getName();    
            String epl = "select respCode,count(1) from "
                    + product +
                    " (respCode='00').win:length_batch(10)";
             
            EPStatement state = admin.createEPL(epl);    
            state.addListener(new AppleListener());        
            EPRuntime runtime = epService.getEPRuntime();            
            for (int i = 0; i < 10; i++) {
                ScuRate rate = new ScuRate();
                rate.setRespCode("00");
                runtime.sendEvent(rate); 
            }              
        }        
    }
    
    class AppleListener implements UpdateListener    
    {        
         public void update(EventBean[] newEvents, EventBean[] oldEvents)    
            {    
                if (newEvents != null)    
                {    
                    Long count = (Long) newEvents[0].get("count(1)");
                    System.out.println(count);
                }    
            }        
    }  
    package com.test.esper;
    
    public class ScuRate {
       
            private String respCode;
            
            public String getRespCode()    
            {    
                return respCode;    
            }    
            
            public void setRespCode(String respCode)    
            {    
                this.respCode = respCode;    
            } 
        
    }

    3.通过类sql的方式容易得到查询的结果

  • 相关阅读:
    oracle学习 五 使用存储过程创建一个重置密码为123456的功能(持续更新中)
    oracle学习 四(持续更新中)无法为表空间 MAXDATA 中的段创建 INITIAL 区
    P3224 [HNOI2012]永无乡
    P3521 [POI2011]ROT-Tree Rotations
    UVA11090 Going in Cycle!!
    P1136 迎接仪式
    P1984 [SDOI2008]烧水问题(具体证明)
    P1494 [国家集训队]小Z的袜子
    P2680 运输计划
    P2831 愤怒的小鸟
  • 原文地址:https://www.cnblogs.com/corolcorona/p/7354987.html
Copyright © 2020-2023  润新知