修改security服务feign调用失败的重试规则
This commit is contained in:
@ -22,7 +22,7 @@ public interface UserCenterClient {
|
|||||||
* @param fileId
|
* @param fileId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestMapping(method = RequestMethod.GET, value = "v1/userinfo/get")
|
@RequestMapping(method = RequestMethod.GET, value = "v1/userinfo/get1")
|
||||||
SecurityUser getUserInfo();
|
SecurityUser getUserInfo();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package com.chinaunicom.mall.ebtp.cloud.security.starter.config;
|
|||||||
|
|
||||||
import static feign.FeignException.errorStatus;
|
import static feign.FeignException.errorStatus;
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
@ -34,6 +33,11 @@ public class FeignClientConfiguration {
|
|||||||
int status = response.status();
|
int status = response.status();
|
||||||
|
|
||||||
if (status >= 400 && status <= 500) {// 客户端异常,启用feign的重试机制
|
if (status >= 400 && status <= 500) {// 客户端异常,启用feign的重试机制
|
||||||
|
try {
|
||||||
|
Thread.sleep(3000);// 设定重试延时
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
return new RetryableException(response.status(), exception.getMessage(),
|
return new RetryableException(response.status(), exception.getMessage(),
|
||||||
response.request().httpMethod(), exception, retryAfter(), response.request());
|
response.request().httpMethod(), exception, retryAfter(), response.request());
|
||||||
}
|
}
|
||||||
@ -42,14 +46,10 @@ public class FeignClientConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 延迟 n 秒后重试
|
* @return 请求重试
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
private Date retryAfter() {
|
private Date retryAfter() {
|
||||||
Calendar cal = GregorianCalendar.getInstance();
|
return GregorianCalendar.getInstance().getTime();
|
||||||
|
|
||||||
return cal.getTime();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -102,10 +102,7 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
*/
|
*/
|
||||||
private Authentication getAuthentication(final String token, final String currentRoleCode) {
|
private Authentication getAuthentication(final String token, final String currentRoleCode) {
|
||||||
SecurityUser securityUser = client.getUserInfo();
|
SecurityUser securityUser = client.getUserInfo();
|
||||||
|
|
||||||
log.info("TokenAuthenticationFilter: token [{}]", token);
|
|
||||||
log.info("TokenAuthenticationFilter: userid [{}]", securityUser.getUserId());
|
|
||||||
|
|
||||||
if (Objects.isNull(securityUser)) {// 对象为空, 则说明网络异常feign已熔断
|
if (Objects.isNull(securityUser)) {// 对象为空, 则说明网络异常feign已熔断
|
||||||
throw new RemoteTimeoutException("90500");
|
throw new RemoteTimeoutException("90500");
|
||||||
}
|
}
|
||||||
@ -114,6 +111,9 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
throw new AccessDeniedException("90403");
|
throw new AccessDeniedException("90403");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.info("TokenAuthenticationFilter: token [{}]", token);
|
||||||
|
log.info("TokenAuthenticationFilter: userid [{}]", securityUser.getUserId());
|
||||||
|
|
||||||
// 根据当前角色设定权限列表
|
// 根据当前角色设定权限列表
|
||||||
List<RoleCodeAuthority> authorities = Optional.ofNullable(securityUser.getAuthorityList()).map(list -> {
|
List<RoleCodeAuthority> authorities = Optional.ofNullable(securityUser.getAuthorityList()).map(list -> {
|
||||||
return list.stream().filter(auth -> StringUtils.equals(auth.getRoleCode(), currentRoleCode))
|
return list.stream().filter(auth -> StringUtils.equals(auth.getRoleCode(), currentRoleCode))
|
||||||
|
Reference in New Issue
Block a user