可以说我有一些其他演员服务层演员常用的.例如,存储和检索域对象的注册表服务:
case class DomainObject(id: UUID)
class Registry extends akka.actor.Actor {
def receive: Receive = {
case o: DomainObject => store(o) // save or update object
case id: UUID => sender ! retrieve(id) // retrieve object and send it back
}
}
Run Code Online (Sandbox Code Playgroud)
我不想将此类注册表的实例明确传递给可能使用它的所有actor.而不是它,我希望他们能够以某种方式"找到"它.
为此我可以想到两个解决方案:
Identify消息:每个注册表用户actor都知道来自某些配置的注册表actor名称,并且能够向其发送标识消息.之后AgentIdentity被收回的消息,我们是好去:
val registryName = ... // some name
val registryId = ... // some id
var registry = _
def preStart() {
context.actorSelection(registryName) ! Identify(registryId)
}
def receive: Receive = {
case ActorIdentity(`registryId`, ref) …Run Code Online (Sandbox Code Playgroud)我正在使用Akka 2.2-RC1,我无法让Akka从application.conf加载调度程序配置:
my-dispatcher {
type = PinnedDispatcher
executor = "thread-pool-executor"
}
akka.actor.deployment {
/test {
dispatcher = my-dispatcher
}
}
Run Code Online (Sandbox Code Playgroud)
从代码中实例化时
val test = system.actorOf(Props[Test], "test")
Run Code Online (Sandbox Code Playgroud)
按日志,它仍在使用akka.actor.default-dispatcher.
当我添加.withDispatcher("my-dispatcher")到道具时,所有都正常工作并被my-dispatcher使用.但我不喜欢加入.withDispatcher(...)我所有的演员......
有谁知道哪里可能有问题?我认为actor路径可能是错误的,但是apllication.conf路由配置正常工作(除了自定义routee调度程序之外).
经过一些测试后我发现这种效果是由于使用造成的RemoteActorRefProvider.一旦我禁用它并更改为默认值
akka.actor.provider = "akka.actor.LocalActorRefProvider"
Run Code Online (Sandbox Code Playgroud)
调度程序正在配置正确配置.
我想通过远程启用Akka在其他地方查找actor调度程序的配置,或者远程refs有不同的逻辑路径?