尝试使持久性actor要求带有RequiresMessageQueue的自定义邮箱时出错

时间:2019-03-17 23:16:05

标签: scala akka

我尝试以下操作:

class ClientActor (stockActor: ActorSelection, paymentsActor: ActorSelection) extends PersistentActor
  with AtLeastOnceDelivery with akka.actor.ActorLogging with RequiresMessageQueue[akka.custom.CustomMailbox]{
//actor implementation

}

我得到了错误:

illegal inheritance;

     self-type Shopping.ClientActor does not conform to akka.dispatch.RequiresMessageQueue[akka.custom.CustomMailbox]'s selftype akka.dispatch.RequiresMessageQueue[akka.custom.CustomMailbox]
      with AtLeastOnceDelivery with akka.actor.ActorLogging with RequiresMessageQueue[akka.custom.CustomMailbox]{

对于非持久性参与者也是如此:

    class PaymentsActor extends Actor with akka.actor.ActorLogging with RequiresMessageQueue[akka.custom.CustomMailbox] {
    // actor implementation
}

1 个答案:

答案 0 :(得分:1)

跟踪相关的源代码,PersistentActor扩展了Eventsourced,扩展了PersistenceStash,又扩展了trait Stash

trait Stash extends UnrestrictedStash with RequiresMessageQueue[DequeBasedMessageQueueSemantics]

如源代码中所述:

  

请注意,Stash特征只能与具有以下特征的演员一起使用:   有一个基于双端队列的邮箱。默认情况下,基于存储的演员请求   由于存储特性增加了基于双端队列的邮箱   RequiresMessageQueue[DequeBasedMessageQueueSemantics]。   您可以覆盖以下情况下提供的默认邮箱:   DequeBasedMessageQueueSemantics是通过配置请求的   ...

一种方法是配置您的自定义邮箱,类似于源代码注释中所建议的:

akka.actor.mailbox.requirements {
  "akka.dispatch.BoundedDequeBasedMessageQueueSemantics" = your-custom-mailbox
}