Consul Service Discovery的自动代理服务


無口君
2025-03-14 11:15:03 (17天前)
  1. 我正试图从Eureka转到Consul进行服务发现并遇到问题 - 我的网关服务注册和我的客户服务注册,但网关服务不会路由......

2 条回复
  1. 0# 听风~ | 2019-08-31 10-32



    试试这个我觉得这有助于你解决问题..



    这是我的网关bootstrap.yml文件




    1. spring:
      application:

    2. name: gateway-service

    3. spring:
      profiles: default
      cloud:
      consul:
      config:
      prefix: config/dev/
      format: FILES
      host: localhost
      port: 8500
      discovery:
      prefer-ip-address: true
      spring.profiles.active: dev

    4. </code>


    我将此依赖关系用于网关和所有应用程序





    1. org.springframework.cloud
      spring-cloud-starter-consul-discovery


    2. org.springframework.cloud
      spring-cloud-starter-consul-config
    3. </code>


    consul用作我的配置服务器。然后我添加consul这个配置。配置路径是/config/dev/gateway.yml




    1. zuul:
      prefix: /api
      ignoredServices: ‘*’
      host:
      connect-timeout-millis: 20000
      socket-timeout-millis: 20000

    2. routes:
      customer-service:
      path: /customer/**
      serviceId: customer-service
      stripPrefix: false
      sensitiveHeaders: Cookie,Set-Cookie

    3. </code>


    网关服务spring boot应用程序注释如下




    1. @SpringBootApplication
      @EnableDiscoveryClient
      @EnableZuulProxy
      public class GatewayServiceApplication {

    2. public static void main(String[] args) {
    3.     SpringApplication.run(GatewayServiceApplication.class, args);
    4. } // End main ()
    5. }// End GatewayServiceApplication

    6. </code>


    如果你像这样制作你的应用程序,你可以使用你更喜欢的路径。




    样本领事配置





登录 后才能参与评论