在Netflix ribbon中路由时没有可用的服务器



我在spring boot 2.3.4中有以下工作代码

public Route.AsyncBuilder apply(PredicateSpec route) {
return route
.path("/api/external/**")
.filters(f -> f
.removeRequestHeader("Cookie")
.filter(loggingGatewayFilter)
.filter(oauth2GatewayFilter)
.filter(this::filter)
)
.uri("lb://external-url");
}

配置:

external-url:
ribbon:
listOfServers: "http://external01.com,http://external02.com"
NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList

当我将spring boot版本升级到2.4.2时,代码必须更改如下:

public Buildable<Route> apply(PredicateSpec route) {
return route
.path("/api/external/**")
.filters(f -> f
.removeRequestHeader("Cookie")
.filter(loggingGatewayFilter)
.filter(oauth2GatewayFilter)
.filter(this::filter)
)
.uri("lb://external-url");
}

由于netflix-ribbon在spring boot 2.4.2中被删除,我不得不添加这些依赖项。在路由中,它给出以下警告。这意味着负载均衡器没有初始化。

o.s.c.l.core.RoundRobinLoadBalancer : No servers available for service: external-url

如何解决这个问题我可以尝试将其迁移到spring负载均衡器

?升级后的依赖树:

[INFO] +- org.apache.commons:commons-lang3:jar:3.9:compile
[INFO] +- com.internetitem:logback-elasticsearch-appender:jar:1.6:compile
[INFO] | - com.fasterxml.jackson.core:jackson-core:jar:2.11.4:compile
[INFO] +- org.springframework.cloud:spring-cloud-starter-config:jar:3.0.0:compile
[INFO] | +- org.springframework.cloud:spring-cloud-starter:jar:3.0.0:compile
[INFO] | | +- org.springframework.cloud:spring-cloud-context:jar:3.0.0:compile
[INFO] | | - org.springframework.security:spring-security-rsa:jar:1.0.9.RELEASE:compile
[INFO] | +- org.springframework.cloud:spring-cloud-config-client:jar:3.0.0:compile
[INFO] | - com.fasterxml.jackson.core:jackson-databind:jar:2.11.4:compile
[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:2.4.2:compile
[INFO] | +- org.springframework:spring-aop:jar:5.3.3:compile
[INFO] | | - org.springframework:spring-beans:jar:5.3.3:compile
[INFO] | +- org.springframework.security:spring-security-config:jar:5.4.2:compile
[INFO] | | +- org.springframework.security:spring-security-core:jar:5.4.2:compile
[INFO] | | - org.springframework:spring-context:jar:5.3.3:compile
[INFO] | - org.springframework.security:spring-security-web:jar:5.4.2:compile
[INFO] | - org.springframework:spring-expression:jar:5.3.3:compile
[INFO] +- org.springframework.boot:spring-boot-starter-webflux:jar:2.4.2:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-json:jar:2.4.2:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.11.4:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.11.4:compile
[INFO] | | - com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.11.4:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-reactor-netty:jar:2.4.2:compile
[INFO] | | - io.projectreactor.netty:reactor-netty-http:jar:1.0.3:compile
[INFO] | | +- io.netty:netty-codec-http:jar:4.1.58.Final:compile
[INFO] | | | +- io.netty:netty-common:jar:4.1.58.Final:compile
[INFO] | | | +- io.netty:netty-buffer:jar:4.1.58.Final:compile
[INFO] | | | +- io.netty:netty-transport:jar:4.1.58.Final:compile
[INFO] | | | +- io.netty:netty-codec:jar:4.1.58.Final:compile
[INFO] | | | - io.netty:netty-handler:jar:4.1.58.Final:compile
[INFO] | | +- io.netty:netty-codec-http2:jar:4.1.58.Final:compile
[INFO] | | +- io.netty:netty-resolver-dns:jar:4.1.58.Final:compile
[INFO] | | | +- io.netty:netty-resolver:jar:4.1.58.Final:compile
[INFO] | | | - io.netty:netty-codec-dns:jar:4.1.58.Final:compile
[INFO] | | +- io.netty:netty-resolver-dns-native-macos:jar:osx-x86_64:4.1.58.Final:compile
[INFO] | | | - io.netty:netty-transport-native-unix-common:jar:4.1.58.Final:compile
[INFO] | | +- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.58.Final:compile
[INFO] | | - io.projectreactor.netty:reactor-netty-core:jar:1.0.3:compile
[INFO] | | - io.netty:netty-handler-proxy:jar:4.1.58.Final:compile
[INFO] | | - io.netty:netty-codec-socks:jar:4.1.58.Final:compile
[INFO] | +- org.springframework:spring-web:jar:5.3.3:compile
[INFO] | - org.springframework:spring-webflux:jar:5.3.3:compile
[INFO] +- org.springframework.cloud:spring-cloud-starter-gateway:jar:3.0.0:compile
[INFO] | - org.springframework.cloud:spring-cloud-gateway-server:jar:3.0.0:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-validation:jar:2.4.2:compile
[INFO] | | +- org.glassfish:jakarta.el:jar:3.0.3:compile
[INFO] | | - org.hibernate.validator:hibernate-validator:jar:6.1.7.Final:compile
[INFO] | | +- jakarta.validation:jakarta.validation-api:jar:2.0.2:compile
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.4.1.Final:compile
[INFO] | | - com.fasterxml:classmate:jar:1.5.1:compile
[INFO] | - io.projectreactor.addons:reactor-extra:jar:3.4.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:2.4.2:compile
[INFO] | +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:2.4.2:compile
[INFO] | | - org.springframework.boot:spring-boot-actuator:jar:2.4.2:compile
[INFO] | - io.micrometer:micrometer-core:jar:1.6.3:compile
[INFO] | +- org.hdrhistogram:HdrHistogram:jar:2.1.12:compile
[INFO] | - org.latencyutils:LatencyUtils:jar:2.0.3:runtime
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.13:compile
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.4.14:compile
[INFO] | - commons-codec:commons-codec:jar:1.15:compile
[INFO] +- org.projectlombok:lombok:jar:1.18.16:compile (optional)
[INFO] +- org.springframework.cloud:spring-cloud-security:jar:2.2.2.RELEASE:compile
[INFO] | +- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] | - javax.xml.bind:jaxb-api:jar:2.3.1:compile
[INFO] +- org.springframework.cloud:spring-cloud-starter-openfeign:jar:3.0.0:compile
[INFO] | +- org.springframework.cloud:spring-cloud-commons:jar:3.0.0:compile
[INFO] | | - org.springframework.security:spring-security-crypto:jar:5.4.2:compile
[INFO] | +- io.github.openfeign:feign-core:jar:10.10.1:compile
[INFO] | - io.github.openfeign:feign-slf4j:jar:10.10.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-cache:jar:2.4.2:compile
[INFO] | - org.springframework:spring-context-support:jar:5.3.3:compile
[INFO] +- com.github.ben-manes.caffeine:caffeine:jar:2.8.8:compile
[INFO] | +- org.checkerframework:checker-qual:jar:3.8.0:compile
[INFO] | - com.google.errorprone:error_prone_annotations:jar:2.4.0:compile
[INFO] +- org.springframework.cloud:spring-cloud-starter-bootstrap:jar:3.0.0:compile
[INFO] +- org.springframework.cloud:spring-cloud-starter-netflix-ribbon:jar:2.2.3.RELEASE:compile
[INFO] | +- org.springframework.cloud:spring-cloud-netflix-ribbon:jar:2.2.3.RELEASE:compile
[INFO] | | - org.springframework.cloud:spring-cloud-netflix-archaius:jar:2.2.3.RELEASE:compile
[INFO] | +- org.springframework.cloud:spring-cloud-starter-netflix-archaius:jar:2.2.3.RELEASE:compile
[INFO] | | +- com.netflix.archaius:archaius-core:jar:0.7.6:compile
[INFO] | | - commons-configuration:commons-configuration:jar:1.8:compile
[INFO] | +- com.netflix.ribbon:ribbon:jar:2.3.0:compile
[INFO] | | +- com.netflix.ribbon:ribbon-transport:jar:2.3.0:runtime
[INFO] | | | +- io.reactivex:rxnetty-contexts:jar:0.4.9:runtime
[INFO] | | | - io.reactivex:rxnetty-servo:jar:0.4.9:runtime
[INFO] | | +- com.netflix.hystrix:hystrix-core:jar:1.4.3:runtime
[INFO] | | +- javax.inject:javax.inject:jar:1:runtime
[INFO] | | - io.reactivex:rxnetty:jar:0.4.9:runtime
[INFO] | +- com.netflix.ribbon:ribbon-core:jar:2.3.0:compile
[INFO] | | - commons-lang:commons-lang:jar:2.6:compile
[INFO] | +- com.netflix.ribbon:ribbon-httpclient:jar:2.3.0:compile
[INFO] | | +- commons-collections:commons-collections:jar:3.2.2:runtime
[INFO] | | +- com.sun.jersey:jersey-client:jar:1.19.1:runtime
[INFO] | | | - com.sun.jersey:jersey-core:jar:1.19.1:runtime
[INFO] | | | - javax.ws.rs:jsr311-api:jar:1.1.1:runtime
[INFO] | | +- com.sun.jersey.contribs:jersey-apache-client4:jar:1.19.1:runtime
[INFO] | | +- com.netflix.servo:servo-core:jar:0.10.1:runtime
[INFO] | | | - com.netflix.servo:servo-internal:jar:0.10.1:runtime
[INFO] | | - com.netflix.netflix-commons:netflix-commons-util:jar:0.1.1:runtime
[INFO] | +- com.netflix.ribbon:ribbon-loadbalancer:jar:2.3.0:compile
[INFO] | | - com.netflix.netflix-commons:netflix-statistics:jar:0.1.1:runtime
[INFO] | - io.reactivex:rxjava:jar:1.3.8:compile
[INFO] +- org.springframework.cloud:spring-cloud-openfeign-core:jar:2.2.3.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-autoconfigure:jar:2.4.2:compile
[INFO] | - io.github.openfeign.form:feign-form-spring:jar:3.8.0:compile
[INFO] | +- io.github.openfeign.form:feign-form:jar:3.8.0:compile
[INFO] | - commons-fileupload:commons-fileupload:jar:1.4:compile
[INFO] +- org.springframework.cloud:spring-cloud-starter-loadbalancer:jar:3.0.0:compile
[INFO] | +- org.springframework.cloud:spring-cloud-loadbalancer:jar:3.0.0:compile
[INFO] | - com.stoyanr:evictor:jar:1.0.0:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.4.2:test
[INFO] | +- org.springframework.boot:spring-boot-test:jar:2.4.2:test
[INFO] | +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.4.2:test
[INFO] | +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] | | - net.minidev:json-smart:jar:2.3:test
[INFO] | | - net.minidev:accessors-smart:jar:1.2:test
[INFO] | | - org.ow2.asm:asm:jar:5.0.4:test
[INFO] | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3:test
[INFO] | | - jakarta.activation:jakarta.activation-api:jar:1.2.2:test
[INFO] | +- org.assertj:assertj-core:jar:3.18.1:test
[INFO] | +- org.hamcrest:hamcrest:jar:2.2:test
[INFO] | +- org.junit.jupiter:junit-jupiter:jar:5.7.0:test
[INFO] | | +- org.junit.jupiter:junit-jupiter-api:jar:5.7.0:test
[INFO] | | +- org.junit.jupiter:junit-jupiter-params:jar:5.7.0:test
[INFO] | | - org.junit.jupiter:junit-jupiter-engine:jar:5.7.0:test
[INFO] | +- org.mockito:mockito-core:jar:3.6.28:test
[INFO] | | +- net.bytebuddy:byte-buddy:jar:1.10.19:test
[INFO] | | +- net.bytebuddy:byte-buddy-agent:jar:1.10.19:test
[INFO] | | - org.objenesis:objenesis:jar:3.1:test
[INFO] | +- org.mockito:mockito-junit-jupiter:jar:3.6.28:test
[INFO] | +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] | | - com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] | +- org.springframework:spring-core:jar:5.3.3:compile
[INFO] | | - org.springframework:spring-jcl:jar:5.3.3:compile
[INFO] | +- org.springframework:spring-test:jar:5.3.3:test
[INFO] | - org.xmlunit:xmlunit-core:jar:2.7.0:test
[INFO] +- org.junit.vintage:junit-vintage-engine:jar:5.7.0:test
[INFO] | +- org.apiguardian:apiguardian-api:jar:1.1.0:test
[INFO] | +- org.junit.platform:junit-platform-engine:jar:1.7.0:test
[INFO] | | +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] | | - org.junit.platform:junit-platform-commons:jar:1.7.0:test
[INFO] | - junit:junit:jar:4.13.1:test
[INFO] | - org.hamcrest:hamcrest-core:jar:2.2:test
[INFO] +- org.springframework.cloud:spring-cloud-starter-sleuth:jar:3.0.0:compile
[INFO] | +- org.springframework.cloud:spring-cloud-sleuth-autoconfigure:jar:3.0.0:compile
[INFO] | | +- org.springframework.cloud:spring-cloud-sleuth-instrumentation:jar:3.0.0:compile
[INFO] | | - org.aspectj:aspectjrt:jar:1.9.6:compile
[INFO] | - org.springframework.cloud:spring-cloud-sleuth-brave:jar:3.0.0:compile
[INFO] | +- io.zipkin.brave:brave:jar:5.13.2:compile
[INFO] | +- io.zipkin.brave:brave-context-slf4j:jar:5.13.2:compile
[INFO] | +- io.zipkin.brave:brave-instrumentation-messaging:jar:5.13.2:compile
[INFO] | +- io.zipkin.brave:brave-instrumentation-rpc:jar:5.13.2:compile
[INFO] | +- io.zipkin.brave:brave-instrumentation-spring-rabbit:jar:5.13.2:compile
[INFO] | +- io.zipkin.brave:brave-instrumentation-kafka-clients:jar:5.13.2:compile
[INFO] | +- io.zipkin.brave:brave-instrumentation-kafka-streams:jar:5.13.2:compile
[INFO] | +- io.zipkin.brave:brave-instrumentation-httpclient:jar:5.13.2:compile
[INFO] | | - io.zipkin.brave:brave-instrumentation-http:jar:5.13.2:compile
[INFO] | +- io.zipkin.brave:brave-instrumentation-httpasyncclient:jar:5.13.2:compile
[INFO] | +- io.zipkin.brave:brave-instrumentation-jms:jar:5.13.2:compile
[INFO] | +- io.zipkin.brave:brave-instrumentation-mongodb:jar:5.13.2:compile
[INFO] | +- io.zipkin.aws:brave-propagation-aws:jar:0.21.3:compile
[INFO] | - io.zipkin.reporter2:zipkin-reporter-metrics-micrometer:jar:2.16.1:compile
[INFO] | - io.zipkin.reporter2:zipkin-reporter:jar:2.16.1:compile
[INFO] | - io.zipkin.zipkin2:zipkin:jar:2.23.0:compile
[INFO] - org.springframework.boot:spring-boot-starter-aop:jar:2.4.2:compile
[INFO] - org.aspectj:aspectjweaver:jar:1.9.6:compile

