持久性参与者和读取处理器之间的 Lagom 消息持久性

Lagom message durability between persistent actor and read processor

只是想知道从持久事件源参与者到 lagom 中的读取处理器的事件通知传递的保证,对于将更新查询端的读取处理器的事件通知,是否存在或没有消息持久性?

我知道最终一致性很好,但我说的是事件处理程序通知 Cassandra 读取处理器。

通过在持久实体中使用事件溯源和在 read-side 处理中使用偏移跟踪来保证事件处理。

当您的持久化实体命令处理程序持久化事件时,每个事件都按顺序存储 "offset"

Read-side 处理器通过轮询数据库来查找偏移量大于已处理的最后一个偏移量的事件。因为所有事件和每个 read-side 处理器的最新偏移量都保存在数据库中,这确保即使 read-side 处理器崩溃并重新启动也不会丢失事件。

Lagom 的 Cassandra read-side 处理器 return 一个 CompletionStageFuture 生成一个 Cassandra BoundStatement 实例列表,并且这些是在原子中执行的批量更新和偏移量更新。只要你的 read-side 事件处理程序的所有效果都被捕获在它产生的更新列表中,这就确保了事件将被有效处理一次:如果部分更新失败,它将自动重试。

如果您在事件处理程序中执行任何其他操作,则需要确保偏移量更新仅在事件处理程序成功时发生。 CompletionStageFuture 事件处理程序 return 必须仅在您的 side-effect 完成后完成,并且应该传播操作的成功或失败。请注意,如果偏移量未更新,您的事件处理程序将被重试,因此如果您的事件处理程序与外部服务交互,例如,您需要确保它是幂等的。

您还应该了解最终一致性如何影响事物。 akka-persistence-cassandra configuration reference 有一些细节:

The returned event stream is ordered by the offset (timestamp), which corresponds to the same order as the write journal stored the events, with inaccuracy due to clock skew between different nodes. The same stream elements (in same order) are returned for multiple executions of the query on a best effort basis. The query is using a Cassandra Materialized View for the query and that is eventually consistent, so different queries may see different events for the latest events, but eventually the result will be ordered by timestamp (Cassandra timeuuid column). To compensate for the the eventual consistency the query is delayed to not read the latest events, the duration of this delay is defined by this configuration property.

However, this is only best effort and in case of network partitions or other things that may delay the updates of the Materialized View the events may be delivered in different order (not strictly by their timestamp).

重要的后果是,如果最终一致性的延迟比配置的最终一致性延迟长(可能是由于Cassandra节点之间的网络分区),则有可能发生事件"lost"。 read-side 处理程序可能已经处理了一个较新的事件并在较旧的事件传递到它正在读取的节点之前存储了它的偏移量。您可能需要相应地调整您的配置。