目前,我正在尝试用Java将几个EPL语句与Esper CEP 8结合起来。当我在EPCompile中读到单个EPLs时,它们都像打开一样工作。例如:
String EPL1 ="@name('EPA12') select * from IEvent where j>3;\n";但是当我试图一次读取多个EPL操作时,只考虑第一个操作。例如,如果我尝试下面的语句,它只检查j>3,而CEP打印它的所有事件。但未选中i>4 (EPA13)。
String EPLnotworking ="@name('EPA12') insert into EPA12 select * from IEvent where j>3;\n"+
"@name('EPA13') select * from EPA12 where i> 4;";Java的编译工作没有任何问题。有没有可能我错误地模拟了我的问题?
Configuration configuration = new Configuration();
configuration.getCommon().addEventType(IEvent.class);
String EPLnotworking ="@name('EPA12') insert into EPA12 select * from IEvent where j>3;\n"+
"@name('EPA13') select * from EPA12 where i> 4;";
EPCompiled compiled = EPCompilerProvider.getCompiler().compile(EPLnotworking, new CompilerArguments(configuration));
runtime = EPRuntimeProvider.getDefaultRuntime(configuration);
DeploymentOptions deploymentOptions = new DeploymentOptions().setDeploymentId("IEvent");
EPStatement stmt = runtime.getDeploymentService().deploy(compiled, deploymentOptions).getStatements()[0];
stmt.addListener(new UpdateListener() {
public void update(EventBean[] newEvents, EventBean[] oldEvents, EPStatement statement, EPRuntime runtime) {
if (newEvents == null) {
return;
}
for (EventBean event : newEvents) {
System.out.println(event.get("i"));
System.out.println(event.get("j"));
}
}
});
public void run() {
//recieve Events
IEvent test = new IEvent();
// test.setI(received);
runtime.getEventService().sendEventBean(test, "IEvent");
}我注意到,即使值为i=<4,CEP也会生成输出。
有人知道问题出在哪里吗?提前谢谢你
发布于 2018-12-22 19:45:02
你没有说明什么是“不起作用的”。“不工作”是否意味着没有输出事件?这可能是因为代码只将侦听器附加到第一条语句,而忽略了第二条语句。您可以将侦听器附加到所有语句。
EPStatement[] stmts = runtime.getDeploymentService().deploy(compiled, deploymentOptions).getStatements();
for (EPStatement stmt : stmts) {
stmt.addListener(new UpdateListener() {
public void update(EventBean[] newEvents, EventBean[] oldEvents, EPStatement statement, EPRuntime runtime) {
if (newEvents == null) {
return;
}
for (EventBean event : newEvents) {
System.out.println(event.get("i"));
}
}
});
}https://stackoverflow.com/questions/53894899
复制相似问题