语法:
create context context_name
group [by] group_expression as category_label
[, group [by] group_expression as category_label]
[, ...]
from stream_def
例子:
create context esbtest group by id<0 as low, group by id>0 and id<10 as middle,group by id>10 as high from com.ebc.category.User
context esbtest select context.id,context.name,context.label, amount from com.ebc.category.User --监听器
Console.log("context.name=" + event.get("name") + ", " +
"context.id=" + event.get("id") + ", " +
"context.label=" + event.get("label")); --发送事件
User u1 = new User(1,20);
Console.log("sendEvent: id={},amount={}",u1.getId(),u1.getAmount());
runtime.sendEvent(u1);
User u2 = new User(0,30);
Console.log("sendEvent: id={},amount={}",u2.getId(),u2.getAmount());
runtime.sendEvent(u2);
User u3 = new User(11,20);
Console.log("sendEvent: id={},amount={}",u3.getId(),u3.getAmount());
runtime.sendEvent(u3); User u4 = new User(-1,40);
Console.log("sendEvent: id={},amount={}",u4.getId(),u4.getAmount());
runtime.sendEvent(u4);
输出
sendEvent: id=1,amount=20
context.name=esbtest, context.id=1, context.label=middle
sendEvent: id=0,amount=30
sendEvent: id=11,amount=20
context.name=esbtest, context.id=2, context.label=high
sendEvent: id=-1,amount=40
context.name=esbtest, context.id=0, context.label=low
id=0的事件,没有触发监听器,因为context里的三个category没有包含id=0的情况,所以这个事件就被排除掉了。