0

我正在尝试在我们的应用程序中使用 akka pub-sub。我有一个游戏应用程序,它是 akka 集群的一部分。我想使用 akka cluster-client 使该应用程序侦听/订阅主题,并且消息将从其他应用程序发布。

集群/订阅者端代码 [在 Play 应用程序中]

class MyRealtimeActor extends Actor {
    import DistributedPubSubMediator.{ Subscribe, SubscribeAck }

    def receive = {
        case SubscribeAck(Subscribe("metrics", _)) => {
        Logger.info("SUBSCRIBED TO MESSAGES")
        context become ready
        }
    }

    def ready: Actor.Receive = {
        case m => {
        Logger.info("RECEIVED MESSAGE " + m)
        }
    }

}

我在 Global 中像这样实例化

val cluster: ActorSystem = ActorSystem("ClusterSystem")
val metricsActor = Global.cluster.actorOf(Props(new MyRealtimeActor), "metricsActor")
ClusterReceptionistExtension(cluster).registerSubscriber("metrics", metricsActor)

并且conf文件具有以下内容

akka {
    actor {
        provider = "akka.cluster.ClusterActorRefProvider"
        extensions = ["akka.contrib.pattern.DistributedPubSubExtension",
        "akka.contrib.pattern.ClusterReceptionistExtension"]
    }
    remote {
        log-remote-lifecycle-events = off
        netty.tcp {
        hostname = "127.0.0.1"
        port = 2551
    }
}

cluster {
    seed-nodes = [
    "akka.tcp://ClusterSystem@127.0.0.1:2551"
    ]

    auto-down-unreachable-after = 10s
}

何时启动播放应用程序我可以看到以下日志

 [INFO] [11/06/2013 17:48:42.926] [ClusterSystem-akka.actor.default-dispatcher-3]     [Cluster(akka://ClusterSystem)] Cluster Node [akka.tcp://ClusterSystem@127.0.0.1:2551] - Node [akka.tcp://ClusterSystem@127.0.0.1:2551] is JOINING, roles []
 [INFO] [11/06/2013 17:48:42.942] [ClusterSystem-akka.actor.default-dispatcher-5] [akka://ClusterSystem/deadLetters] Message [akka.contrib.pattern.DistributedPubSubMediator$SubscribeAck] from Actor[akka://ClusterSystem/user/distributedPubSubMediator#1608017981] to Actor[akka://ClusterSystem/deadLetters] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.

想知道为什么演员没有正确订阅?我期待它打印订阅消息

4

1 回答 1

2

问题是,SubscribeAck 被发送给订阅消息的发送者,而不是订阅消息中的参与者。要将 SubscribeAck 发送给 metricsActor,它必须发送 Subscribe 本身,并直接发送给中介。

接待员由集群客户端代码使用,您不应该使用它来正常订阅您的演员。

于 2013-11-07T13:54:07.880 回答