简单的Akka邮箱配置可丢弃溢出的邮件 [英] Simple Akka mailbox configuration to discard overflowing messages

查看:105
本文介绍了简单的Akka邮箱配置可丢弃溢出的邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含2个参与者的系统,它们共享相同的配置。所需的配置是:邮箱的最大容量为1条消息,任何溢出的消息都应丢弃。

I have a system with 2 actors, which share the same configuration. This desired configuration is: "the mailbox should have a max capacity of 1 message, and any overflowing message should be discarded".

最简单的设置方法是什么?

What is the easiest way to set this up?

我尝试将以下内容放入(Play框架的) application.conf

I have tried putting the following in (Play Framework's) application.conf:

akka.actor.default-mailbox {
    mailbox-type = "akka.dispatch.BoundedMailbox"
    mailbox-capacity = 1
}

但是它不起作用:演员的邮箱在忙时仍然堆积邮件,并在可用时对其进行处理。演员没有给出 application.conf 的内容,或者上面的配置不正确。

But it doesn't work: the actor's mailbox still piles up messages when busy, and processes each of them when available. Either the actor does not give a damn about the contents of application.conf, or the above config is incorrect.

有任何想法吗?

推荐答案

如果像我一样,您想要一个最大容量为1的邮箱并丢弃溢出的邮件,我建议使用 java.util.Timer 而不是Akka。

If like me you want a mailbox with a max capacity of 1, and discarding overflowing messages, I recommend using java.util.Timer instead of Akka.

这是我在Scala程序中写的:

This is what I wrote in my Scala program:

MyTask.scala:

object MyTask extends TimerTask {
  var isRunning = false;

  def run() {
    if (!isRunning) {
      isRunning = true

      [...]

      isRunning = false
    }
  }
}

执行0ms之后执行任务,每秒重复一次:

Executing the task after 0ms, repeating every second:

new Timer().schedule(MyTask, 0, 1000)

这篇关于简单的Akka邮箱配置可丢弃溢出的邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