Lagom 持久实体是Actor 吗? / 演员模型

Are Lagom Persistent Entities Actors? / Actor Models

我正在使用 Lagom 的永久实体,并支持读取端 Cassandra 来实现,保存读取端查询的状态。所以试图理解,持久实体也是演员吗?意味着一次只处理一个事件/命令?事件也是 "persistent entity" 处理的消息吗? 我找不到很多关于以下内容的文档:

  1. 持久实体在可配置的不活动时间后从内存中删除。
  2. 持久实体通过读取最近的快照和它之后的每个事件再次加载到内存中。
  3. 可以通过与从事件日志(真实来源)构建的持久实体状态进行比较来验证命令。您可以将产品存储在内部状态并知道何时再次添加产品。然后你可以通过不发出事件并返回错误来拒绝这个命令。

Are the persistent entities also actors? Meaning only one event / command will be handled at a time ?

我不会这样问的; actors do 执行同步消息处理,但是执行同步消息处理并不意味着它是 actor。

现在语义已经不存在了,我们可以解决这个问题了……PersistentEntity在技术上是 not actors... However, PersistentEntityRegistrys will create something that is a PersistentActor

  • is every entity persisted in memory once created?

根据 Akka 持久性快照(请参阅 here)机制,实体会持久保存在您使用的任何存储中。

  • If we go by a model in which the actor is removed after some timeout... Will the actor have to read all events again to handle another request?

同样,快照将大有帮助。

  • If adding items to cart is handled by commands / queries how is it ensured that the same item is not added onto the cart twice?

您可以阅读更多关于 Akka actors 传递语义的信息here