[英]Spring Boot Webflux reactive api
I was hoping to get some hints for a small Spring Boot Application I'm building.我希望得到一些关于我正在构建的小型 Spring Boot 应用程序的提示。
The application itself should function much like consuming a Kafka topic (or any pub/sub pattern).应用程序本身的功能应该很像使用 Kafka 主题(或任何发布/订阅模式)。 I however have no tools like Kafka available so it should all be done within the application itself.
然而,我没有像 Kafka 这样的工具可用,所以这一切都应该在应用程序本身内完成。
The application will have a RestController that should expose a “hot” stream of Events when they happen.应用程序将有一个 RestController,它应该在事件发生时公开一个“热”事件流。
@GetMapping(produces = MediaType.APPLICATION_STREAM_JSON_VALUE)
public Flux<Event> getApis() {
return …
}
The application will itself consume a stream of events from another application.应用程序本身将使用来自另一个应用程序的事件流。
Where I need some hints is - how can I treat each consumer of this API as a new subscriber - and publish event to them as I get them in?我需要一些提示的地方是 - 我如何将这个 API 的每个消费者视为新订阅者 - 并在他们进入时向他们发布事件? Implementing a full pub-sub pattern keeping track of subscribers and when they stop consuming the endpoint should of course be possible.
实现一个完整的 pub-sub 模式来跟踪订阅者以及他们何时停止使用端点当然应该是可能的。 But I'm wondering if there isn't an easier solution using some of Springs Reactive functionality.
但我想知道是否有使用某些 Springs Reactive 功能的更简单的解决方案。 The Events I get in doesn't need to be stored - just forwarded to each consumer subscribing at the moment of the event.
我进入的事件不需要存储 - 只需转发给在事件发生时订阅的每个消费者。
Thanks谢谢
Before returning your Flux<Event>
from the controller handler, make sure that you're always returning:在从控制器处理程序返回您的
Flux<Event>
之前,请确保您始终返回:
Flux.share()
on it, so that all subscribers share the same hot stream of eventsFlux.share()
,以便所有订阅者共享相同的热事件流
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.