Scala Akka|如何在集群中使用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

您想要进行

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

最新更新