reactivedb没有使用application/stream+json获取最新记录

4zcjmb1e  于 2021-07-16  发布在  Java
关注(0)|答案(0)|浏览(276)

我正在尝试使用React式mongodb来获取数据流 application/stream+json .
控制器:

  1. @GetMapping(value = "/findAll", produces = MediaType.APPLICATION_STREAM_JSON_VALUE)
  2. public Flux<Author> findAll() {
  3. Flux<Author> flux = repository.findAll();
  4. return flux.delayElements(Duration.ofMillis(500));
  5. }
  6. @GetMapping("/insertAuthor")
  7. public Flux<Author> insertAuthor() {
  8. Author author= new Author("Some Author name", "Book name", new Date(), "A");
  9. Author author1 = new Author("Some other Author name", "Another Book name", new Date(), "A");
  10. List<Author> list = new ArrayList<Author>();
  11. list.add(author);
  12. list.add(author1);
  13. Flux<Author> flux = repository.saveAll(list);
  14. flux.subscribe();
  15. return flux;
  16. }

因此,在插入一些作者之后,我们可以在浏览器上以500毫秒的延迟获取数据。但是假设我们已经插入了100个作者并调用findall endpoint,这将花费大约50秒在浏览器上显示所有作者。如果我再插入几个author,findall将不会显示它,尽管它仍在处理现有记录。
当数据流显示在浏览器上时,是否有任何方法可以从被动mongo存储库中获取最近插入的记录。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题