首页 > 解决方案 > 斯卡拉阿卡 | 如何在集群中使用 allButSelf 属性?

问题描述

基于集群的 Akka 文档,我想向集群中 我自己之外的所有节点发布一条广泛的消息。目前它也总是向我发送广泛的信息。

val mediator = DistributedPubSub(context.system).mediator
mediator ! Subscribe("content", self)       // subscribe to the topic named "content"
mediator ! Publish("content", "msg")        // sends the msg out Broad to all nodes including myself

如何准确设置文档属性“allButSelf”?

https://doc.akka.io/docs/akka/current/distributed-pub-sub.html

标签: scalaakka

解决方案


你想做

mediator ! DistributedPubSubMediator.Put(testActor)
mediator ! DistributedPubSubMediator.SendToAll(path, msg, allButSelf=false) // it is false by default

请参阅此处的示例https://github.com/akka/akka/blob/0e4d41ad33dbeb00b598cb75b4d29899371bdc8c/akka-cluster-tools/src/test/scala/akka/cluster/pubsub/DistributedPubSubMediatorRouterSpec.scala#L56


推荐阅读