我有一个BE服务A,它正在使用Feign客户端向微服务B发送Rest JSON消息。
@FeignClient(name = "mail-service")
@LoadBalancerClient(name = "mail-service", configuration = LoadBalancerConfiguration.class)
public interface EmailClient {
@RequestMapping(method = RequestMethod.POST, value = "/engine/emails/register")
void setUserRegistration(CreateUserDTO createUserDTO);
}
Rest Endpoint:
@RestController
@RequestMapping("/emails")
public class EmailController {
@RequestMapping(method = RequestMethod.POST, value = "/register", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> register(@Valid @RequestBody CreateUserDTO createUserDTO) {
emailRestService.processCreateUserMessage(createUserDTO);
// Implementation of service to send mail to AWS SES
return new ResponseEntity<>(HttpStatus.OK);
}
}
Rest Endpoint正在向AWS Ses mail或其他邮件提供商发送邮件。
问题是Feign的第一次调用可能需要5秒甚至更多。我需要把它变成异步的,以便FE客户端不等待邮件的发送。
我怎样才能使Feign的Rest调用成为异步的,从而不需要等待http响应OK?有没有一些更好的解决方案来实现这一点呢?
StackOverflow:spring - Send Async message to microservice - Stack Overflow