【问题标题】:Setting Bounded mailbox for an actor that uses stashing为使用存储的参与者设置有界邮箱
【发布时间】:2013-12-23 13:45:57
【问题描述】:

我有一个依赖隐藏的演员。存储需要UnboundedDequeBasedMailbox。可以和Bounded邮箱一起使用stash吗?

正如 Arnaud 指出的,我的设置是:

Actor with UnrestrictedStash with RequiresMessageQueue[BoundedDequeBasedMessageQueueSemantics]

和配置:

akka {

    loggers = ["akka.event.slf4j.Slf4jLogger"]
    loglevel = INFO
    daemonic = on

    actor {
            mailbox {
                bounded-deque-based {
                    mailbox-type = "akka.dispatch.BoundedDequeBasedMailbox"
                    mailbox-capacity = 2000
                    mailbox-push-timeout-time = 5s
                }
                requirements {
                  "akka.dispatch.BoundedDequeBasedMessageQueueSemantics" = akka.actor.mailbox.bounded-deque-based
                }
            }
    }
}

错误是:

[ERROR] 2013/12/06 14:03:58.268 [r-4] a.a.OneForOneStrategy - DequeBasedMailbox required, got: akka.dispatch.UnboundedMailbox$MessageQueue
An (unbounded) deque-based mailbox can be configured as follows:
  my-custom-mailbox {
    mailbox-type = "akka.dispatch.UnboundedDequeBasedMailbox"
  }

akka.actor.ActorInitializationException: exception during creation
    at akka.actor.ActorInitializationException$.apply(Actor.scala:218) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.actor.ActorCell.create(ActorCell.scala:578) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:425) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.actor.ActorCell.systemInvoke(ActorCell.scala:447) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:262) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.dispatch.Mailbox.run(Mailbox.scala:218) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386) [akka-actor_2.10-2.2.0.jar:2.2.0]
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.10.2.jar:na]
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.10.2.jar:na]
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.10.2.jar:na]
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.10.2.jar:na]
Caused by: akka.actor.ActorInitializationException: DequeBasedMailbox required, got: akka.dispatch.UnboundedMailbox$MessageQueue
An (unbounded) deque-based mailbox can be configured as follows:
  my-custom-mailbox {
    mailbox-type = "akka.dispatch.UnboundedDequeBasedMailbox"
  }

    at akka.actor.ActorInitializationException$.apply(Actor.scala:218) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.actor.UnrestrictedStash$class.$init$(Stash.scala:82) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at com.fg.mail.smtp.index.Indexer.<init>(Indexer.scala:38) ~[classes/:na]
    at com.fg.mail.smtp.Supervisor$$anonfun$preStart$1.apply(Supervisor.scala:20) ~[classes/:na]
    at com.fg.mail.smtp.Supervisor$$anonfun$preStart$1.apply(Supervisor.scala:20) ~[classes/:na]
    at akka.actor.CreatorFunctionConsumer.produce(Props.scala:369) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.actor.Props.newActor(Props.scala:323) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.actor.ActorCell.newActor(ActorCell.scala:534) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    at akka.actor.ActorCell.create(ActorCell.scala:560) ~[akka-actor_2.10-2.2.0.jar:2.2.0]
    ... 9 common frames omitted

如果我这样做Props.withMailbox("bounded-deque-based"),那么我会得到

Caused by: akka.ConfigurationException: Mailbox Type [bounded-deque-based] not configured

回答:感谢 Arnaud:问题在于配置,基于 bounded-deque 的配置块应该与 akka 配置块处于同一级别。 Documentation 在这种情况下完全是误导......

akka {

    loggers = ["akka.event.slf4j.Slf4jLogger"]
    loglevel = INFO
    daemonic = on

    actor {
        mailbox {
            requirements {
                    "akka.dispatch.BoundedDequeBasedMessageQueueSemantics" = akka.actor.mailbox.bounded-deque-based
                  }
        }
    }
}

bounded-deque-based {
    mailbox-type = "akka.dispatch.BoundedDequeBasedMailbox"
    mailbox-capacity = 2000
    mailbox-push-timeout-time = 5s
}

【问题讨论】:

  • 我刚刚对邮箱配置的放置位置感到困惑。同意文档在这一点上很薄弱。
  • 你能指出这是什么版本的 Akka 吗?

标签: java scala akka messaging actor


【解决方案1】:

根据官方 Akka stash doc,您可以决定使用不强制任何邮箱类型的 Stash 特征,请参阅 UnrestrictedStash

如果您使用 UnrestrictedStash,您可以手动配置正确的邮箱,只要它扩展 akka.dispatch.DequeBasedMessageQueueSemantics 标记特征即可。

您可以在mailboxes doc 之后手动配置您的 BoundedMailbox 邮箱,如下所示:

bounded-mailbox {
  mailbox-type = "akka.dispatch.BoundedDequeBasedMailbox"
  mailbox-capacity = 1000
  mailbox-push-timeout-time = 10s
}

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

我自己没有尝试过,但应该可以。

编辑:您使用的是什么版本的 Akka?看起来 stash trait 定义在 2.2.0 版本中发生了变化

【讨论】:

  • 谢谢 Arnaud,就是这样。您能否详细说明邮箱手动配置?所以它扩展了 DequeBasedMessageQueueSemantics ?除了'with UnrestrictedStash with RequiresMessageQueue[BoundedDequeBasedMessageQueue]',配置是什么?
  • 我编辑了答案以添加一些有关邮箱配置的信息。
  • 我开始认为,问题出在 application.conf 中
  • 为什么要使用部署配置?
  • 我改了,我在做实验,因为我玩了一个多小时
猜你喜欢
  • 1970-01-01
  • 2018-11-01
  • 1970-01-01
  • 2018-03-23
  • 1970-01-01
  • 2015-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多