记一下用feignclient进行服务间调用的问题

业务上需要用到模块间调用,然后由于鉴权原因不能直接访问,

去网上搜了方法,配置拦截,传递token,问题解决

 

@Configuration
public class FeignRequestInterceptor implements RequestInterceptor {
        private static final String AUTHORIZATION_HEADER = "authorization";

    @Override
        public void apply(RequestTemplate template) {
            Map headMap=getHeaders(getHttpServletRequest());
            template.header(AUTHORIZATION_HEADER, headMap.get(AUTHORIZATION_HEADER));
        }
        private HttpServletRequest getHttpServletRequest() {
            try {
                return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            } catch (Exception e) {
                return null;
            }
        }
        private Map getHeaders(HttpServletRequest request) {
            Map map = new LinkedHashMap<>();
            Enumeration enumeration = request.getHeaderNames();
            while (enumeration.hasMoreElements()) {
                String key = enumeration.nextElement();
                String value = request.getHeader(key);
                map.put(key, value);
            }
            return map;
        }

}

然后碰上了 read time out的错误

再加上下面这个,问题解决

feign:
  client:
    config:
      default:
        connectTimeout: 50000
        readTimeout: 50000
        loggerLevel: basic

 

你可能感兴趣的:(Java)