2016-09-01 18 views
0

当我尝试为配置文件中的池(RoundRobinPool)的路由设置有界邮箱时,Akka忽略邮箱配置。无法为RoundRobinPool的管理员配置有限邮箱

下面是我的配置使用:

bounded-mailbox { 
    mailbox-type = "akka.dispatch.BoundedMailbox" 
    mailbox-capacity = 1 
    mailbox-push-timeout-time = 1s 
} 

akka.actor.deployment { 
    /singletestactor { 
     mailbox = bounded-mailbox 
} 

    /groupedtestactor { 
     mailbox = bounded-mailbox 

     router = round-robin-pool 
     nr-of-instances = 5 
    } 
} 

这里是测试代码:

object MailboxTest { 
    def main(args: Array[String]): Unit = { 
    val actorSystem = ActorSystem() 
    val singleTestActor = actorSystem.actorOf(Props[TestActor], "singletestactor") 
    for (i <- 1 to 10) { 
     singleTestActor ! Hello(i) 
    } 


    val groupedTestActor = actorSystem.actorOf(Props[TestActor].withRouter(FromConfig, "groupedtestactor") 
    for (i <- 1 to 1000) { 
     groupedTestActor ! Hello(i) 
    } 
    } 
} 

class TestActor extends Actor { 
    def receive = { 
    case Hello(i) => { 
     println(s"Hello($i) - begin!") 
     Thread.sleep(10000) 
     println(s"Hello($i) - end!") 
    } 
    } 
} 

case class Hello(i: Int) 

难道我做错了什么,或者没有办法定义邮箱routees?

回答

0

您需要在application.conf中添加mailbox.requirements配置;

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

然后需要像这样延伸TestActor;

class TestActor extends Actor with RequiresMessageQueue[BoundedMessageQueueSemantics] 

见邮箱配置文件here

我也创建了这样的循环池;

val groupedTestActor = actorSystem.actorOf(FromConfig.props(Props[TestActor]), "groupedtestactor") 
+0

但是如果我想将其他或自定义邮箱分配给该演员,我可以通过配置更改来做到这一点吗? – mehmetgunturkun

+0

是的,你可以;检查这个链接; http://letitcrash.com/post/54099834993/22-spotlight-mailbox-requirements“如果actor在部署中配置了不同的邮箱,那么这将覆盖此映射。” –

+1

嗨@Fatih,这里是为路由配置邮箱的更好方式 - https://groups.google.com/forum/#!topic/akka-user/JU722c10Dqg – mehmetgunturkun

相关问题