From bf1c794732eb8d31e24c9f3ec6fd166457f90a92 Mon Sep 17 00:00:00 2001 From: ityouknow Date: Thu, 1 Jun 2017 13:27:02 +0800 Subject: [PATCH] m --- README.md | 4 +- .../gateway-service-zuul-eureka/pom.xml | 66 +++++++++++++++++++ .../neo/GatewayServiceZuulApplication.java | 14 ++++ .../src/main/resources/application.properties | 8 +++ .../GatewayServiceZuulApplicationTests.java | 16 +++++ .../gateway-service-zuul-simple/pom.xml | 62 +++++++++++++++++ .../neo/GatewayServiceZuulApplication.java | 14 ++++ .../src/main/resources/application.properties | 8 +++ .../GatewayServiceZuulApplicationTests.java | 16 +++++ .../spring-cloud-eureka/pom.xml | 62 +++++++++++++++++ .../com/neo/SpringCloudEurekaApplication.java | 14 ++++ .../src/main/resources/application.properties | 8 +++ .../SpringCloudEurekaApplicationTests.java | 16 +++++ .../spring-cloud-producer-2/pom.xml | 62 +++++++++++++++++ .../java/com/neo/ProducerApplication.java | 14 ++++ .../com/neo/controller/HelloController.java | 14 ++++ .../src/main/resources/application.properties | 4 ++ .../com/neo/ProducerApplicationTests.java | 16 +++++ .../spring-cloud-producer/pom.xml | 62 +++++++++++++++++ .../java/com/neo/ProducerApplication.java | 14 ++++ .../com/neo/controller/HelloController.java | 14 ++++ .../src/main/resources/application.properties | 4 ++ .../com/neo/ProducerApplicationTests.java | 16 +++++ 23 files changed, 526 insertions(+), 2 deletions(-) create mode 100644 gateway-service-zuul/gateway-service-zuul-eureka/pom.xml create mode 100644 gateway-service-zuul/gateway-service-zuul-eureka/src/main/java/com/neo/GatewayServiceZuulApplication.java create mode 100644 gateway-service-zuul/gateway-service-zuul-eureka/src/main/resources/application.properties create mode 100644 gateway-service-zuul/gateway-service-zuul-eureka/src/test/java/com/neo/GatewayServiceZuulApplicationTests.java create mode 100644 gateway-service-zuul/gateway-service-zuul-simple/pom.xml create mode 100644 gateway-service-zuul/gateway-service-zuul-simple/src/main/java/com/neo/GatewayServiceZuulApplication.java create mode 100644 gateway-service-zuul/gateway-service-zuul-simple/src/main/resources/application.properties create mode 100644 gateway-service-zuul/gateway-service-zuul-simple/src/test/java/com/neo/GatewayServiceZuulApplicationTests.java create mode 100644 gateway-service-zuul/spring-cloud-eureka/pom.xml create mode 100644 gateway-service-zuul/spring-cloud-eureka/src/main/java/com/neo/SpringCloudEurekaApplication.java create mode 100644 gateway-service-zuul/spring-cloud-eureka/src/main/resources/application.properties create mode 100644 gateway-service-zuul/spring-cloud-eureka/src/test/java/com/neo/SpringCloudEurekaApplicationTests.java create mode 100644 gateway-service-zuul/spring-cloud-producer-2/pom.xml create mode 100644 gateway-service-zuul/spring-cloud-producer-2/src/main/java/com/neo/ProducerApplication.java create mode 100644 gateway-service-zuul/spring-cloud-producer-2/src/main/java/com/neo/controller/HelloController.java create mode 100644 gateway-service-zuul/spring-cloud-producer-2/src/main/resources/application.properties create mode 100644 gateway-service-zuul/spring-cloud-producer-2/src/test/java/com/neo/ProducerApplicationTests.java create mode 100644 gateway-service-zuul/spring-cloud-producer/pom.xml create mode 100644 gateway-service-zuul/spring-cloud-producer/src/main/java/com/neo/ProducerApplication.java create mode 100644 gateway-service-zuul/spring-cloud-producer/src/main/java/com/neo/controller/HelloController.java create mode 100644 gateway-service-zuul/spring-cloud-producer/src/main/resources/application.properties create mode 100644 gateway-service-zuul/spring-cloud-producer/src/test/java/com/neo/ProducerApplicationTests.java diff --git a/README.md b/README.md index 79e5121..1fbb30d 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,7 @@ Spring cloud使用的各种示例,以最简单、最实用为标准 - [spring-cloud-config-svn-refresh](https://github.com/ityouknow/spring-cloud-starter/tree/master/spring-cloud-config-svn-refresh):配置中心svn版本示例,客户端refresh版本示例 - [spring-cloud-config-eureka](https://github.com/ityouknow/spring-cloud-starter/tree/master/spring-cloud-config-eureka):配置中心服务化和高可用代码示例 - [spring-cloud-config-eureka-bus](https://github.com/ityouknow/spring-cloud-starter/tree/master/spring-cloud-config-eureka-bus):配置中心和消息总线示例(配置中心终结版) - - +- [gateway-service-zuul](https://github.com/ityouknow/spring-cloud-starter/tree/master/gateway-service-zuul):服务网关zuul的使用示例 @@ -27,6 +26,7 @@ Spring cloud使用的各种示例,以最简单、最实用为标准 - [springcloud(七):配置中心svn示例和refresh](http://www.ityouknow.com/springcloud/2017/05/23/springcloud-config-svn-refresh.html) - [springcloud(八):配置中心服务化和高可用](http://www.ityouknow.com/springcloud/2017/05/25/springcloud-config-eureka.html) - [springcloud(九):配置中心和消息总线(配置中心终结版)](http://www.ityouknow.com/springcloud/2017/05/26/springcloud-config-eureka-bus.html) +- [springcloud(十):服务网关zuul](http://www.ityouknow.com/springcloud/2017/06/01/gateway-service-zuul.html) diff --git a/gateway-service-zuul/gateway-service-zuul-eureka/pom.xml b/gateway-service-zuul/gateway-service-zuul-eureka/pom.xml new file mode 100644 index 0000000..d3630a2 --- /dev/null +++ b/gateway-service-zuul/gateway-service-zuul-eureka/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + + com.neo + gateway-service-zuul-eureka + 0.0.1-SNAPSHOT + jar + + gateway-service-zuul-eureka + Demo project for Spring cloud zuul + + + org.springframework.boot + spring-boot-starter-parent + 1.5.3.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + Dalston.RELEASE + + + + + org.springframework.cloud + spring-cloud-starter-zuul + + + org.springframework.cloud + spring-cloud-starter-eureka + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/gateway-service-zuul/gateway-service-zuul-eureka/src/main/java/com/neo/GatewayServiceZuulApplication.java b/gateway-service-zuul/gateway-service-zuul-eureka/src/main/java/com/neo/GatewayServiceZuulApplication.java new file mode 100644 index 0000000..cd51f9d --- /dev/null +++ b/gateway-service-zuul/gateway-service-zuul-eureka/src/main/java/com/neo/GatewayServiceZuulApplication.java @@ -0,0 +1,14 @@ +package com.neo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.zuul.EnableZuulProxy; + +@SpringBootApplication +@EnableZuulProxy +public class GatewayServiceZuulApplication { + + public static void main(String[] args) { + SpringApplication.run(GatewayServiceZuulApplication.class, args); + } +} diff --git a/gateway-service-zuul/gateway-service-zuul-eureka/src/main/resources/application.properties b/gateway-service-zuul/gateway-service-zuul-eureka/src/main/resources/application.properties new file mode 100644 index 0000000..1841788 --- /dev/null +++ b/gateway-service-zuul/gateway-service-zuul-eureka/src/main/resources/application.properties @@ -0,0 +1,8 @@ +spring.application.name=gateway-service-zuul +server.port=8888 + +zuul.routes.producer.path=/producer/** +zuul.routes.producer.serviceId=spring-cloud-producer + +eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/ + diff --git a/gateway-service-zuul/gateway-service-zuul-eureka/src/test/java/com/neo/GatewayServiceZuulApplicationTests.java b/gateway-service-zuul/gateway-service-zuul-eureka/src/test/java/com/neo/GatewayServiceZuulApplicationTests.java new file mode 100644 index 0000000..3c5a48f --- /dev/null +++ b/gateway-service-zuul/gateway-service-zuul-eureka/src/test/java/com/neo/GatewayServiceZuulApplicationTests.java @@ -0,0 +1,16 @@ +package com.neo; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class GatewayServiceZuulApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/gateway-service-zuul/gateway-service-zuul-simple/pom.xml b/gateway-service-zuul/gateway-service-zuul-simple/pom.xml new file mode 100644 index 0000000..ad427fb --- /dev/null +++ b/gateway-service-zuul/gateway-service-zuul-simple/pom.xml @@ -0,0 +1,62 @@ + + + 4.0.0 + + com.neo + gateway-service-zuul-simple + 0.0.1-SNAPSHOT + jar + + gateway-service-zuul-simple + Demo project for Spring cloud zuul + + + org.springframework.boot + spring-boot-starter-parent + 1.5.3.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + Dalston.RELEASE + + + + + org.springframework.cloud + spring-cloud-starter-zuul + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/gateway-service-zuul/gateway-service-zuul-simple/src/main/java/com/neo/GatewayServiceZuulApplication.java b/gateway-service-zuul/gateway-service-zuul-simple/src/main/java/com/neo/GatewayServiceZuulApplication.java new file mode 100644 index 0000000..cd51f9d --- /dev/null +++ b/gateway-service-zuul/gateway-service-zuul-simple/src/main/java/com/neo/GatewayServiceZuulApplication.java @@ -0,0 +1,14 @@ +package com.neo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.zuul.EnableZuulProxy; + +@SpringBootApplication +@EnableZuulProxy +public class GatewayServiceZuulApplication { + + public static void main(String[] args) { + SpringApplication.run(GatewayServiceZuulApplication.class, args); + } +} diff --git a/gateway-service-zuul/gateway-service-zuul-simple/src/main/resources/application.properties b/gateway-service-zuul/gateway-service-zuul-simple/src/main/resources/application.properties new file mode 100644 index 0000000..66c623b --- /dev/null +++ b/gateway-service-zuul/gateway-service-zuul-simple/src/main/resources/application.properties @@ -0,0 +1,8 @@ +server.port=8888 + +#ñʾ/it/** ֱضhttp://www.ityouknow.com/** +zuul.routes.it.path=/it/** +zuul.routes.it.url=http://www.ityouknow.com + +zuul.routes.hello.path=/hello/** +zuul.routes.hello.url=http://localhost:9000/ \ No newline at end of file diff --git a/gateway-service-zuul/gateway-service-zuul-simple/src/test/java/com/neo/GatewayServiceZuulApplicationTests.java b/gateway-service-zuul/gateway-service-zuul-simple/src/test/java/com/neo/GatewayServiceZuulApplicationTests.java new file mode 100644 index 0000000..3c5a48f --- /dev/null +++ b/gateway-service-zuul/gateway-service-zuul-simple/src/test/java/com/neo/GatewayServiceZuulApplicationTests.java @@ -0,0 +1,16 @@ +package com.neo; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class GatewayServiceZuulApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/gateway-service-zuul/spring-cloud-eureka/pom.xml b/gateway-service-zuul/spring-cloud-eureka/pom.xml new file mode 100644 index 0000000..16f9038 --- /dev/null +++ b/gateway-service-zuul/spring-cloud-eureka/pom.xml @@ -0,0 +1,62 @@ + + + 4.0.0 + + com.neo + spring-cloud-eureka + 0.0.1-SNAPSHOT + jar + + spring-cloud-eureka + Demo project for Spring cloud eureka + + + org.springframework.boot + spring-boot-starter-parent + 1.5.3.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + Dalston.RELEASE + + + + + org.springframework.cloud + spring-cloud-starter-eureka-server + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/gateway-service-zuul/spring-cloud-eureka/src/main/java/com/neo/SpringCloudEurekaApplication.java b/gateway-service-zuul/spring-cloud-eureka/src/main/java/com/neo/SpringCloudEurekaApplication.java new file mode 100644 index 0000000..5d47795 --- /dev/null +++ b/gateway-service-zuul/spring-cloud-eureka/src/main/java/com/neo/SpringCloudEurekaApplication.java @@ -0,0 +1,14 @@ +package com.neo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; + +@SpringBootApplication +@EnableEurekaServer +public class SpringCloudEurekaApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringCloudEurekaApplication.class, args); + } +} diff --git a/gateway-service-zuul/spring-cloud-eureka/src/main/resources/application.properties b/gateway-service-zuul/spring-cloud-eureka/src/main/resources/application.properties new file mode 100644 index 0000000..124b09d --- /dev/null +++ b/gateway-service-zuul/spring-cloud-eureka/src/main/resources/application.properties @@ -0,0 +1,8 @@ +spring.application.name=spring-cloud-eureka + +server.port=8000 +eureka.client.register-with-eureka=false +eureka.client.fetch-registry=false + +eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/ + diff --git a/gateway-service-zuul/spring-cloud-eureka/src/test/java/com/neo/SpringCloudEurekaApplicationTests.java b/gateway-service-zuul/spring-cloud-eureka/src/test/java/com/neo/SpringCloudEurekaApplicationTests.java new file mode 100644 index 0000000..d536a6b --- /dev/null +++ b/gateway-service-zuul/spring-cloud-eureka/src/test/java/com/neo/SpringCloudEurekaApplicationTests.java @@ -0,0 +1,16 @@ +package com.neo; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class SpringCloudEurekaApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/gateway-service-zuul/spring-cloud-producer-2/pom.xml b/gateway-service-zuul/spring-cloud-producer-2/pom.xml new file mode 100644 index 0000000..4146b7e --- /dev/null +++ b/gateway-service-zuul/spring-cloud-producer-2/pom.xml @@ -0,0 +1,62 @@ + + + 4.0.0 + + com.neo + spring-cloud-producer-2 + 0.0.1-SNAPSHOT + jar + + spring-cloud-producer-2 + Demo project for Spring cloud producer + + + org.springframework.boot + spring-boot-starter-parent + 1.5.3.RELEASE + + + + + UTF-8 + UTF-8 + 1.7 + Dalston.RELEASE + + + + + org.springframework.cloud + spring-cloud-starter-eureka + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/gateway-service-zuul/spring-cloud-producer-2/src/main/java/com/neo/ProducerApplication.java b/gateway-service-zuul/spring-cloud-producer-2/src/main/java/com/neo/ProducerApplication.java new file mode 100644 index 0000000..d6275cd --- /dev/null +++ b/gateway-service-zuul/spring-cloud-producer-2/src/main/java/com/neo/ProducerApplication.java @@ -0,0 +1,14 @@ +package com.neo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@SpringBootApplication +@EnableDiscoveryClient +public class ProducerApplication { + + public static void main(String[] args) { + SpringApplication.run(ProducerApplication.class, args); + } +} diff --git a/gateway-service-zuul/spring-cloud-producer-2/src/main/java/com/neo/controller/HelloController.java b/gateway-service-zuul/spring-cloud-producer-2/src/main/java/com/neo/controller/HelloController.java new file mode 100644 index 0000000..a305393 --- /dev/null +++ b/gateway-service-zuul/spring-cloud-producer-2/src/main/java/com/neo/controller/HelloController.java @@ -0,0 +1,14 @@ +package com.neo.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HelloController { + + @RequestMapping("/hello") + public String index(@RequestParam String name) { + return "hello "+name+",this is two messge"; + } +} \ No newline at end of file diff --git a/gateway-service-zuul/spring-cloud-producer-2/src/main/resources/application.properties b/gateway-service-zuul/spring-cloud-producer-2/src/main/resources/application.properties new file mode 100644 index 0000000..5086230 --- /dev/null +++ b/gateway-service-zuul/spring-cloud-producer-2/src/main/resources/application.properties @@ -0,0 +1,4 @@ +spring.application.name=spring-cloud-producer +server.port=9001 +eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/ + diff --git a/gateway-service-zuul/spring-cloud-producer-2/src/test/java/com/neo/ProducerApplicationTests.java b/gateway-service-zuul/spring-cloud-producer-2/src/test/java/com/neo/ProducerApplicationTests.java new file mode 100644 index 0000000..677161e --- /dev/null +++ b/gateway-service-zuul/spring-cloud-producer-2/src/test/java/com/neo/ProducerApplicationTests.java @@ -0,0 +1,16 @@ +package com.neo; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ProducerApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/gateway-service-zuul/spring-cloud-producer/pom.xml b/gateway-service-zuul/spring-cloud-producer/pom.xml new file mode 100644 index 0000000..ee2be51 --- /dev/null +++ b/gateway-service-zuul/spring-cloud-producer/pom.xml @@ -0,0 +1,62 @@ + + + 4.0.0 + + com.neo + spring-cloud-producer + 0.0.1-SNAPSHOT + jar + + spring-cloud-producer + Demo project for Spring cloud producer + + + org.springframework.boot + spring-boot-starter-parent + 1.5.3.RELEASE + + + + + UTF-8 + UTF-8 + 1.7 + Dalston.RELEASE + + + + + org.springframework.cloud + spring-cloud-starter-eureka + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/gateway-service-zuul/spring-cloud-producer/src/main/java/com/neo/ProducerApplication.java b/gateway-service-zuul/spring-cloud-producer/src/main/java/com/neo/ProducerApplication.java new file mode 100644 index 0000000..d6275cd --- /dev/null +++ b/gateway-service-zuul/spring-cloud-producer/src/main/java/com/neo/ProducerApplication.java @@ -0,0 +1,14 @@ +package com.neo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@SpringBootApplication +@EnableDiscoveryClient +public class ProducerApplication { + + public static void main(String[] args) { + SpringApplication.run(ProducerApplication.class, args); + } +} diff --git a/gateway-service-zuul/spring-cloud-producer/src/main/java/com/neo/controller/HelloController.java b/gateway-service-zuul/spring-cloud-producer/src/main/java/com/neo/controller/HelloController.java new file mode 100644 index 0000000..ba93702 --- /dev/null +++ b/gateway-service-zuul/spring-cloud-producer/src/main/java/com/neo/controller/HelloController.java @@ -0,0 +1,14 @@ +package com.neo.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HelloController { + + @RequestMapping("/hello") + public String index(@RequestParam String name) { + return "hello "+name+",this is first messge"; + } +} \ No newline at end of file diff --git a/gateway-service-zuul/spring-cloud-producer/src/main/resources/application.properties b/gateway-service-zuul/spring-cloud-producer/src/main/resources/application.properties new file mode 100644 index 0000000..7994abc --- /dev/null +++ b/gateway-service-zuul/spring-cloud-producer/src/main/resources/application.properties @@ -0,0 +1,4 @@ +spring.application.name=spring-cloud-producer +server.port=9000 +eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/ + diff --git a/gateway-service-zuul/spring-cloud-producer/src/test/java/com/neo/ProducerApplicationTests.java b/gateway-service-zuul/spring-cloud-producer/src/test/java/com/neo/ProducerApplicationTests.java new file mode 100644 index 0000000..677161e --- /dev/null +++ b/gateway-service-zuul/spring-cloud-producer/src/test/java/com/neo/ProducerApplicationTests.java @@ -0,0 +1,16 @@ +package com.neo; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ProducerApplicationTests { + + @Test + public void contextLoads() { + } + +}