代码之家  ›  专栏  ›  技术社区  ›  dushkin

FeignException ServiceUnavailable:负载平衡器不包含服务匹配结果服务的实例

  •  0
  • dushkin  · 技术社区  · 4 年前

    我不明白,也找不到任何解释,我该如何解决这个问题的例外。

    这是我使用的主要代码:

    尤里卡服务器

    应用程序:

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

    应用程序.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);
        }
    }
    

    应用程序.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();
        }
    }
    

    MatchResult服务

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

    应用程序.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();
        }
    }
    

    enter image description here

    当我尝试执行时:

    http://localhost:9903/匹配结果字节

    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]
    

    你能告诉我哪里出了问题,怎么修理吗?

    0 回复  |  直到 4 年前