我有一个简单的查询:
define stream myEventStream (userId string, price int);
define stream outputStream (avgPrice double, userId string);
@info(name = 'aQuery')
from myEventStream#window.time(5000)
select avg(price) as avgPrice, userId group by userId
insert into outputStream;
当我添加查询回调时,我没有得到任何回复。
runtime.addCallback("aQuery", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
}
});
我正在另一个帖子中制作消息:
final AtomicInteger counter = new AtomicInteger(0);
final Random rnd = new Random(System.currentTimeMillis());
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(() -> {
while (counter.getAndIncrement() < 100) {
try {
handler.send(new Object[]{"user1", rnd.nextInt(100)});
handler.send(new Object[]{"user2", rnd.nextInt(100)});
handler.send(new Object[]{"user3", rnd.nextInt(100)});
System.out.println("Sent: " + counter.get());
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
});
我期待结果每5秒钟。我在这里错过了什么?请帮忙。 谢谢。
答案 0 :(得分:0)
问题是我在产生事件流的代码之后立即关闭了运行时。然而,我已经能够向运行时发送消息,尽管它已经关闭了。没有例外。