springboot搭建微服务架构,采用Feign进行服务之间的远程调用,配置fallback实现服务降级,配置服务降级配置,主服务监听调用服务返回的内容,判断继续执行还是抛出异常。从而保证逻辑一致性。
1.配置服务调用
@FeignClient(name = "user-service",fallback = UserClientFallback.class)
public interface UserClient {
@PostMapping("/user/authPayStatusUpdateRemote")
CommonResponse authPayStatusUpdate(@RequestBody CreateUserRequest reques);
@PostMapping("/user/userVIPUpdateRemote")
CommonResponse userVIPUpdateRemote(@RequestBody CreateVIPRequest reques);
@PostMapping("/user/userCompanyAuthUpdateRemote")
CommonResponse userCompanyAuthUpdateRemote(@RequestBody CreateVIPRequest reques);
@PostMapping("/user/userCompanyRenewAuthUpdateRemote")
CommonResponse userCompanyRenewAuthUpdateRemote(@RequestBody CreateVIPRequest reques);
@PostMapping("/user/userInfoRemoteQuery")
CommonResponse userInfoRemoteQuery(@RequestBody UserRemoteRequest request);
@PostMapping("/user/queryUserRecommendRemot")
CommonResponse queryUserRecommendRemot(@RequestBody UserRemoteRequest reques);
@PostMapping("/user/addUserwalletRemot")
CommonResponse addUserwalletRemot(@RequestBody UserRemoteRequest reques);
@PostMapping("/user/queryUserUidRemote")
CommonResponse queryUserUidRemote(@RequestBody UserRemoteRequest request);
@Component
static class UserClientFallback implements UserClient {
@Override
public CommonResponse authPayStatusUpdate(CreateUserRequest reques){
return null;
}
@Override
public CommonResponse userVIPUpdateRemote(CreateVIPRequest reques){
return null;
}
@Override
public CommonResponse userCompanyAuthUpdateRemote(CreateVIPRequest reques){
return null;
}
}
}