I need to use RabbitMQ for decreasing api overload (900 requests in 10 seconds). But my impl seems a little bit strange to me, i want to know that i am on right path or not.
So client request the rest api, then controller sent to the queue and consumer send to service.
Controller:
@PostMapping("/login")
public LoginResponse login(@Valid @RequestBody LoginRequest loginRequest ) {
return (LoginResponse) rabbitTemplate.convertSendAndReceive(LOGIN_EXCHANGE, LOGIN_ROUTING_KEY, loginRequest);
}
Listener:
@RabbitListener(queues = RabbitConfig.LOGIN_QUEUE)
public LoginResponse listener(LoginRequest loginRequest ) { return userService.login(loginRequest); }
There are 2 oveloaded apis (login & check). My impl is that 1 queue, 1 direct exchange, 1 binding and 20 consumers for each. Is it good for this case?
I would like to know your opinion and suggestion about code impl and queue logic.
CodePudding user response:
