2017-01-20 5 views
1

簡単なマイクロサービスをEureka Serverに登録してから、Zuulプロキシをマイクロサービスに追加しようとしています。私はユーレカサーバに登録するためにマイクロサービスを手に入れました。しかし、私がZuulサービスを起動するたびに、それがEureka Serverに登録されていないことがわかります。私はmicroserviceにルーティングしようとするたびに、私は以下の例外を取得:私は、問題がどこにあるか把握することはできませんよmicroserviceSpring Cloud:Zuul throw "ロードバランサにクライアント用のサーバーがありません"

ロードバランサは、クライアントのために使用可能なサーバを持っていません。どんな助けにも大いに感謝されます

以下は、これらのコンポーネントのそれぞれのスプリングブートクラスです。

Microserviceコンポーネント

MicroserviceApplication.java

@SpringBootApplication(scanBasePackages = { "some.package.controller", "some.package.service" }) 
@EnableEurekaClient 
@EnableJpaRepositories("some.package.repository") 
@EntityScan("some.package.entity") 
public class MicroserviceApplication { 

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

} 

bootstrap.yml

server: 
    port: 8090 

info: 
    component: Core Services 

spring: 
    application: 
    name: microservice 

application.yml

eureka: 
    instance: 
    leaseRenewalIntervalInSeconds: 1 
    leaseExpirationDurationInSeconds: 2 
    client: 
    serviceUrl: 
     defaultZone: http://localhost:8761/eureka/ 
    healthcheck: 
     enabled: true 
    lease: 
     duration: 5 

#some other logging and jpa properties below 

ユーレカサーバーコンポーネント

EurekaServerApplication.java

@SpringBootApplication 
@EnableEurekaServer 
public class EurekaServerApplication { 

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

} 

bootstrap.yml

spring: 
    application: 
    name: discovery-server 

application.yml

server: 
    port: 8761 

info: 
    component: Discovery Server 

eureka: 
    client: 
    registerWithEureka: false 
    fetchRegistry: false 
    serviceUrl: 
     defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ 
    instance: 
    hostname: localhost 
    server: 
    waitTimeInMsWhenSyncEmpty: 0 

API Gatewayのコンポーネント

ZuulGatewayApplication.java

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

    @Bean 
    public ZuulGatewayPreFilter gatewayPreFilter() { 
     return new ZuulGatewayPreFilter(); 
    } 
} 

bootstrap.yml

追加

application.yml

server: 
    port: 8888 

info: 
    component: API Gateway 

eureka: 
    instance: 
    leaseRenewalIntervalInSeconds: 1 
    leaseExpirationDurationInSeconds: 2 
    client: 
    serviceUrl: 
     defaultZone: http://localhost:8761/eureka/ 

zuul: 
    routes: 
    microservice: 
     path: /microservice/** 
     serviceId: microservice 
+0

ユーレカは何を言っているのですか(ダッシュボードと '/ eureka/apps'はマイクロサービスが登録されていますか?そのような更新時間と有効期限が短くなると、実際に問題が発生する可能性があります。あなたはそれらを長くしようとしましたか? – spencergibb

+0

あなたはどのバージョンを使用していますか? – spencergibb

+0

マイクロサービスは登録されていて、Zuulアプリケーションクラスに '@ EnableEurekaClient'アノテーションを追加するだけで問題は解決しました.Zuulは登録サービスとしてユーレカダッシュボードに表示され、マイクロサービスにもプロキシしています。特定のバージョンは指定していませんが、Spring CloudバージョンのCamden.SR4に基づいています。 更新間隔と有効期限にはどのようなことをお勧めしますか? – Sayantan

答えて

4

は、この問題を解決しました。 Zuulアプリケーションは現在、Eurekaサーバーで検出可能で、要求をルーティングすることができます。

関連する問題