首页 文章

将Zuul添加到Netflix OSS安装中

提问于
浏览
0

我在linux机器上运行netflix oss堆栈 . 这个堆栈有Eureka,并且安装了一堆微服务(hello服务),所有这些都在各个docker容器中运行 .

它是使用Maven和Spring Boot安装的 .

我的问题是:如何将Zuul添加到此堆栈?我在网上发现了一些东西,但是他们也安装了Eureka,如果我运行它,我就会覆盖当前的Eureka .

2 回答

  • 0

    您需要将 @EnableZuulProxy 注释添加到主类

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

    并在application.yml文件中添加具有您的eureka-microservices名称的路由

    zuul:
       ignoredServices: '*'
       routes:
          microservice1: 
             path: /microservice1/** 
             stripPrefix: false
    
          microservice2:
             path: /microservice2/**
             stripPrefix: false
    
          ...
          #If you have hystrix
          hystrix: 
              threadpool:
                default:
                   maxQueueSize: 100
                   queueSizeRejectionThreshold: 100
              command:      
                default:
                 execution:
                     isolation:
                         thread:
                            timeoutInMilliseconds: 60000
         #load balancing
          ribbon:
             MaxAutoRetries: 2 
             MaxAutoRetriesNextServer: 2        
             OkToRetryOnAllOperations: true
             ServerListRefreshInterval: 2000
             ConnectTimeout: 50000
             ReadTimeout: 50000
    

    默认情况下,zuul在端口8500上运行 .

    maven依赖

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-zuul</artifactId>
    </dependency>
    
  • 0
    • 另外,请确保使用serviceid进行URL路由 . 例如:
    zuul:
      routes:
        httpbin:
          path: /**
          serviceId: httpbin
    
    • Zuul应该知道eureka能够为正在运行的各种服务获取正确的ip .
    ribbon:
       eureka:
        enabled: false
    

    上述配置确保您可以在以后为特定服务动态添加更多服务器,而无需修改zull路由服务器配置,因为它将能够通过查询eureka来查询和更新运行特定服务的服务器

相关问题