【问题标题】:FeignException ServiceUnavailable: Load balancer does not contain an instance for the service match-result-serviceFeignException ServiceUnavailable:负载均衡器不包含服务 match-result-service 的实例
【发布时间】:2021-04-03 04:23:55
【问题描述】:

我不明白,也找不到任何关于如何修复主题异常的解释。

这是我使用的主要代码:

尤里卡服务器

应用:

...
@SpringBootApplication
@EnableEurekaServer
public class BbSimApplication {

    public static void main(String[] args) {
        SpringApplication.run(BbSimApplication.class, args);
    }
}

application.yml:

server.port : 8088

spring: 
    application: 
        name : bbsim-discovery-server

eureka:
    server:
        evictionIntervalTimerInMs: 3000
        response-cache-update-interval-ms: 3000
        wait-time-in-ms-when-sync-empty: 0
        peer-node-read-timeout-ms : 10000
    client:
        registerWithEureka: false
        fetchRegistry: false
        service-url: 
            defaultZone: http://localhost:${server.port}/eureka

控制器类:

@RestController
public class WebController {

    @Autowired private WebService webService;

    @GetMapping("/matchresultbyids")
    public MatchStats matchResult(@RequestParam Long homeId, @RequestParam Long awayId){

        return webService.matchResult(homeId, awayId);
    }
}

经理服务

应用:

@SpringBootApplication
@EnableFeignClients
@EnableDiscoveryClient
public class BBSimManagerServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(BBSimManagerServiceApplication.class, args);
    }
}

application.yaml:

server.port: 9903

spring:
    application.name: bbsim-manager-service
eureka:
    client:
        serviceUrl:
            defaultZone: ${EUREKA_URI:http://localhost:8088/eureka}
            registryFetchIntervalSeconds: 1
            # register-with-eureka: true
            # fetch-registry: true
    instance:
        leaseRenewalIntervalInSeconds: 1

客户端界面:

@FeignClient("match-result-service")
public interface MatchResultClient {

    @GetMapping("/matchresultbyids")
    MatchStats getMatchResult();
}

控制器类:

@RestController
public class BbsimManagerController {
    
    @Autowired
    MatchResultClient matchStatsClient;
 
    @GetMapping("/matchresultbyids")
    public MatchStats matchResult(){

        return matchStatsClient.getMatchResult();
    }
}

匹配结果服务

应用:

@SpringBootApplication
@EnableDiscoveryClient
public class MatchResultServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(MatchResultServiceApplication.class, args);
    }

}

application.yml:

server.port: 9901

spring:
    application:
        name: match-result-service
eureka:
    client:
        serviceUrl:
            defaultZone: http://localhost:8088/eureka/
            registryFetchIntervalSeconds: 1
            instance:
                leaseRenewalIntervalInSeconds: 1

控制器:

@RestController
public class WebController {

    @Autowired private WebService webService;

    @GetMapping("/matchresultbyids")
    public MatchStats matchResult(){

        return webService.matchResult();
    }
}

当我尝试执行时:

http://localhost:9903/matchresultbyids

我得到了例外:

o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is feign.FeignException$ServiceUnavailable: [503] during [GET] to [http://match-result-service/matchresultbyids?homeId=0&awayId=1] [MatchResultClient#getMatchResult()]: [Load balancer does not contain an instance for the service match-result-service]] with root cause

feign.FeignException$ServiceUnavailable: [503] during [GET] to [http://match-result-service/matchresultbyids?homeId=0&awayId=1] [MatchResultClient#getMatchResult()]: [Load balancer does not contain an instance for the service match-result-service]

你能告诉我哪里出了问题以及如何解决它吗?

谢谢大家。

【问题讨论】:

  • 你尝试去localhost:8088,确定match-result-service实例在Eureka上注册成功了吗?
  • @NguaCon 请查看添加的图片。
  • 您是否尝试直接致电http://localhost:9901/matchresultbyids 以确保可用?错误表示该服务不可用。
  • @dushkin 如果问题仍然存在,请创建一个 GitHub 问题,并提供一个指向重现问题的示例的链接 - 将尝试调试它。
  • 问题解决了吗

标签: spring spring-boot spring-cloud spring-cloud-feign


【解决方案1】:

可能与 OpenFeign bug 有关。您可以尝试将其升级到版本 >= v3.0.6。 如果你使用 spring-cloud-dependencies 版本 >= v2020.0.5 应该也可以。

【讨论】:

    猜你喜欢
    • 2021-08-29
    • 2021-08-18
    • 2018-12-17
    • 2013-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多