Ribbon配置不能与Spring Cloud LoadBalancer一起工作。对于实例的静态列表,请使用SimpleDiscoveryClient,并通过以下属性传递实例:

spring.cloud.discovery.client.simple.instances.service1[0].uri=http://s11:8080

如果你想对这些实例运行健康检查,就像使用Ribbon一样,你也应该设置LoadBalancer健康检查。

我也遇到了同样的问题,因为春云从2020年开始就不支持zuul了。Spring-cloud和netflix-zuul将在以下版本中正常工作。


spring-boot-starter-parent: 2.1.3.RELEASE
java.version: 1.8
spring-cloud.version: Greenwich.RELEASE
spring-cloud-starter-netflix-zuul: 2.1.0.RELEASE
spring-cloud-starter-netflix-eureka-client: 2.1.0.RELEASE
jackson-dataformat-xml: 2.9.9
spring-cloud-starter-netflix-eureka-server: 2.1.0.RELEASE

仅当您的应用程序中的路由是正确的时,才检查此答案。yml或application.properties文件。

当包括路由配置在内的一切对我来说都是正确的时,我所做的是解决问题:

步骤1。打开应用程序的配置文件(通常是application)。yml或application.properties) .

步骤2。找到Eureka客户端配置部分。它可能看起来像这样:

eureka:
client:
enabled: false

步骤3。将enabled属性更改为true,或者您可以将此属性作为默认值删除。

eureka:
client:
enabled: true

相关内容

  • 没有找到相关文章

最新更新