如何让多个上下文处理 Apama 中的事件
How can I have multiple contexts handle events in Apama
我正在尝试定义一个监视器,我在其中接收事件,然后在多个上下文中处理它们(如果我理解正确的话,大致等同于线程)我知道我可以写
spawn myAction() to myNewContext;
这将 运行 在新上下文中执行该操作。
但是我想要一个动作来响应进入我的监视器的事件:
on all trigger() as t {
doMyThing()
}
on all otherTrigger() as ot {
doMyOtherThing()
}
我可以使用特定上下文来定义我的 on all
吗?像
on all trigger() as t in myContext {
doMyThing()
}
on all otherTrigger() as t in myOtherContext {
doMyOtherThing()
}
如果不是,在 Apama EPL 中定义它的最佳方法是什么?我还可以让多个上下文在事件到达时以循环方式处理相同的事件吗?
来自外部接收器(即外部世界)的 Apama 事件仅传送到 public
上下文,包括 'main' 上下文。因此,根据您的架构,您可以将您的操作生成到 public 上下文
// set the receivesInput parameter to true to make this context public
spawn myAction() to context("myContext", true);
...
action myAction() {
on all trigger() as t {
doMyThing();
}
}
或者,将您的操作生成到私有上下文并在 public 上下文中设置事件转发器,通常是主上下文(它将始终存在)
spawn myAction() to context("myNewContext");
on all trigger() as t {
send t to "myChannel"; // forward all trigger events to the "myChannel" channel
}
...
action myAction() {
monitor.subscribe("myChannel"); // receive all events delivered to the "myChannel" channel
on all trigger() as t {
doMyThing();
}
}
生成到私有上下文并利用通道系统通常是更好的设计,因为它只将事件发送到关心它们的上下文
为了扩展 Madden 的回答(我还没有足够的代表发表评论),私有上下文和转发器也是实现真正循环的唯一方法:否则所有上下文都将接收所有事件。 最简单 方法是使用分区策略(例如,以 0 结尾的 ID 转到上下文 0,或者您正在监视的每台机器都有一个上下文等),因为这样每个在相同的上下文中跟踪关注点,您不必共享状态。
Also could I have multiple contexts handling the same events when they arrive, round robin style?
我不是很清楚。你在这里的目标是什么?如果您希望通过让 "next available" 上下文接收事件来减少延迟,这可能不是实现它的正确方法 - 决定哪个上下文处理事件意味着您需要上下文间通信和协调,这将增加延迟。如果您希望多个上下文处理相同的事件(例如,一个上下文运行您的温度尖峰规则,另一个运行您的长期温度平均规则,但两者都将温度读数作为输入),那么这是一个很好的方法,但它不是我的方法会调用循环法。
我正在尝试定义一个监视器,我在其中接收事件,然后在多个上下文中处理它们(如果我理解正确的话,大致等同于线程)我知道我可以写
spawn myAction() to myNewContext;
这将 运行 在新上下文中执行该操作。
但是我想要一个动作来响应进入我的监视器的事件:
on all trigger() as t {
doMyThing()
}
on all otherTrigger() as ot {
doMyOtherThing()
}
我可以使用特定上下文来定义我的 on all
吗?像
on all trigger() as t in myContext {
doMyThing()
}
on all otherTrigger() as t in myOtherContext {
doMyOtherThing()
}
如果不是,在 Apama EPL 中定义它的最佳方法是什么?我还可以让多个上下文在事件到达时以循环方式处理相同的事件吗?
来自外部接收器(即外部世界)的 Apama 事件仅传送到 public
上下文,包括 'main' 上下文。因此,根据您的架构,您可以将您的操作生成到 public 上下文
// set the receivesInput parameter to true to make this context public
spawn myAction() to context("myContext", true);
...
action myAction() {
on all trigger() as t {
doMyThing();
}
}
或者,将您的操作生成到私有上下文并在 public 上下文中设置事件转发器,通常是主上下文(它将始终存在)
spawn myAction() to context("myNewContext");
on all trigger() as t {
send t to "myChannel"; // forward all trigger events to the "myChannel" channel
}
...
action myAction() {
monitor.subscribe("myChannel"); // receive all events delivered to the "myChannel" channel
on all trigger() as t {
doMyThing();
}
}
生成到私有上下文并利用通道系统通常是更好的设计,因为它只将事件发送到关心它们的上下文
为了扩展 Madden 的回答(我还没有足够的代表发表评论),私有上下文和转发器也是实现真正循环的唯一方法:否则所有上下文都将接收所有事件。 最简单 方法是使用分区策略(例如,以 0 结尾的 ID 转到上下文 0,或者您正在监视的每台机器都有一个上下文等),因为这样每个在相同的上下文中跟踪关注点,您不必共享状态。
Also could I have multiple contexts handling the same events when they arrive, round robin style?
我不是很清楚。你在这里的目标是什么?如果您希望通过让 "next available" 上下文接收事件来减少延迟,这可能不是实现它的正确方法 - 决定哪个上下文处理事件意味着您需要上下文间通信和协调,这将增加延迟。如果您希望多个上下文处理相同的事件(例如,一个上下文运行您的温度尖峰规则,另一个运行您的长期温度平均规则,但两者都将温度读数作为输入),那么这是一个很好的方法,但它不是我的方法会调用循环法。