简体   繁体   English

如何编辑Akka application.conf

[英]how to edit akka application.conf

I am searching for days for a tutorial on how to write a custom application.conf. 我正在寻找有关如何编写自定义application.conf的教程的日子。 I read the akka-documentation and tried the Pi example. 我阅读了akka文档,并尝试了Pi示例。

But now I want to run my own configuration. 但是现在我想运行自己的配置。 My goal is to override the router type and change the number of routees. 我的目标是覆盖路由器类型并更改路由数量。 Here is my code: 这是我的代码:

package org.sddb.playground

import akka.actor._
import com.typesafe.config.ConfigFactory
import akka.routing.RoundRobinRouter

object Test extends App {

  case object Log
  case object Ask

  class Tester extends Actor with ActorLogging {

    def receive = {
      case Log => logging
      case Ask => answer
    }

    def logging {
      log error "error"
      log warning "warning"
      log debug "debug"
    }

    def answer {
      log info "somebody asked"
    }
  }
  val config = ConfigFactory.load
  val system = ActorSystem("TestSystem", config.getConfig("test"))
  val tester = system.actorOf(Props[Tester].withRouter(RoundRobinRouter(2)))
  tester ! Log
  tester ! Ask
  tester ! PoisonPill
  system.shutdown
}

My application.config looks that way: 我的application.config看起来是这样的:

test {
  akka.loglevel = DEBUG
  deployment {
    /tester {
      router = broadcast
      nr-of-instances = 5
    }
  }
}

The loging on debug level is ok but there is neither a broadcast nor are there 5 instances. 可以进行调试级别的登录,但是既没有广播,也没有5个实例。 Where is my misstake? 我的错在哪里?

That is because you are creating a RoundRobinRouter(2) explicitly. 那是因为您正在显式创建RoundRobinRouter(2)。 You have to pass FromConfig() instead and also you have to pass "tester" as name. 您必须改为传递FromConfig()并且还必须传递“ tester”作为名称。

edit: 编辑:

Your config section is wrong, it should be: 您的配置部分错误,应该是:

test {
  akka.loglevel = DEBUG
  akka.actor.deployment {
    /tester {
      router = broadcast
      nr-of-instances = 5
    }
  }
}

But you could also just do 但是你也可以做

akka {
  loglevel = DEBUG
  actor {
    deployment {
      /tester {
        router = broadcast
        nr-of-instances = 5
      }
    }
  }
}

then you don't have to pass in the config manually. 那么您不必手动传递配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM