Akka Persistence:当它不仅仅是状态更新时,命令的执行去哪里了
Akka Persistence: Where do the execution of the Command Goes when it is not simply a state update
澄清一下:当执行不仅仅是状态更新时(就像在网上找到的大多数示例中那样),命令的执行去哪里了
例如,就我而言,
命令是FetchLastHistoryChangeSet,它包括根据我们的位置从外部服务获取最后的历史变更集上次离开了。也就是说之前历史ChangeSet Fetched.
最新变化的时间
事件 将是 HistoryChangeSetFetched(changeSet, time)。与上面所说的相关,时间应该是新历史 ChangeSet Fetched 的最新变化的时间(根据当前正在处理的命令事件)
现在在我看到的所有示例中,它总是:(i) 验证命令,然后,(ii) 坚持事件,最后 (iii) 处理事件。
在 处理事件 中,我看到除了 updatestate 逻辑之外还添加了自定义代码。其中,自定义代码一般添加在更新状态函数之后。但是这个习惯大部分时间都是关于将消息发送回发送者,或者将它广播到事件总线。
根据我的示例,很明显我需要执行很少的操作才能实际调用 Persist(HistoryChangeSetFetched(changeSet, time))。确实我需要新的变更集,以及它的最新变更时间。
我认为唯一可行的方法是在验证命令
中进行提取
即:
case FetchLastHistoryChangeSet => val changetuple = if ValidateCommand(FetchLastHistoryChangeSet) persit(HistoryChangeSetFetched(changetuple._1, changetuple._2)) { historyChangeSetFetched =>
updateState(historyChangeSetFetched)
}
其中 ValidateCommand(FetchLastHistoryChangeSet)
按照逻辑,读取最后的 changeSet 时间(changeSet 的最新更改),基于它获取一个新的 changeset,如果它存在,获取其最新更改的时间,并且 return元组。
My question is, is that how it is supposed to work. Validating command
can be something as complex as that ? i.e. actually executing the
command ?
如文档中所述:"validation can mean anything, from simple inspection of a command message's fields up to a conversation with several external services"
所以我认为你正在尝试做的是完全正确的。与外部服务的任何交互都必须在命令验证阶段完成。
澄清一下:当执行不仅仅是状态更新时(就像在网上找到的大多数示例中那样),命令的执行去哪里了
例如,就我而言,
命令是FetchLastHistoryChangeSet,它包括根据我们的位置从外部服务获取最后的历史变更集上次离开了。也就是说之前历史ChangeSet Fetched.
最新变化的时间
事件 将是 HistoryChangeSetFetched(changeSet, time)。与上面所说的相关,时间应该是新历史 ChangeSet Fetched 的最新变化的时间(根据当前正在处理的命令事件)
现在在我看到的所有示例中,它总是:(i) 验证命令,然后,(ii) 坚持事件,最后 (iii) 处理事件。
在 处理事件 中,我看到除了 updatestate 逻辑之外还添加了自定义代码。其中,自定义代码一般添加在更新状态函数之后。但是这个习惯大部分时间都是关于将消息发送回发送者,或者将它广播到事件总线。
根据我的示例,很明显我需要执行很少的操作才能实际调用 Persist(HistoryChangeSetFetched(changeSet, time))。确实我需要新的变更集,以及它的最新变更时间。
我认为唯一可行的方法是在验证命令
中进行提取即:
case FetchLastHistoryChangeSet => val changetuple = if ValidateCommand(FetchLastHistoryChangeSet) persit(HistoryChangeSetFetched(changetuple._1, changetuple._2)) { historyChangeSetFetched =>
updateState(historyChangeSetFetched)
}
其中 ValidateCommand(FetchLastHistoryChangeSet)
按照逻辑,读取最后的 changeSet 时间(changeSet 的最新更改),基于它获取一个新的 changeset,如果它存在,获取其最新更改的时间,并且 return元组。
My question is, is that how it is supposed to work. Validating command can be something as complex as that ? i.e. actually executing the command ?
如文档中所述:"validation can mean anything, from simple inspection of a command message's fields up to a conversation with several external services"
所以我认为你正在尝试做的是完全正确的。与外部服务的任何交互都必须在命令验证阶段完成。