akka-streams with akka-cluster

时间:2016-02-03 02:39:57

标签: scala akka akka-cluster akka-stream

My akka-streams learn-o-thon continues. I'd like to integrate my akka-streams application with akka-cluster and DistributedPubSubMediator.

Adding support for Publish is fairly straight forward, but the Subscribe part I'm having trouble with.

For reference, a subscriber is given as follows in the Typesafe sample:

class ChatClient(name: String) extends Actor {
  val mediator = DistributedPubSub(context.system).mediator
  mediator ! Subscribe("some topic", self)

  def receive = {
    case ChatClient.Message(from, text) =>
      ...process message...
  }
}

My question is, how should I integrate this actor with my flow, and how should I ensure I'm getting publish messages in the absence of stream backpressure?

I'm trying to accomplish a pubsub model where one stream may publish a message and another stream would consume it (if subscribed).

3 个答案:

答案 0 :(得分:9)

You probably want to make your Actor extend ActorPublisher. Then you can create a Source from it and integrate that into your stream.

See the docs on ActorPublisher here: http://doc.akka.io/docs/akka-stream-and-http-experimental/2.0.3/scala/stream-integrations.html

答案 1 :(得分:2)

在这个主题上有一个非常好的YouTube presentation。与集群的集成即将结束,但整个演讲内容非常丰富。

答案 2 :(得分:1)

其他答案已过时:他们建议使用ActorPublisher,自版本2.5.0以来已弃用。

对于那些对当前方法感兴趣的人,Colin Breck在他的博客中写了一篇关于整合Akka Streams和Akka演员的精彩系列。在整个系列中,Breck充实了一个以Akka Streams和普通演员开始的系统,然后整合了Akka Cluster和Akka Persistence。该系列的第一篇文章是here(分布式流处理文章位于part 3)。