简体   繁体   English

如何使用Spring data-mongodb-reactive从受限制的集合中流式传输

[英]How to stream from a capped collection with Spring data-mongodb-reactive

I'm trying to use this interesting repository method : 我正在尝试使用这个有趣的存储库方法:

@Tailable
Flux<Movie> findWithTailableCursorBy();

by expose it in a controller, to stream new saved docs in a capped collection: 通过将其公开在控制器中,以将新保存的文档流式传输到有上限的集合中:

This is a DataAppInitializr : 这是一个DataAppInitializr:

@EventListener(ApplicationReadyEvent.class)
public void run(ApplicationReadyEvent evt) {

      operations.collectionExists(Movie.class)
                  .flatMap(exists -> exists ? operations.dropCollection(Movie.class) : Mono.just(exists))
                  .then(operations.createCollection(Movie.class, CollectionOptions.empty()
                             .size(256 * 256)
                             .maxDocuments(10)
                             .capped()))
                  .thenMany(operations.insertAll(Flux.just("Jeyda", "Kaf Efrit").map(title-> new Movie(title)).collectList()))
                  .subscribe();
}

This is the controller method : 这是控制器方法:

@GetMapping(value = "/tail", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
Flux<Movie> allTail() {
    return movieRepository.findWithTailableCursorBy();
}

I got no exception, I'm just getting a white page in the browser and no stream of new docs. 我也不例外,浏览器中只有一个白页,没有新文档流。 Am I missing a step ? 我错过了一步吗?

Thank you in advance! 先感谢您!

There are two aspects in your question that do not fit what you want to achieve: 您的问题有两个方面与您要实现的目标不符:

  1. Your code contains blocking bits: block() . 您的代码包含阻塞位: block() Do not call .block() in initializers and event handlers during startup or when receiving events triggered by reactive infrastructure. 在启动过程中或接收到反应式基础结构触发的事件时,请勿在初始化程序和事件处理程序中调用.block() Blocking is the easiest way to disrupt any functionality and makes your application defunct. 阻塞是破坏任何功能并使应用程序失效的最简单方法。
  2. Browsers aren't the ideal tool to consume streams with a page view. 浏览器不是使用页面视图使用流的理想工具。 Rather use cURL . 而是使用cURL

Besides that, you seem to have a mismatch between Flux<Person> and Flux<Movie> . 除此之外,您似乎在Flux<Person>Flux<Movie>之间不匹配。

The issue comes from SecurityWebFilterChain from the spring-security-webflux. 问题来自spring-security-webflux的SecurityWebFilterChain。 I should contact concerned people to notify them. 我应该联系有关人员以通知他们。 Thank you for your support! 谢谢您的支持!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM