✨ 添加新特性。feign fallback 注入异常堆栈

This commit is contained in:
冷冷 committed 2018-09-01 13:08:41 +08:00
1 parent fd91f630a6
commit 5c8ecf4ea6
4 files changed
+48 -5

No files matched your search

@@ -20,7 +20,7 @@
package com.pig4cloud.pigx.admin.api.feign;
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
import com.pig4cloud.pigx.admin.api.feign.fallback.RemoteUserServiceFallbackImpl;
import com.pig4cloud.pigx.admin.api.feign.factory.RemoteUserServiceFallbackFactory;
import com.pig4cloud.pigx.common.core.constant.ServiceNameConstant;
import com.pig4cloud.pigx.common.core.util.R;
import org.springframework.cloud.openfeign.FeignClient;
@@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.RequestHeader;
* @author lengleng
* @date 2018/6/22
*/
@FeignClient(value = ServiceNameConstant.UMPS_SERVICE, fallback = RemoteUserServiceFallbackImpl.class)
@FeignClient(value = ServiceNameConstant.UMPS_SERVICE, fallbackFactory = RemoteUserServiceFallbackFactory.class)
public interface RemoteUserService {
/**
* 通过用户名查询用户、角色信息
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.admin.api.feign.factory;
import com.pig4cloud.pigx.admin.api.feign.RemoteUserService;
import com.pig4cloud.pigx.admin.api.feign.fallback.RemoteUserServiceFallbackImpl;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
/**
* @author lengleng
* @date 2018/9/1
*/
@Component
public class RemoteUserServiceFallbackFactory implements FallbackFactory<RemoteUserService> {
@Override
public RemoteUserService create(Throwable throwable) {
RemoteUserServiceFallbackImpl remoteUserServiceFallback = new RemoteUserServiceFallbackImpl();
remoteUserServiceFallback.setCause(throwable);
return remoteUserServiceFallback;
}
}
@@ -22,6 +22,7 @@ package com.pig4cloud.pigx.admin.api.feign.fallback;
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
import com.pig4cloud.pigx.admin.api.feign.RemoteUserService;
import com.pig4cloud.pigx.common.core.util.R;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -32,6 +33,9 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
public class RemoteUserServiceFallbackImpl implements RemoteUserService {
@Setter
private Throwable cause;
/**
* 通过用户名查询用户、角色信息
*
@@ -41,7 +45,7 @@ public class RemoteUserServiceFallbackImpl implements RemoteUserService {
*/
@Override
public R<UserInfo> info(String username, String from) {
log.error("feign 查询用户信息失败:{}", username);
log.error("feign 查询用户信息失败:{}", username, cause);
return null;
}
@@ -53,7 +57,7 @@ public class RemoteUserServiceFallbackImpl implements RemoteUserService {
*/
@Override
public R<UserInfo> social(String inStr) {
log.error("feign 查询用户信息失败:{}", inStr);
log.error("feign 查询用户信息失败:{}", inStr, cause);
return null;
}
}
@@ -1,3 +1,4 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.pig4cloud.pigx.admin.api.feign.fallback.RemoteUserServiceFallbackImpl,\
com.pig4cloud.pigx.admin.api.feign.fallback.RemoteLogServiceFallbackImpl\
com.pig4cloud.pigx.admin.api.feign.fallback.RemoteLogServiceFallbackImpl,\
com.pig4cloud.pigx.admin.api.feign.factory.RemoteUserServiceFallbackFactory