如何使用 PriorityExecutorBasedEventDrivenDispatcher 防止消息重新排序?
我的 Akka FSM actor 需要根据类型对消息进行优先级排序。具体来说,Actor 按优先顺序接收以下类别之一的消息:
- 触发状态转换的
- 消息 查询当前状态的
- 消息 导致 Actor 执行某些工作的消息(“WorkMsg”)
根据 Akka 文档,消息可以使用包含 PriorityGenerator 的 PriorityExecutorBasedEventDrivenDispatcher 根据上面的列表确定优先级。我已经用这个调度程序实现了 FSM actor,并且效果很好。
问题是这个调度程序还重新排序 WorkMsgs,这不是我想要的。
WorkMsgs 包含时间戳并发送到按此时间戳排序的 FSM actor。当 FSM actor 处理 WorkMsgs 时,它会丢弃比之前的 WorkMsg 更旧的 WorkMsgs。因此,如果重新排序,我就会丢失数据。
如果没有 PriorityExecutorBasedEventDrivenDispatcher,WorkMsgs 不会重新排序,但上面列表中的优先级不会得到满足。
如何维护上面列表中的优先级,同时防止相同优先级的消息重新排序?
My Akka FSM actor has the need to prioritize messages dependent on type. To be specific, the actor receives messages in one of these categories, in prioritized order:
- Messages that triggers state transitions
- Messages that query the current state
- Messages that causes the actor to perform some work ("WorkMsg")
According to the Akka docs, messages can be prioritized according to the list above with a PriorityExecutorBasedEventDrivenDispatcher containing a PriorityGenerator. I've implemented the FSM actor with this dispatcher and it works well.
The problem is that this dispatcher also reorders WorkMsgs, which is not what I want.
WorkMsgs contain a timestamp and are sent to the FSM actor sorted by this timestamp. When the FSM actor processes WorkMsgs, it discards WorkMsgs that are older than the previous WorkMsg. So if these are reordered, I lose data.
Without the PriorityExecutorBasedEventDrivenDispatcher, WorkMsgs are not reordered, but then the priorities in the list above are not satisfied.
How can I maintain the priorities in the list above, while preventing reordering of messages of the same priority?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确定代理参与者的优先级可以确定发送给您的工作参与者的消息的优先级。您必须对传入消息进行排序和存储,并实现优先级逻辑。另外,工作人员还必须在每条消息之后响应代理,以使其知道它已准备好进行更多工作。
A prioritizing proxy actor can prioritize messages to be sent to your worker actor. You will have to sort and store the incoming messages as well as implement the prioritization logic. The worker will additionally have to respond to the proxy after each message to let it know that it is ready for more work.