2

Let's assume we have two Akka Stream flows, each running on its own JVM.

// A reactive streams publisher running on JVM 1:
val stringPublisher: Publisher[String] = Source(() => "Lorem Ipsum".split("\\s").iterator).runWith(Sink.publisher[String])

// A reactive streams subscriber running on JVM 2:
def subscriber: Subscriber[String] = Sink.foreach[String](println(_)).runWith(Source.subscriber[String])

// Subscribe the second stream to the first stream
stringPublisher.subscribe(subscriber)

This example runs fine on one JVM, but how can I subscribe to a publisher running on a different JVM?

Do I have to use messaging/queueing middleware or can I use the reactive streams API to connect the two together?

Ruurtjan Pul
  • 1,197
  • 1
  • 10
  • 21
  • on first sight, i would say you will need some messaging or RPC, since each JVM runs on its own sandbox – Nikos M. Mar 06 '15 at 15:14
  • Good question... I'm also reasoning about "distributed reactive streams". The underlying mechansim is Akka, and Akka scales out to different machines. But I'm not sure if Akka-Stream supports this "out-of-the-box"... – Peti Apr 19 '15 at 15:53

1 Answers1

3

The reactive-streams spec does not speak about distributed (crossing network) streams, and none of the current implementations of it (Akka Streams as an example) implement streams that cross network boundaries. It's a bit tricky to do (but can be done and possibly will be) as it requires transparent re-delivery in case of message loss.

Short answer: you (currently) can't. However since Akka HTTP is stream based and applies back-pressure via TCP you can connect streams via stream based TCP or HTTP and the back-pressure will work as expected.

Konrad 'ktoso' Malawski
  • 13,102
  • 3
  • 47
  • 52