微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Zuul/Eureka/ribbon 无法路由到从网关服务到宁静服务的服务

如何解决Zuul/Eureka/ribbon 无法路由到从网关服务到宁静服务的服务

我正在创建 3 个不同的服务

  1. discovery-service - Eureka 服务发现 - http://localhost:8761/
  2. 网关服务 - Netflix Zuul 网关 - http://localhost:9090/actuator/
  3. restful-service - 一个 Rest 服务 - http://localhost:8091/actuator/,

我的想法是使用 gateway-service 调用使用 Ribbon 的 restful-service ,这将 Eureka 的 discoveryEnablednIWSServerList我不想硬编码服务器列表,并希望 Ribbon 在运行时使用 Eureka 的服务发现动态获取服务器。

稍后,我想将这 3 项服务部署到 AWS 并查看其工作原理。

每次我试图点击下面提到的网址

http://localhost:9090/restful/resttest

我收到错误 404

当我尝试击球时也是如此

http://localhost:8091/resttest

这也给了我ERROR 404

有人可以帮我解决这个问题吗?

我已经通过以下链接来了解和解决问题

https://github.com/spring-cloud/spring-cloud-netflix/issues/3389

https://github.com/spring-cloud/spring-cloud-netflix/issues/1177

还尝试了 stripPrefix: false 并提供了 vIpAddress 配置,但似乎没有任何效果

该项目的 Github 链接 - https://github.com/SauravDas90/SpringCloudExercise

gateway-service application.yml

  application:
    name: gateway-service
  profiles:
    active: dev

server:
    port: 9090


eureka:
  instance:
    preferIPAddress: true
    leaserenewalIntervalInSeconds: 3
    MetadataMap:
      instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}
  client:
    registerWithEureka: true
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://localhost:8761/eureka
ribbon:
  eureka:
    enabled: true

  zuul:
    ignoredServices: '*'
    routes:
      search-service:
        path: /search/**
        serviceId: search-service
      restful-service:
        path: /restful/**
        serviceId: restful-service
        strip-prefix: false

restful-service application.yml

spring:
  application:
    name: restful-service
  profiles:
    active: dev

server:
  port: 8091


eureka:
    client:
      registerWithEureka: true
      fetchRegistry: true
      serviceUrl:
        defaultZone: http://localhost:8761/eureka/
    instance:
      hostname: localhost
    leaserenewalIntervalInSeconds: 3
    MetadataMap:
      instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}

ribbon:
  eureka:
    enabled: true

RestfulServiceApplication.java

@SpringBootApplication
public class RestfulServiceApplication {

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

    @GetMapping("/resttest")
    public String testConnection(){
        return "Test Url for RestFul Service";
    }

}

当我尝试访问 url http://localhost:9090/restful/resttest 时打印的一些日志

2021-02-14 20:32:55.326  INFO 24432 --- [nio-9090-exec-1] c.n.l.DynamicServerListLoadBalancer      : Using serverListUpdater PollingServerListUpdater
2021-02-14 20:32:55.329  INFO 24432 --- [nio-9090-exec-1] c.netflix.config.ChainedDynamicProperty  : Flipping property: restful-service.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2021-02-14 20:32:55.330  INFO 24432 --- [nio-9090-exec-1] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client restful-service initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=restful-service,current list of Servers=[localhost:8091],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone;  Instance count:1;   Active connections count: 0;    Circuit breaker tripped count: 0;   Active connections per server: 0.0;]
},Server stats: [[Server:localhost:8091;    Zone:defaultZone;   Total Requests:0;   Successive connection failure:0;    Total blackout seconds:0;   Last connection made:Thu Jan 01 05:30:00 IST 1970;  First connection made: Thu Jan 01 05:30:00 IST 1970;    Active Connections:0;   total failure count in last (1000) msecs:0; average resp time:0.0;  90 percentile resp time:0.0;    95 percentile resp time:0.0;    min resp time:0.0;  max resp time:0.0;  stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@55598538
2021-02-14 20:32:56.332  INFO 24432 --- [erListUpdater-1] c.netflix.config.ChainedDynamicProperty  : Flipping property: restful-service.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。