Postman發請求
網關------》A服務 攜帶JWT做認證ok
網關------》B服務 攜帶JWT做認證OK,
網關------》A服務----Feign(調用)-----》B服務 Full authentication is required to access this resource
分析:
a.因為Feign在服務之間相互調用如果需要認證,需要實現RequestInterceptor,在每次請求的時候header里面增加(token、oauthToken、Authorization),但是發現單單給header里面增加(token、oauthToken、Authorization),還是會報認證錯誤。於是把A服務請求中所有header放入RequestInterceptor實現代碼中就ok了。
之前的攔截器代碼:
改動后代碼:
b.線程隔離策略設置為信號量,默認線程
hystrix.command.default.execution.isolation.strategy=SEMAPHORE
官方文檔:
如果你需要在你的程序中使用ThreadLocal綁定變量,您需要將Hystrix的線程隔離策略設置為“信號量”或在Fegin中禁用Hystrix
# To disable Hystrix in Feign(禁用斷路器,這樣將不會走服務降級,之前想調用放返回調用失敗異常)
feign.hystrix.enabled=false
# To set thread isolation to SEMAP(設置線程隔離策略為信號量)
hystrix.command.default.execution.isolation.strategy=SEMAPHORE
微信公眾號