7 months ago

Spring Cloud 整合了 Netflix/zuul 提供了一個外部可以存取內部資源的動態 gateway,讓內部資源不管如何調度都不會影響外部的使用。

ps. 但一直聽說有要出 Zuul2 !!
ps.ps. 但 spring cloud 自己推出了 spring-cloud/spring-cloud-gateway!!

引入套件

build.gradle
ext {
    springCloudVersion = 'Dalston.SR3'
}

dependencies {
    compile('org.springframework.cloud:spring-cloud-starter-zuul')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

設定檔

application.yml
#關閉eureka因為路由部分是由我們手動編寫

ribbon.eureka.enabled: false


#有幾組就寫幾組上去吧

zuul:

  routes:

    member:

      path: /member/**

      url: http://api-test-member.711.com

    google:

      path: /google/**

      url: http://google.com.tw

記得啟用

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

就可以改用 Proxy 來取得資料

#原本的
curl -X GET \
  http://api-test-member.711.com/api/member/point/distribution/list

#透過Proxy
curl -X GET \
  http://localhost:5566/member/api/member/point/distribution/list

結束

← How to setup Ceph Persistent Volume for Kubernetes 客製化 Swagger UI →
 
comments powered by Disqus