Spring webflux and reading from database

后端 未结 4 802
难免孤独
难免孤独 2020-12-13 06:29

Spring 5 introduces the reactive programming style for rest APIs with webflux. I\'m fairly new to it myself and was wondering wether wrapping synchronous calls to a database

4条回答
  •  醉梦人生
    2020-12-13 07:22

    Based on this blog you should rewrite your snippet in following way

    @GetMapping(value = "/v1/measurements")
    public Flux getMeasurements() {
        return Flux.defer(() -> Flux.fromIterable(repository.findByFromDateGreaterThanEqual(new Date(1486980000L))))
               .subscribeOn(Schedulers.elastic());
    }
    

提交回复
热议问题