Esper:由于验证错误,EPL“select”失败

时间:2014-10-16 16:01:17

标签: complex-event-processing esper epl

我试图用Esper运行一个简单的测试(第14章,http://dl.e-book-free.com/2013/07/activiti_in_action.pdf)。代码非常简单:

public class EventLengthWindowTest {
  public class LoanRequestEvent {
    public int amount =2;

    public LoanRequestEvent(int a){
        amount += a;
    }
}

private int sumAmount = 0;

@Test
public void testEventLengthWindow() {
  Configuration configuration = new Configuration();
  configuration.addEventType(LoanRequestEvent.class); 

  EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration);
  EPAdministrator admin = epService.getEPAdministrator();
  EPStatement epStatement = admin.createEPL("select sum(amount) as sumAmount from LoanRequestEvent.win:length(2)");

  ...
}

我收到有关EPL部分的错误消息:

"select sum(amount) as sumAmount from LoanRequestEvent.win:length(2)"

它说:

com.espertech.esper.client.EPStatementException: Error starting statement: Failed to validate select-clause expression 'sum(amount)': Property named 'amount' is not valid in any stream [select sum(amount) as sumAmount from LoanRequestEvent.win:length(2)]

为什么会发生这种情况?

1 个答案:

答案 0 :(得分:2)

如果希望Esper读取和/或写入事件类,则需要为事件类中的事件属性提供JavaBean getter和setter。要使您的示例正常工作,您需要添加如下的getter:

public class LoanRequestEvent {
    public int amount =2;

    public LoanRequestEvent(int a){
        amount += a;
    }

    public int getAmount() {
        return amount;
    }
}
相关问题