@FeignClient всегда вызывает резервный метод даже после получения ответа - PullRequest
0 голосов
/ 08 апреля 2020

Я пытаюсь получить информацию из другого сервиса, используя FeignClient. Оба зарегистрированы в Консуле. Это мой код.

@Service
@FeignClient(name = "TESTSERVICE", fallback = TestClientImpl.class)
public interface TestClient {

    @GetMapping("/v1/api/get")
    Optional<Object> testMethod();
}
@Service
public class TestClientImpl implements TestClient {

    @Override
    public Optional<Object> testMethod() {
        return Optional.empty();
    }
}

application.yml

hystrix:
  command:
    default:
      execution:
        isolation:
          strategy: SEMAPHORE
#          thread:
#            timeoutInMilliseconds: 160000000

feign:
  hystrix:
    enabled: true
#  client:
#    config:
#      default:
#        loggerLevel: full
#        connectTimeOutMillis: 160000000
#        readTimeOutMillis: 160000000

Почему FeignClient всегда вызывает метод возврата и возвращает Optional.empty () даже после успешного получения ответа ?

сгенерированный лог

08-04-2020 12:31:11.646 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] ---> GET http://TESTSERVICE/v1/api/get HTTP/1.1
08-04-2020 12:31:11.647 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJVc2VybmFtZSIsIkFVVEgiOiJhZG1pbiIsImV4cCI6MTU4NTk5MjYxN30.TzbbUxZpmlQtHrLjJGZcKBX7fRbACmvMoQvMgts0kqpH1Bk0Ei3nbf40XFjKyuRxPEpLhOwsbAagZjK6sOAMhw
08-04-2020 12:31:11.648 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] correlationId: 1111
08-04-2020 12:31:11.648 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] ---> END HTTP (0-byte body)
08-04-2020 12:31:11.863 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] <--- HTTP/1.1 200 (213ms)
08-04-2020 12:31:11.863 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] access-control-allow-headers: Authorization, Access-Control-Allow-Origin, Content-Type
08-04-2020 12:31:11.863 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] access-control-allow-methods: POST, PUT, GET, OPTIONS, PATCH, DELETE
08-04-2020 12:31:11.864 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] access-control-allow-origin: *
08-04-2020 12:31:11.864 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] access-control-max-age: 3600
08-04-2020 12:31:11.864 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] connection: keep-alive
08-04-2020 12:31:11.864 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] content-length: 11
08-04-2020 12:31:11.864 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] content-type: text/plain;charset=UTF-8
08-04-2020 12:31:11.865 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] date: Wed, 08 Apr 2020 06:31:11 GMT
08-04-2020 12:31:11.865 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] keep-alive: timeout=60
08-04-2020 12:31:11.865 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] 
08-04-2020 12:31:11.867 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] Hello World
08-04-2020 12:31:11.867 [http-nio-8082-exec-10] DEBUG com.tt.result.openfeign.TestClient.log - [TestClient#testMethod] <--- END HTTP (11-byte body)
...