Akka - 如何检查邮件在收件箱中的时长?
Akka - how to check how long a message was in inbox?
如何在 akka 中查看邮件在收件箱中的时长?如果邮件在收件箱中的时间过长,我想制作一条日志消息。类似于:
override def receive: Receive = {
case Message =>
val timeInInbox = ...
if (timeInInbox > treshold) log.warn("bla bla bla the doom is coming")
Akka 目前没有内置的东西可以做到这一点。
您可以创建一个自定义邮箱实现,它在 enqueue
上记录每条消息的到达时间并在 dequeue
上记录队列持续时间。请参阅 Akka 文档中的“Creating your own Mailbox type”。
请注意,调用 getCurrentTimeMillis
或类似的方法并不便宜,因此您可能会发现这样的邮箱具有显着的性能成本。我想这就是 Akka 不提供开箱即用的原因。
有可用的指标/遥测库可以提供此信息。
一个是 kamon.io (open source), which gives you a "time-in-mailbox" metric, see http://kamon.io/documentation/kamon-akka/0.6.6/actor-router-and-dispatcher-metrics/
另一个(非自由,闭源)是“Lightbend Telemetry", which calls it "mailbox time", see http://developer.lightbend.com/docs/monitoring/latest/instrumentations/akka/akka.html#actor-metrics
如何在 akka 中查看邮件在收件箱中的时长?如果邮件在收件箱中的时间过长,我想制作一条日志消息。类似于:
override def receive: Receive = {
case Message =>
val timeInInbox = ...
if (timeInInbox > treshold) log.warn("bla bla bla the doom is coming")
Akka 目前没有内置的东西可以做到这一点。
您可以创建一个自定义邮箱实现,它在 enqueue
上记录每条消息的到达时间并在 dequeue
上记录队列持续时间。请参阅 Akka 文档中的“Creating your own Mailbox type”。
请注意,调用 getCurrentTimeMillis
或类似的方法并不便宜,因此您可能会发现这样的邮箱具有显着的性能成本。我想这就是 Akka 不提供开箱即用的原因。
有可用的指标/遥测库可以提供此信息。 一个是 kamon.io (open source), which gives you a "time-in-mailbox" metric, see http://kamon.io/documentation/kamon-akka/0.6.6/actor-router-and-dispatcher-metrics/
另一个(非自由,闭源)是“Lightbend Telemetry", which calls it "mailbox time", see http://developer.lightbend.com/docs/monitoring/latest/instrumentations/akka/akka.html#actor-metrics