首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Akka演员不接收DistributedPubSub消息

Akka演员不接收DistributedPubSub消息
EN

Stack Overflow用户
提问于 2017-02-05 15:51:19
回答 1查看 519关注 0票数 0

我试着用分布式消息使akka集群正常工作,但我被困住了。我的演员已经正确启动并订阅了主题,但是没有收到任何消息。这是代码

代码语言:javascript
复制
import akka.actor.{Actor, ActorSystem, Props}
import akka.cluster.client.ClusterClient.Publish
import akka.cluster.pubsub.DistributedPubSub
import akka.cluster.pubsub.DistributedPubSubMediator.{Subscribe, SubscribeAck}

case object DistributedMessage

object ClusterExample extends App {
  val system = ActorSystem("ClusterSystem")
  val actor = system.actorOf(Props(classOf[ClusterExample]), "clusterExample")
}

class ClusterExample extends Actor {
  private val mediator = DistributedPubSub(context.system).mediator

  mediator ! Subscribe("content", self)

  override def receive = {
    case SubscribeAck(Subscribe("content", None, `self`)) =>
      (1 to 100) foreach (_ => {
        mediator ! Publish("content", msg = DistributedMessage)
      })

    case DistributedMessage => println("received message from queue!")
  }
}

下面是配置:

代码语言:javascript
复制
akka {
  log-dead-letters = 0
  log-dead-letters-during-shutdown = on

  actor {
    provider = "akka.cluster.ClusterActorRefProvider"
    enable-additional-serialization-bindings = on
  }
  remote {
    log-remote-lifecycle-events = off
    netty.tcp {
      hostname = "127.0.0.1"
      port = 2552

      bind-hostname = "0.0.0.0"
      bind-port = 2552
    }
  }
  extensions = ["akka.cluster.pubsub.DistributedPubSub"]

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

“从队列接收消息”实际上从未被打印过。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-06 10:40:39

愚蠢的错误。因此,问题是无效的导入。这是:

代码语言:javascript
复制
import akka.cluster.client.ClusterClient.Publish

应改为:

代码语言:javascript
复制
import akka.cluster.pubsub.DistributedPubSubMediator.Publish
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42054035

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档