Akka,实施建议

Akka, advices on implementation

我想创建一个将我们的(企业)特定工具与 Slack 集成的应用程序。为此,我可以预见一些 机器人 将事件发送到 Slack 和一些 命令 触发操作。

我想使用 Akka,因为它是一个流行词,看起来不错,但没有任何支持它的论据。 (这不是问题,因为我会在空闲时间独自开发这个应用程序)。

但我对如何创建 "Actor based application" 没有任何经验。我已经有 3 位演员,两位负责收集 Event,一位负责将这些 Event 发布到 Slack。每个收集器都由一个计时器触发,它们持有对发布者的引用并向他发送消息......有效..

对于 commands 部分,我什么都没有,但可以想象一个 listener(播放 http 控制器)将 Slack 请求转换为消息并将它们发送给一个演员。理想情况下,我想将此 listener 与将处理命令的 Actor 分离。

我想就如何开发这种应用程序提出一些建议,我让参与者按时间收集信息,而其他参与者则对消息做出反应。

谢谢。

对于基于时间的 activity,即 "ticks" 或 "heartbeats",documentation 展示了一种非常好的定期向 Actor 发送消息的模式。

对于您的其他需求,Actor 在消息传入时对其进行响应,这正是 Actor 的接收方法的目的。来自 documentation:

Actors are objects which encapsulate state and behavior, they communicate exclusively by exchanging messages which are placed into the recipient’s mailbox. In a sense, actors are the most stringent form of object-oriented programming, but it serves better to view them as persons: while modeling a solution with actors, envision a group of people and assign sub-tasks to them, arrange their functions into an organizational structure and think about how to escalate failure (all with the benefit of not actually dealing with people, which means that we need not concern ourselves with their emotional state or moral issues). The result can then serve as a mental scaffolding for building the software implementation.