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?
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.
来源:https://stackoverflow.com/questions/28901599/how-do-i-subscribe-to-a-reactive-streams-implementation-running-on-a-different-j