Spring Boot应用程序中的BackPressure

时间:2018-07-12 12:49:57

标签: spring spring-restcontroller spring-rest spring-webflux

我想在我的应用程序Web服务上施加反压。因此,如果请求数量很高,请说多于N我可以通知客户。下面是我的控制器

WebFlux之前

@RequestMapping(value = "/tasks", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ResponseTaskModel> taskForUser(@RequestParam(value = "userId", required = true) String userId,              
@RequestParam(required = false) Map<String, String> userData) {
    ResponseTaskModel responseTaskModel = service.retrieveNextTaskForUser(userId.toLowerCase(), userData);
    return new ResponseEntity<ResponseTaskModel>(responseTaskModel, HttpStatus.OK);
}

WebFlux之后

@RequestMapping(value = "/tasks/v1", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Mono taskForUserV1(@RequestParam(value = "userId", required = true) String userId,
                                                     @RequestParam(required = false) Map<String, String> userData) {
    return service.taskForUserV1(userId, userData);
}

我正在调用的服务方法是对带有三个查询的db的阻塞调用,我正在使用postgres数据库。

现在我应该如何对返回的Mono对象施加反压?

0 个答案:

没有答案