我正在尝试将一些参与者接收代码包装在 db 事务中,以构建通过更新数据库中的信息来处理事件的幂等持久视图。
class TrajectoryView extends IdempotentView {
override def viewId: String = "trajectoryView"
override def persistenceId: String = "sample-id-1"
override def handleEvent(event: Event): Unit = {
case ProcessDetectedEvent(time, processData, id, activityType) =>
val coords = Db.save(processData.coordinates)
Db.save(CoordinatesWrapper(id, coords))
case ProcessUpdatedEvent(id, processData, time) =>
val coords = Db.save(processData.coordinates)
Db.save(CoordinatesWrapper(id, coords))
}
}
abstract class IdempotentView extends PersistentView {
def handleEvent(event: Event): Unit = ???
var maxSeenSeqNumber = Db.query[SeqNumberWrapper].fetchOne().getOrElse(SeqNumberWrapper(0, viewId)).seqNumber
def receive: Receive = {
case event: Event =>
if (lastSequenceNr > maxSeenSeqNumber) {
Db.transaction {
Db.save(SeqNumberWrapper(lastSequenceNr, viewId))
handleEvent(event)
}
}
case _: Unit =>
println("Unknown message")
}
}
Error:(22, 50) missing parameter type for expanded function The argument types of an anonymous function must be fully known. (SLS 8.5)
Expected type was: Unit override def handleEvent(event: Event): Unit = {
我应该怎么办?我不明白这个错误的确切含义。从我的角度来看,我已经编写了所有类型,编译器不需要推断任何东西。