2

在 Akka Actor 应用程序中,我必须在收到控制消息后推迟接收某些类型的消息。为了控制消息,我必须实现自己的优先邮箱,将控制消息优先于普通消息。让我们假设此实现有效且无法撤消。邮箱如下所示,具有重写的入队和出队功能。

object MyControlAwareMailbox {
   class MyControlAwareMessageQueue extends MessageQueue with MyControlAwareMessageQueueSemantics {

      private final val controlQueue: Queue[Envelope] = new ConcurrentLinkedQueue[Envelope]()
      private final val queue: Queue[Envelope] = new ConcurrentLinkedQueue[Envelope]()

  }

我的配置文件也如下所示:

custom-dispatcher {
   mailbox-requirement =
   "com.example.MyControlAwareMessageQueueSemantics"
}

akka.actor.mailbox.requirements {
  "com.example.MyControlAwareMessageQueueSemantics" =
   custom-dispatcher-mailbox
}

custom-dispatcher-mailbox {
   mailbox-type = "com.example.MyControlAwareMailbox"
}

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

akka.actor.default-mailbox {
   mailbox-type = "com.example.MyControlAwareMailbox"
}

有没有一种方法可以配置我的应用程序,以便我可以使用 akka stash 来存储消息?

4

0 回答 0