如何订阅在不同JVM上运行的反应式流实现? [英] How do I subscribe to a reactive streams implementation running on a different JVM?
问题描述
假设我们有两个Akka Stream流,每个流都在自己的JVM上运行.
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)
此示例在一个JVM上运行良好,但是如何订阅在另一JVM上运行的发布者?
This example runs fine on one JVM, but how can I subscribe to a publisher running on a different JVM?
我必须使用消息传递/排队中间件还是可以使用反应流API将两者连接在一起?
Do I have to use messaging/queueing middleware or can I use the reactive streams API to connect the two together?
推荐答案
反应流规范不起作用有关分布式(跨网络)流的信息,目前没有实现(以Akka流为例)实现跨网络边界的流.这样做有些棘手(但是可以做到,而且可能会做到),因为在消息丢失的情况下需要透明地重新发送.
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.
简短的回答:您(当前)不能.但是,由于Akka HTTP基于流并且通过TCP施加反压,因此您可以通过
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.
这篇关于如何订阅在不同JVM上运行的反应式流实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!