From efa3378517586d1bbdfbe516f15a8a4413f4f0bc Mon Sep 17 00:00:00 2001 From: huzhicheng Date: Thu, 21 Mar 2019 18:00:13 +0800 Subject: [PATCH] =?UTF-8?q?Spring=20Cloud=20=E7=B3=BB=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 0 -> 6148 bytes .gitignore | 7 ++ actuator/pom.xml | 88 +++++++++++++++++ .../actuator/ActuatorApplication.java | 18 ++++ actuator/src/main/resources/application.yml | 19 ++++ .../test/java/kite/springcloud/AppTest.java | 20 ++++ admin/pom.xml | 82 ++++++++++++++++ admin/src/main/java/kite/springcloud/App.java | 13 +++ .../test/java/kite/springcloud/AppTest.java | 20 ++++ common/pom.xml | 30 ++++++ .../springcloud/common/stream/LogInfo.java | 34 +++++++ .../common/stream/MessageUtil.java | 18 ++++ .../common/stream/MyProcessor.java | 38 ++++++++ .../config-single-client/pom.xml | 88 +++++++++++++++++ .../config/single/client/Application.java | 15 +++ .../client/config/GitAutoRefreshConfig.java | 51 ++++++++++ .../single/client/config/GitConfig.java | 27 +++++ .../client/controller/GitController.java | 33 +++++++ .../src/main/resources/application.yml | 12 +++ .../src/main/resources/bootstrap.yml | 22 +++++ .../test/java/kite/springcloud/AppTest.java | 20 ++++ .../config-single-server/pom.xml | 84 ++++++++++++++++ .../config/single/server/Application.java | 20 ++++ .../src/main/resources/application.yml | 3 + .../src/main/resources/bootstrap.yml | 12 +++ .../test/java/kite/springcloud/AppTest.java | 20 ++++ config/config-single/pom.xml | 88 +++++++++++++++++ config/pom.xml | 76 +++++++++++++++ consul/consul-config/pom.xml | 85 ++++++++++++++++ .../java/kite/springcloud/consul/.DS_Store | Bin 0 -> 6148 bytes .../kite/springcloud/consul/Application.java | 20 ++++ .../kite/springcloud/consul/config/.DS_Store | Bin 0 -> 6148 bytes .../consul/config/ConfigController.java | 45 +++++++++ .../consul/config/MySqlComplexConfig.java | 68 +++++++++++++ .../consul/config/MySqlConfig.java | 24 +++++ .../src/main/resources/application.yml | 16 +++ .../src/main/resources/bootstrap.yml | 11 +++ .../src/main/resources/config-demo.yml | 5 + consul/consul-customer/pom.xml | 77 +++++++++++++++ .../consul/customer/Application.java | 31 ++++++ .../controller/ConsumerController.java | 80 +++++++++++++++ .../customer/service/IHelloService.java | 20 ++++ .../src/resources/application.yml | 17 ++++ .../src/resources/bootstrap.yml | 5 + consul/consul-provider/pom.xml | 72 ++++++++++++++ .../consul/provider/Application.java | 20 ++++ .../provider/controller/HelloController.java | 44 +++++++++ .../src/main/resources/application.yml | 32 ++++++ .../src/main/resources/bootstrap.yml | 7 ++ consul/pom.xml | 51 ++++++++++ docker/docker-sample/.DS_Store | Bin 0 -> 6148 bytes docker/docker-sample/Dockerfile | 4 + docker/docker-sample/pom.xml | 92 ++++++++++++++++++ .../docker/sample/Application.java | 18 ++++ .../sample/controller/DockerController.java | 19 ++++ .../src/main/resources/application.yml | 5 + docker/pom.xml | 81 +++++++++++++++ eureka/eureka-ha/eureka-ha-customer/pom.xml | 80 +++++++++++++++ .../eureak/ha/customer/Application.java | 28 ++++++ .../controller/ConsumerController.java | 41 ++++++++ .../ha/customer/service/IHelloService.java | 20 ++++ .../src/main/resources/application.yml | 8 ++ .../src/main/resources/bootstrap.yml | 3 + eureka/eureka-ha/eureka-ha-provider/pom.xml | 33 +++++++ .../java/kite/springcloud/eureka/.DS_Store | Bin 0 -> 6148 bytes .../java/kite/springcloud/eureka/ha/.DS_Store | Bin 0 -> 6148 bytes .../eureka/ha/provider/Application.java | 21 ++++ .../provider/controller/HelloController.java | 42 ++++++++ .../src/main/resources/application.yml | 35 +++++++ eureka/eureka-ha/eureka-ha-server/pom.xml | 72 ++++++++++++++ .../eureka/ha/server/Application.java | 33 +++++++ .../src/main/resources/application.yml | 32 ++++++ .../src/main/resources/bootstrap.yml | 11 +++ eureka/eureka-ha/pom.xml | 22 +++++ .../eureka-single-customer/pom.xml | 89 +++++++++++++++++ .../customer/SingleCustomerApplication.java | 34 +++++++ .../aop/SimplePerformanceMonitor.java | 50 ++++++++++ .../customer/conf/WebSecurityConfig.java | 43 ++++++++ .../controller/ConsumerController.java | 49 ++++++++++ .../customer/service/IHelloService.java | 20 ++++ .../src/main/resources/application.yml | 16 +++ .../eureka-single-provider/pom.xml | 37 +++++++ .../kite/springcloud/eureka/single/.DS_Store | Bin 0 -> 8196 bytes .../eureka/single/provider/.DS_Store | Bin 0 -> 6148 bytes .../provider/SingleProviderApplication.java | 21 ++++ .../aop/SimplePerformanceMonitor.java | 50 ++++++++++ .../provider/conf/WebSecurityConfig.java | 43 ++++++++ .../single/provider/controller/.DS_Store | Bin 0 -> 6148 bytes .../controller/ProviderController.java | 42 ++++++++ .../src/main/resources/application.yml | 23 +++++ .../eureka-single-server/pom.xml | 80 +++++++++++++++ .../eureka/single/server/Application.java | 21 ++++ .../single/server/conf/WebSecurityConfig.java | 43 ++++++++ .../src/main/resources/application.yml | 18 ++++ .../src/main/resources/bootstrap.yml | 15 +++ eureka/eureka-single/pom.xml | 23 +++++ eureka/pom.xml | 77 +++++++++++++++ pom.xml | 78 +++++++++++++++ sleuth/pom.xml | 87 +++++++++++++++++ .../springcloud/sleuth/SleuthApplication.java | 16 +++ .../sleuth/controller/SleuthController.java | 19 ++++ sleuth/src/main/resources/application.yml | 5 + .../test/java/kite/springcloud/AppTest.java | 20 ++++ stream/pom.xml | 34 +++++++ stream/stream-rabbit-customer/pom.xml | 73 ++++++++++++++ .../rabbit/customer/CustomerApplication.java | 28 ++++++ .../rabbit/customer/DefaultApplication.java | 26 +++++ .../service/DefaultMessageListener.java | 23 +++++ .../customer/service/LogMessageListener.java | 50 ++++++++++ .../src/main/resources/application.yml | 84 ++++++++++++++++ stream/stream-rabbit-producer/pom.xml | 72 ++++++++++++++ .../rabbit/producer/ProducerApplication.java | 26 +++++ .../controller/MyMessageController.java | 46 +++++++++ .../src/main/resources/application.yml | 21 ++++ 114 files changed, 3890 insertions(+) create mode 100644 .DS_Store create mode 100644 .gitignore create mode 100644 actuator/pom.xml create mode 100644 actuator/src/main/java/kite/springcloud/actuator/ActuatorApplication.java create mode 100644 actuator/src/main/resources/application.yml create mode 100644 actuator/src/test/java/kite/springcloud/AppTest.java create mode 100644 admin/pom.xml create mode 100644 admin/src/main/java/kite/springcloud/App.java create mode 100644 admin/src/test/java/kite/springcloud/AppTest.java create mode 100644 common/pom.xml create mode 100644 common/src/main/java/kite/springcloud/common/stream/LogInfo.java create mode 100644 common/src/main/java/kite/springcloud/common/stream/MessageUtil.java create mode 100644 common/src/main/java/kite/springcloud/common/stream/MyProcessor.java create mode 100644 config/config-single/config-single-client/pom.xml create mode 100644 config/config-single/config-single-client/src/main/java/kite/springcloud/config/single/client/Application.java create mode 100644 config/config-single/config-single-client/src/main/java/kite/springcloud/config/single/client/config/GitAutoRefreshConfig.java create mode 100644 config/config-single/config-single-client/src/main/java/kite/springcloud/config/single/client/config/GitConfig.java create mode 100644 config/config-single/config-single-client/src/main/java/kite/springcloud/config/single/client/controller/GitController.java create mode 100644 config/config-single/config-single-client/src/main/resources/application.yml create mode 100644 config/config-single/config-single-client/src/main/resources/bootstrap.yml create mode 100644 config/config-single/config-single-client/src/test/java/kite/springcloud/AppTest.java create mode 100644 config/config-single/config-single-server/pom.xml create mode 100644 config/config-single/config-single-server/src/main/java/kite/springcloud/config/single/server/Application.java create mode 100644 config/config-single/config-single-server/src/main/resources/application.yml create mode 100644 config/config-single/config-single-server/src/main/resources/bootstrap.yml create mode 100644 config/config-single/config-single-server/src/test/java/kite/springcloud/AppTest.java create mode 100644 config/config-single/pom.xml create mode 100644 config/pom.xml create mode 100644 consul/consul-config/pom.xml create mode 100644 consul/consul-config/src/main/java/kite/springcloud/consul/.DS_Store create mode 100644 consul/consul-config/src/main/java/kite/springcloud/consul/Application.java create mode 100644 consul/consul-config/src/main/java/kite/springcloud/consul/config/.DS_Store create mode 100644 consul/consul-config/src/main/java/kite/springcloud/consul/config/ConfigController.java create mode 100644 consul/consul-config/src/main/java/kite/springcloud/consul/config/MySqlComplexConfig.java create mode 100644 consul/consul-config/src/main/java/kite/springcloud/consul/config/MySqlConfig.java create mode 100644 consul/consul-config/src/main/resources/application.yml create mode 100644 consul/consul-config/src/main/resources/bootstrap.yml create mode 100644 consul/consul-config/src/main/resources/config-demo.yml create mode 100644 consul/consul-customer/pom.xml create mode 100644 consul/consul-customer/src/main/java/kite/springcloud/consul/customer/Application.java create mode 100644 consul/consul-customer/src/main/java/kite/springcloud/consul/customer/controller/ConsumerController.java create mode 100644 consul/consul-customer/src/main/java/kite/springcloud/consul/customer/service/IHelloService.java create mode 100644 consul/consul-customer/src/resources/application.yml create mode 100644 consul/consul-customer/src/resources/bootstrap.yml create mode 100644 consul/consul-provider/pom.xml create mode 100644 consul/consul-provider/src/main/java/kite/springcloud/consul/provider/Application.java create mode 100644 consul/consul-provider/src/main/java/kite/springcloud/consul/provider/controller/HelloController.java create mode 100644 consul/consul-provider/src/main/resources/application.yml create mode 100644 consul/consul-provider/src/main/resources/bootstrap.yml create mode 100644 consul/pom.xml create mode 100644 docker/docker-sample/.DS_Store create mode 100644 docker/docker-sample/Dockerfile create mode 100644 docker/docker-sample/pom.xml create mode 100644 docker/docker-sample/src/main/java/kite/springcloud/docker/sample/Application.java create mode 100644 docker/docker-sample/src/main/java/kite/springcloud/docker/sample/controller/DockerController.java create mode 100644 docker/docker-sample/src/main/resources/application.yml create mode 100644 docker/pom.xml create mode 100644 eureka/eureka-ha/eureka-ha-customer/pom.xml create mode 100644 eureka/eureka-ha/eureka-ha-customer/src/main/java/kite/springcloud/eureak/ha/customer/Application.java create mode 100644 eureka/eureka-ha/eureka-ha-customer/src/main/java/kite/springcloud/eureak/ha/customer/controller/ConsumerController.java create mode 100644 eureka/eureka-ha/eureka-ha-customer/src/main/java/kite/springcloud/eureak/ha/customer/service/IHelloService.java create mode 100644 eureka/eureka-ha/eureka-ha-customer/src/main/resources/application.yml create mode 100644 eureka/eureka-ha/eureka-ha-customer/src/main/resources/bootstrap.yml create mode 100644 eureka/eureka-ha/eureka-ha-provider/pom.xml create mode 100644 eureka/eureka-ha/eureka-ha-provider/src/main/java/kite/springcloud/eureka/.DS_Store create mode 100644 eureka/eureka-ha/eureka-ha-provider/src/main/java/kite/springcloud/eureka/ha/.DS_Store create mode 100644 eureka/eureka-ha/eureka-ha-provider/src/main/java/kite/springcloud/eureka/ha/provider/Application.java create mode 100644 eureka/eureka-ha/eureka-ha-provider/src/main/java/kite/springcloud/eureka/ha/provider/controller/HelloController.java create mode 100644 eureka/eureka-ha/eureka-ha-provider/src/main/resources/application.yml create mode 100644 eureka/eureka-ha/eureka-ha-server/pom.xml create mode 100644 eureka/eureka-ha/eureka-ha-server/src/main/java/kite/springcloud/eureka/ha/server/Application.java create mode 100644 eureka/eureka-ha/eureka-ha-server/src/main/resources/application.yml create mode 100644 eureka/eureka-ha/eureka-ha-server/src/main/resources/bootstrap.yml create mode 100644 eureka/eureka-ha/pom.xml create mode 100644 eureka/eureka-single/eureka-single-customer/pom.xml create mode 100644 eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/SingleCustomerApplication.java create mode 100644 eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/aop/SimplePerformanceMonitor.java create mode 100755 eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/conf/WebSecurityConfig.java create mode 100644 eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/controller/ConsumerController.java create mode 100644 eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/service/IHelloService.java create mode 100644 eureka/eureka-single/eureka-single-customer/src/main/resources/application.yml create mode 100644 eureka/eureka-single/eureka-single-provider/pom.xml create mode 100644 eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/.DS_Store create mode 100644 eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/.DS_Store create mode 100644 eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/SingleProviderApplication.java create mode 100644 eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/aop/SimplePerformanceMonitor.java create mode 100755 eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/conf/WebSecurityConfig.java create mode 100644 eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/controller/.DS_Store create mode 100644 eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/controller/ProviderController.java create mode 100644 eureka/eureka-single/eureka-single-provider/src/main/resources/application.yml create mode 100644 eureka/eureka-single/eureka-single-server/pom.xml create mode 100644 eureka/eureka-single/eureka-single-server/src/main/java/kite/springcloud/eureka/single/server/Application.java create mode 100755 eureka/eureka-single/eureka-single-server/src/main/java/kite/springcloud/eureka/single/server/conf/WebSecurityConfig.java create mode 100644 eureka/eureka-single/eureka-single-server/src/main/resources/application.yml create mode 100644 eureka/eureka-single/eureka-single-server/src/main/resources/bootstrap.yml create mode 100644 eureka/eureka-single/pom.xml create mode 100644 eureka/pom.xml create mode 100644 pom.xml create mode 100644 sleuth/pom.xml create mode 100644 sleuth/src/main/java/kite/springcloud/sleuth/SleuthApplication.java create mode 100644 sleuth/src/main/java/kite/springcloud/sleuth/controller/SleuthController.java create mode 100644 sleuth/src/main/resources/application.yml create mode 100644 sleuth/src/test/java/kite/springcloud/AppTest.java create mode 100644 stream/pom.xml create mode 100644 stream/stream-rabbit-customer/pom.xml create mode 100644 stream/stream-rabbit-customer/src/main/java/kite/springcloud/stream/rabbit/customer/CustomerApplication.java create mode 100644 stream/stream-rabbit-customer/src/main/java/kite/springcloud/stream/rabbit/customer/DefaultApplication.java create mode 100644 stream/stream-rabbit-customer/src/main/java/kite/springcloud/stream/rabbit/customer/service/DefaultMessageListener.java create mode 100644 stream/stream-rabbit-customer/src/main/java/kite/springcloud/stream/rabbit/customer/service/LogMessageListener.java create mode 100644 stream/stream-rabbit-customer/src/main/resources/application.yml create mode 100644 stream/stream-rabbit-producer/pom.xml create mode 100644 stream/stream-rabbit-producer/src/main/java/kite/springcloud/stream/rabbit/producer/ProducerApplication.java create mode 100644 stream/stream-rabbit-producer/src/main/java/kite/springcloud/stream/rabbit/producer/controller/MyMessageController.java create mode 100644 stream/stream-rabbit-producer/src/main/resources/application.yml diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f639fb6275105a8e3c018fdafe661e76b9ff5e9e GIT binary patch literal 6148 zcmeHKO>fgM7=GP$T>_fu0j+S$1&PBpwM9%wXi`(;O4{c&&c!+fOhcuLk zHo)^~L?OlEOJ8ArDlqGa%fTEWFK}6NEjOkF?-AwWviBvfkB9?0qd@I8zu$poZa!|sy^QNkld+Eb#T!RqlD1mkSfyIqsBc=fZP{D)tNxHr`>C5|Nza|UkWZl> zc)I+Q^JrOiy=P%CJ#O55#N*Tr<6yEvfB8I&eLn5+EcO!_=ZTvR;VU~jZZv1J){fJ@ zcYnU)%-Wp?c-ZfB=5yO>-f15kos2Ht%-+u5eZY8N47;(k8ybJXM-=K%VyVaL{v?ig ze2RMEvq@t)Uwd?pIV;RU!6Ogie$8uhIwVH2L2&|d1d`neEG^qa~Vb!n9Ew|4t7Zeg^bUTM>-#JYZ^RWO4$3K#{}DIoR- z2T5R8<3gd_I*`dL0I-H?X()?d2I1pq>}p&nL<@{5SDuOvmRPMy| z<%8*-nZBVg**oGpl1{9v(Bwt|qd;DPs(NgQ^Z)Um@Beux^JEk-3j9|Ju-ak&u!kY( zv$Zrhan?FWCrH8sZ=q1SAk)XOEQq7{7LqiyIidjUYFsEp4b1!qNEu9K6!@zO`~(c* B*|Y!v literal 0 HcmV?d00001 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4b9e838 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +_Store +*/.DS_Store +*.swp +.idea +*.iml + +target diff --git a/actuator/pom.xml b/actuator/pom.xml new file mode 100644 index 0000000..b2c4d39 --- /dev/null +++ b/actuator/pom.xml @@ -0,0 +1,88 @@ + + + + + parent + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + actuator + + actuator + + + + UTF-8 + 1.8 + 1.8 + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + + junit + junit + 4.11 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/actuator/src/main/java/kite/springcloud/actuator/ActuatorApplication.java b/actuator/src/main/java/kite/springcloud/actuator/ActuatorApplication.java new file mode 100644 index 0000000..a615096 --- /dev/null +++ b/actuator/src/main/java/kite/springcloud/actuator/ActuatorApplication.java @@ -0,0 +1,18 @@ +package kite.springcloud.actuator; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * + * 启动类 + * @author fengzheng + */ +@SpringBootApplication +public class ActuatorApplication { + + public static void main(String[] args) { + SpringApplication.run(ActuatorApplication.class,args); + } +} diff --git a/actuator/src/main/resources/application.yml b/actuator/src/main/resources/application.yml new file mode 100644 index 0000000..7dc8b5c --- /dev/null +++ b/actuator/src/main/resources/application.yml @@ -0,0 +1,19 @@ +server: + port: 3201 +management: + endpoint: + shutdown: + enabled: false + endpoints: + web: + exposure: + include: "*" + jmx: + exposure: + include: "*" + server: + port: 3208 + +spring: + application: + name: actuator-application diff --git a/actuator/src/test/java/kite/springcloud/AppTest.java b/actuator/src/test/java/kite/springcloud/AppTest.java new file mode 100644 index 0000000..03cc220 --- /dev/null +++ b/actuator/src/test/java/kite/springcloud/AppTest.java @@ -0,0 +1,20 @@ +package kite.springcloud; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/admin/pom.xml b/admin/pom.xml new file mode 100644 index 0000000..f6afeb0 --- /dev/null +++ b/admin/pom.xml @@ -0,0 +1,82 @@ + + + + + parent + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + admin + + admin + + + UTF-8 + 1.8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + junit + junit + 4.11 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/admin/src/main/java/kite/springcloud/App.java b/admin/src/main/java/kite/springcloud/App.java new file mode 100644 index 0000000..2cd0e8d --- /dev/null +++ b/admin/src/main/java/kite/springcloud/App.java @@ -0,0 +1,13 @@ +package kite.springcloud; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/admin/src/test/java/kite/springcloud/AppTest.java b/admin/src/test/java/kite/springcloud/AppTest.java new file mode 100644 index 0000000..03cc220 --- /dev/null +++ b/admin/src/test/java/kite/springcloud/AppTest.java @@ -0,0 +1,20 @@ +package kite.springcloud; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/common/pom.xml b/common/pom.xml new file mode 100644 index 0000000..675c325 --- /dev/null +++ b/common/pom.xml @@ -0,0 +1,30 @@ + + + + parent + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + common + + + org.springframework + spring-messaging + 5.0.5.BUILD-SNAPSHOT + compile + + + org.springframework.cloud + spring-cloud-stream + 1.3.2.RELEASE + compile + + + + + \ No newline at end of file diff --git a/common/src/main/java/kite/springcloud/common/stream/LogInfo.java b/common/src/main/java/kite/springcloud/common/stream/LogInfo.java new file mode 100644 index 0000000..98c823b --- /dev/null +++ b/common/src/main/java/kite/springcloud/common/stream/LogInfo.java @@ -0,0 +1,34 @@ +package kite.springcloud.common.stream; + +import lombok.Data; + +import java.util.Date; + + +/** + * LogInfo + * + * @author fengzheng + * @date 2018/12/26 + */ +@Data +public class LogInfo { + + private String clientVersion; + + private String userId; + + private String clientIp; + + private Date time; + + @Override + public String toString() { + return "LogInfo{" + + "clientVersion='" + clientVersion + '\'' + + ", userId='" + userId + '\'' + + ", clientIp='" + clientIp + '\'' + + ", time=" + time + + '}'; + } +} diff --git a/common/src/main/java/kite/springcloud/common/stream/MessageUtil.java b/common/src/main/java/kite/springcloud/common/stream/MessageUtil.java new file mode 100644 index 0000000..4839fd2 --- /dev/null +++ b/common/src/main/java/kite/springcloud/common/stream/MessageUtil.java @@ -0,0 +1,18 @@ +package kite.springcloud.common.stream; + +import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; + +/** + * MessageUtil + * + * @author fengzheng + * @date 2018/12/20 + */ +public class MessageUtil { + + public static Message message(T message){ + return MessageBuilder.withPayload(message).build(); + } + +} diff --git a/common/src/main/java/kite/springcloud/common/stream/MyProcessor.java b/common/src/main/java/kite/springcloud/common/stream/MyProcessor.java new file mode 100644 index 0000000..0518245 --- /dev/null +++ b/common/src/main/java/kite/springcloud/common/stream/MyProcessor.java @@ -0,0 +1,38 @@ +package kite.springcloud.common.stream; + +import org.springframework.cloud.stream.annotation.Input; +import org.springframework.cloud.stream.annotation.Output; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.SubscribableChannel; +import org.springframework.stereotype.Component; + +/** + * MyProcessor + * + * @author fengzheng + * @date 2018/12/20 + */ +@Component +public interface MyProcessor { + + String MESSAGE_INPUT = "log_input"; + + String MESSAGE_OUTPUT = "log_output"; + + String LOG_FORMAT_INPUT = "log_format_input"; + + String LOG_FORMAT_OUTPUT = "log_format_output"; + + @Input(MESSAGE_INPUT) + SubscribableChannel logInput(); + + @Output(MESSAGE_OUTPUT) + MessageChannel logOutput(); + + @Input(LOG_FORMAT_INPUT) + SubscribableChannel logFormatInput(); + + @Output(LOG_FORMAT_OUTPUT) + MessageChannel logFormatOutput(); + +} diff --git a/config/config-single/config-single-client/pom.xml b/config/config-single/config-single-client/pom.xml new file mode 100644 index 0000000..8ff8f25 --- /dev/null +++ b/config/config-single/config-single-client/pom.xml @@ -0,0 +1,88 @@ + + + + + config-single + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + config-single-client + + config-single-client + + + UTF-8 + 1.8 + 1.8 + + + + + + org.springframework.cloud + spring-cloud-starter-config + + + + org.springframework.boot + spring-boot-starter-actuator + + + + junit + junit + 4.11 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/config/config-single/config-single-client/src/main/java/kite/springcloud/config/single/client/Application.java b/config/config-single/config-single-client/src/main/java/kite/springcloud/config/single/client/Application.java new file mode 100644 index 0000000..a2535d6 --- /dev/null +++ b/config/config-single/config-single-client/src/main/java/kite/springcloud/config/single/client/Application.java @@ -0,0 +1,15 @@ +package kite.springcloud.config.single.client; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author fengzheng + */ +@SpringBootApplication +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/config/config-single/config-single-client/src/main/java/kite/springcloud/config/single/client/config/GitAutoRefreshConfig.java b/config/config-single/config-single-client/src/main/java/kite/springcloud/config/single/client/config/GitAutoRefreshConfig.java new file mode 100644 index 0000000..6396c74 --- /dev/null +++ b/config/config-single/config-single-client/src/main/java/kite/springcloud/config/single/client/config/GitAutoRefreshConfig.java @@ -0,0 +1,51 @@ +package kite.springcloud.config.single.client.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * GitAutoRefreshConfig + * 配合调用 actuator/refresh 方法 再次获取的就是新的值 + * @author fengzheng + * @date 2019/3/21 + */ +@Component +@Data +@ConfigurationProperties(prefix = "data") +public class GitAutoRefreshConfig { + + public static class UserInfo { + private String username; + + private String password; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @Override + public String toString() { + return "UserInfo{" + + "username='" + username + '\'' + + ", password='" + password + '\'' + + '}'; + } + } + + private String env; + + private UserInfo user; +} diff --git a/config/config-single/config-single-client/src/main/java/kite/springcloud/config/single/client/config/GitConfig.java b/config/config-single/config-single-client/src/main/java/kite/springcloud/config/single/client/config/GitConfig.java new file mode 100644 index 0000000..265e474 --- /dev/null +++ b/config/config-single/config-single-client/src/main/java/kite/springcloud/config/single/client/config/GitConfig.java @@ -0,0 +1,27 @@ +package kite.springcloud.config.single.client.config; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +/** + * GitConfig + * 配合调用 actuator/refresh 方法 刷新页面依然是旧值 + * @author fengzheng + * @date 2019/3/21 + */ +@Data +@Component +public class GitConfig { + + @Value("${data.env}") + private String env; + + @Value("${data.user.username}") + private String username; + + @Value("${data.user.password}") + private String password; + +} diff --git a/config/config-single/config-single-client/src/main/java/kite/springcloud/config/single/client/controller/GitController.java b/config/config-single/config-single-client/src/main/java/kite/springcloud/config/single/client/controller/GitController.java new file mode 100644 index 0000000..0d932b2 --- /dev/null +++ b/config/config-single/config-single-client/src/main/java/kite/springcloud/config/single/client/controller/GitController.java @@ -0,0 +1,33 @@ +package kite.springcloud.config.single.client.controller; + +import kite.springcloud.config.single.client.config.GitAutoRefreshConfig; +import kite.springcloud.config.single.client.config.GitConfig; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * GitController + * + * @author fengzheng + * @date 2019/3/21 + */ +@RestController +public class GitController { + + @Autowired + private GitConfig gitConfig; + + @Autowired + private GitAutoRefreshConfig gitAutoRefreshConfig; + + @GetMapping(value = "show") + public Object show(){ + return gitConfig; + } + + @GetMapping(value = "autoShow") + public Object autoShow(){ + return gitAutoRefreshConfig; + } +} diff --git a/config/config-single/config-single-client/src/main/resources/application.yml b/config/config-single/config-single-client/src/main/resources/application.yml new file mode 100644 index 0000000..76dcbdf --- /dev/null +++ b/config/config-single/config-single-client/src/main/resources/application.yml @@ -0,0 +1,12 @@ +server: + port: 3302 +management: + endpoint: + shutdown: + enabled: false + endpoints: + web: + exposure: + include: "*" + + diff --git a/config/config-single/config-single-client/src/main/resources/bootstrap.yml b/config/config-single/config-single-client/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..0bf89c6 --- /dev/null +++ b/config/config-single/config-single-client/src/main/resources/bootstrap.yml @@ -0,0 +1,22 @@ + +spring: + profiles: prod + application: + name: config-single-client + cloud: + config: + uri: http://localhost:3301 + label: master + profile: default + + +--- +spring: + profiles: dev + application: + name: config-single-client + cloud: + config: + uri: http://localhost:3301 + label: master + profile: dev diff --git a/config/config-single/config-single-client/src/test/java/kite/springcloud/AppTest.java b/config/config-single/config-single-client/src/test/java/kite/springcloud/AppTest.java new file mode 100644 index 0000000..03cc220 --- /dev/null +++ b/config/config-single/config-single-client/src/test/java/kite/springcloud/AppTest.java @@ -0,0 +1,20 @@ +package kite.springcloud; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/config/config-single/config-single-server/pom.xml b/config/config-single/config-single-server/pom.xml new file mode 100644 index 0000000..6349636 --- /dev/null +++ b/config/config-single/config-single-server/pom.xml @@ -0,0 +1,84 @@ + + + + + config-single + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + config-single-server + + config-single-server + + + + UTF-8 + 1.8 + 1.8 + + + + + + org.springframework.cloud + spring-cloud-config-server + + + + junit + junit + 4.11 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/config/config-single/config-single-server/src/main/java/kite/springcloud/config/single/server/Application.java b/config/config-single/config-single-server/src/main/java/kite/springcloud/config/single/server/Application.java new file mode 100644 index 0000000..6c21aea --- /dev/null +++ b/config/config-single/config-single-server/src/main/java/kite/springcloud/config/single/server/Application.java @@ -0,0 +1,20 @@ +package kite.springcloud.config.single.server; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.config.server.EnableConfigServer; + + +/** + * spring cloud config server 启动类 + * + * @author fengzheng + */ +@SpringBootApplication +@EnableConfigServer +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/config/config-single/config-single-server/src/main/resources/application.yml b/config/config-single/config-single-server/src/main/resources/application.yml new file mode 100644 index 0000000..adeba4c --- /dev/null +++ b/config/config-single/config-single-server/src/main/resources/application.yml @@ -0,0 +1,3 @@ +server: + port: 3301 + diff --git a/config/config-single/config-single-server/src/main/resources/bootstrap.yml b/config/config-single/config-single-server/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..4568857 --- /dev/null +++ b/config/config-single/config-single-server/src/main/resources/bootstrap.yml @@ -0,0 +1,12 @@ +spring: + application: + name: config-single-server + cloud: + config: + server: + git: + uri: https://github.com/huzhicheng/config-only-a-demo + username: usrname + password: password + default-label: master + search-paths: config \ No newline at end of file diff --git a/config/config-single/config-single-server/src/test/java/kite/springcloud/AppTest.java b/config/config-single/config-single-server/src/test/java/kite/springcloud/AppTest.java new file mode 100644 index 0000000..03cc220 --- /dev/null +++ b/config/config-single/config-single-server/src/test/java/kite/springcloud/AppTest.java @@ -0,0 +1,20 @@ +package kite.springcloud; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/config/config-single/pom.xml b/config/config-single/pom.xml new file mode 100644 index 0000000..df7718c --- /dev/null +++ b/config/config-single/pom.xml @@ -0,0 +1,88 @@ + + + + + config + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + config-single + pom + + config-single + + config-single-server + config-single-client + + + + UTF-8 + 1.8 + 1.8 + + + + + + org.springframework.boot + spring-boot-starter-web + + + + junit + junit + 4.11 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/config/pom.xml b/config/pom.xml new file mode 100644 index 0000000..98ef915 --- /dev/null +++ b/config/pom.xml @@ -0,0 +1,76 @@ + + + + + parent + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + config + pom + + config-single + + + config + + + UTF-8 + 1.8 + 1.8 + + + + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/consul/consul-config/pom.xml b/consul/consul-config/pom.xml new file mode 100644 index 0000000..c3757f4 --- /dev/null +++ b/consul/consul-config/pom.xml @@ -0,0 +1,85 @@ + + + + + consul + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + consul-config + + consul-config + + + UTF-8 + 1.8 + 1.8 + + + + + org.springframework.cloud + spring-cloud-starter-consul-config + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/consul/consul-config/src/main/java/kite/springcloud/consul/.DS_Store b/consul/consul-config/src/main/java/kite/springcloud/consul/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..12db7cf64da79dd932ccfccbbd901c4eda211125 GIT binary patch literal 6148 zcmeHKI|>3Z5S>vG!N$@uSMUZw^aNf&P!vH{5VYRPb9pr1d>UQtw2?P3dC6p6LSC`6 zBO*G#Y-b`95gEY^B@zm@)+3y3!9m+;d(#Yi0p zwti-h{ zq5pp-aYY5Fz+Wk#gT-nw$CI+Qb{=Q7w!qhL%elkNFn0c7o_bQ`6`Nzf VCbof2N8IT^{tTEdG%E0G1s?X~6^#G@ literal 0 HcmV?d00001 diff --git a/consul/consul-config/src/main/java/kite/springcloud/consul/Application.java b/consul/consul-config/src/main/java/kite/springcloud/consul/Application.java new file mode 100644 index 0000000..ec5aea4 --- /dev/null +++ b/consul/consul-config/src/main/java/kite/springcloud/consul/Application.java @@ -0,0 +1,20 @@ +package kite.springcloud.consul.config; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +/** + * @author fengzheng + * @date 2018-11-23 + * Application + */ +@SpringBootApplication +@EnableDiscoveryClient +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/consul/consul-config/src/main/java/kite/springcloud/consul/config/.DS_Store b/consul/consul-config/src/main/java/kite/springcloud/consul/config/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 + + + + consul + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + consul-customer + jar + + consul-customer + + + + UTF-8 + 1.8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + + + maven-clean-plugin + 3.0.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.7.0 + + + maven-surefire-plugin + 2.20.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + + diff --git a/consul/consul-customer/src/main/java/kite/springcloud/consul/customer/Application.java b/consul/consul-customer/src/main/java/kite/springcloud/consul/customer/Application.java new file mode 100644 index 0000000..50426d1 --- /dev/null +++ b/consul/consul-customer/src/main/java/kite/springcloud/consul/customer/Application.java @@ -0,0 +1,31 @@ +package kite.springcloud.consul.customer; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; + +/** + * @author fengzheng + * @date 2018-11-23 + * Application + */ +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +public class Application { + + @Bean + @LoadBalanced + public RestTemplate restTemplate() { + return new RestTemplate(); + } + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/consul/consul-customer/src/main/java/kite/springcloud/consul/customer/controller/ConsumerController.java b/consul/consul-customer/src/main/java/kite/springcloud/consul/customer/controller/ConsumerController.java new file mode 100644 index 0000000..f019af7 --- /dev/null +++ b/consul/consul-customer/src/main/java/kite/springcloud/consul/customer/controller/ConsumerController.java @@ -0,0 +1,80 @@ +package kite.springcloud.consul.customer.controller; + +import kite.springcloud.consul.customer.service.IHelloService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.client.discovery.DiscoveryClient; +import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +/** + * ConsumerController + * + * @author fengzheng + * @date 2018/9/25 + */ +@RestController +public class ConsumerController { + + @Autowired + private LoadBalancerClient loadBalancer; + + @Autowired + private DiscoveryClient discoveryClient; + + + @Autowired + private RestTemplate restTemplate; + + @Autowired + private IHelloService helloService; + + private final static String SERVICE_NAME = "consul-provider"; + + + /** + * 使用普通的 RestTemplate 方法访问服务 + * + * @return + */ + @GetMapping(value = "test") + public Object test() { + String result = restTemplate.getForObject("http://"+SERVICE_NAME + "/test", String.class); + System.out.println(result); + return result; + } + + /** + * 使用 openFeign 方式访问服务 + * + * @return + */ + @GetMapping(value = "feign") + public Object feign() { + String s = helloService.nice(); + return s; + } + + + /** + * 获取所有服务实例 + * + * @return + */ + @GetMapping(value = "/services") + public Object services() { + return discoveryClient.getInstances(SERVICE_NAME); + } + + /** + * 从所有服务中选择一个服务(轮询) + */ + @GetMapping(value = "/choose") + public Object choose() { + return loadBalancer.choose(SERVICE_NAME).getUri().toString(); + } + +} diff --git a/consul/consul-customer/src/main/java/kite/springcloud/consul/customer/service/IHelloService.java b/consul/consul-customer/src/main/java/kite/springcloud/consul/customer/service/IHelloService.java new file mode 100644 index 0000000..2e737b7 --- /dev/null +++ b/consul/consul-customer/src/main/java/kite/springcloud/consul/customer/service/IHelloService.java @@ -0,0 +1,20 @@ +package kite.springcloud.consul.customer.service; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * IHelloService + * + * @author fengzheng + * @date 2018/9/26 + */ +@FeignClient(value = "consul-provider") +public interface IHelloService { + + @RequestMapping(value = "/test") + String test(); + + @RequestMapping(value = "nice") + String nice(); +} diff --git a/consul/consul-customer/src/resources/application.yml b/consul/consul-customer/src/resources/application.yml new file mode 100644 index 0000000..f1b07b9 --- /dev/null +++ b/consul/consul-customer/src/resources/application.yml @@ -0,0 +1,17 @@ +spring: + application: + name: consul-customer +server: + port: 5001 + +endpoints: + health: + sensitive: false + restart: + enabled: true + shutdown: + enabled: true + +management: + security: + enabled: false \ No newline at end of file diff --git a/consul/consul-customer/src/resources/bootstrap.yml b/consul/consul-customer/src/resources/bootstrap.yml new file mode 100644 index 0000000..e7d7132 --- /dev/null +++ b/consul/consul-customer/src/resources/bootstrap.yml @@ -0,0 +1,5 @@ +spring: + cloud: + consul: + discovery: + register: false \ No newline at end of file diff --git a/consul/consul-provider/pom.xml b/consul/consul-provider/pom.xml new file mode 100644 index 0000000..c8ab4e9 --- /dev/null +++ b/consul/consul-provider/pom.xml @@ -0,0 +1,72 @@ + + + + + consul + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + consul-provider + jar + + consul-provider + + + + UTF-8 + 1.8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + + + maven-clean-plugin + 3.0.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.7.0 + + + maven-surefire-plugin + 2.20.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + + diff --git a/consul/consul-provider/src/main/java/kite/springcloud/consul/provider/Application.java b/consul/consul-provider/src/main/java/kite/springcloud/consul/provider/Application.java new file mode 100644 index 0000000..d8725d9 --- /dev/null +++ b/consul/consul-provider/src/main/java/kite/springcloud/consul/provider/Application.java @@ -0,0 +1,20 @@ +package kite.springcloud.consul.provider; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +/** + * @author fengzheng + * @date 2018-11-23 + * Application + * 注册到 consul 上的服务提供者 + */ +@SpringBootApplication +@EnableDiscoveryClient +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/consul/consul-provider/src/main/java/kite/springcloud/consul/provider/controller/HelloController.java b/consul/consul-provider/src/main/java/kite/springcloud/consul/provider/controller/HelloController.java new file mode 100644 index 0000000..2814b85 --- /dev/null +++ b/consul/consul-provider/src/main/java/kite/springcloud/consul/provider/controller/HelloController.java @@ -0,0 +1,44 @@ +package kite.springcloud.consul.provider.controller; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.client.discovery.DiscoveryClient; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; + +/** + * HelloController + * + * @author fengzheng + * @date 2018/11/23 + */ +@RestController +@Slf4j +public class HelloController { + + @Autowired + private DiscoveryClient discoveryClient; + + @GetMapping(value = "test") + public String test(){ + List services = discoveryClient.getServices(); + for(String s : services){ + log.info(s); + } + return "hello spring cloud!"; + } + + @GetMapping(value = "nice") + public String nice(){ + List services = discoveryClient.getServices(); + for(String s : services){ + log.info("gogogo" + s); + } + return "nice to meet you!"; + } +} diff --git a/consul/consul-provider/src/main/resources/application.yml b/consul/consul-provider/src/main/resources/application.yml new file mode 100644 index 0000000..6ce7cac --- /dev/null +++ b/consul/consul-provider/src/main/resources/application.yml @@ -0,0 +1,32 @@ +spring: + profiles: + active: consul-provider1 +endpoints: + health: + sensitive: false + restart: + enabled: true + shutdown: + enabled: true + +management: + security: + enabled: false + +--- +spring: + profiles: consul-provider1 + application: + name: consul-provider1 + +server: + port: 5000 + +--- +spring: + profiles: consul-provider2 + application: + name: consul-provider2 + +server: + port: 5002 diff --git a/consul/consul-provider/src/main/resources/bootstrap.yml b/consul/consul-provider/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..e5e5d04 --- /dev/null +++ b/consul/consul-provider/src/main/resources/bootstrap.yml @@ -0,0 +1,7 @@ +spring: + cloud: + consul: + discovery: + service-name: consul-provider + host: localhost + port: 8500 \ No newline at end of file diff --git a/consul/pom.xml b/consul/pom.xml new file mode 100644 index 0000000..4e5411e --- /dev/null +++ b/consul/pom.xml @@ -0,0 +1,51 @@ + + + + parent + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + consul + pom + + consul-provider + consul-customer + consul-config + + + + + org.springframework.cloud + spring-cloud-starter-consul-all + + + + + + + org.springframework.cloud + spring-cloud-consul-dependencies + 2.1.0.M2 + pom + import + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/libs-milestone + + false + + + + + + \ No newline at end of file diff --git a/docker/docker-sample/.DS_Store b/docker/docker-sample/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c2b2914c64cfca9c7c92836371ca994768f0d79b GIT binary patch literal 6148 zcmeHK%Wl&^6upy##s(o$2`OF9rV@)#CE`(42+0az(H&9{EC98399j#<6WI=F2|?cU zAK(-C6aIh?;RDK{Z0`lH%Qb>XZ^p2MA-S}f&*@e^R>jO(-@o)W;j`&fi+9jRXkNG4OYiwXQiqQ%JJ-_bcA1? zmui1pRvS#Sv02}@U>rwT-fn+qm1^zUM%{5;$Gz#k=^u+}Klk%V*7eg@suzXBz{Jmm zh%aJ4co7Y!2aVfLM3VbaGEA4sU%!l!P)xgGl7yKW=b4`$gR3SwXf$WD2b~u0?Cs54 ze73vWZt?r~9?s{k)7AVBP}GjjOhByI!k+Rp5^b$oB(>OY{sD8r7=ha2<^ z78-E{#xxbEsmvTPn5HAoO`T`3(5UIe%;AHXnVC7EFf}{I=c=5Tr_r`n0jt2O0#)5@ z$o>E6@6Z3MB-^tJSOxwo1z4@u?{%>xv$w7-PVTiFeh8N)>k5q*6a;E3My=e6x8TZ< Y=Q03#1`CbI!0d;BlEF4sfxoK2Pu;kZ;s5{u literal 0 HcmV?d00001 diff --git a/docker/docker-sample/Dockerfile b/docker/docker-sample/Dockerfile new file mode 100644 index 0000000..532093e --- /dev/null +++ b/docker/docker-sample/Dockerfile @@ -0,0 +1,4 @@ +FROM openjdk:8-jdk-alpine +VOLUME /tmp +COPY target/docker-sample-1.0-SNAPSHOT.jar app.jar +ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file diff --git a/docker/docker-sample/pom.xml b/docker/docker-sample/pom.xml new file mode 100644 index 0000000..f8576a6 --- /dev/null +++ b/docker/docker-sample/pom.xml @@ -0,0 +1,92 @@ + + + + + docker + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + docker-sample + + docker-sample + + + + UTF-8 + 1.8 + 1.8 + kite + registry.cn-beijing.aliyuncs.com + fengzheng + + + + + org.springframework.boot + spring-boot-starter-web + + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + com.spotify + dockerfile-maven-plugin + 1.4.9 + + + tag-latest + deploy + + build + tag + push + + + latest + + + + tag-version + deploy + + build + tag + push + + + ${project.version} + + + + + + 用户名 + + 密码 + + registry.cn-beijing.aliyuncs.com/fengzheng/kite + latest + + ${project.build.finalName}.jar + + + + + + + + + diff --git a/docker/docker-sample/src/main/java/kite/springcloud/docker/sample/Application.java b/docker/docker-sample/src/main/java/kite/springcloud/docker/sample/Application.java new file mode 100644 index 0000000..b82dfd2 --- /dev/null +++ b/docker/docker-sample/src/main/java/kite/springcloud/docker/sample/Application.java @@ -0,0 +1,18 @@ +package kite.springcloud.docker.sample; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Application + * + * @author fengzheng + * @date 2019/1/18 + */ +@SpringBootApplication +public class Application { + + public static void main(String[] args){ + SpringApplication.run(Application.class, args); + } +} diff --git a/docker/docker-sample/src/main/java/kite/springcloud/docker/sample/controller/DockerController.java b/docker/docker-sample/src/main/java/kite/springcloud/docker/sample/controller/DockerController.java new file mode 100644 index 0000000..adefe4b --- /dev/null +++ b/docker/docker-sample/src/main/java/kite/springcloud/docker/sample/controller/DockerController.java @@ -0,0 +1,19 @@ +package kite.springcloud.docker.sample.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * DockerController + * + * @author fengzheng + * @date 2019/1/18 + */ +@RestController +public class DockerController { + + @GetMapping(value = "hello") + public Object sayHello(){ + return "hello! spring boot with docker."; + } +} diff --git a/docker/docker-sample/src/main/resources/application.yml b/docker/docker-sample/src/main/resources/application.yml new file mode 100644 index 0000000..b8d3997 --- /dev/null +++ b/docker/docker-sample/src/main/resources/application.yml @@ -0,0 +1,5 @@ +server: + port: 7000 +spring: + application: + name: spring-boot-docker-sample diff --git a/docker/pom.xml b/docker/pom.xml new file mode 100644 index 0000000..2f864eb --- /dev/null +++ b/docker/pom.xml @@ -0,0 +1,81 @@ + + + + + parent + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + docker + pom + + docker + + docker-sample + + + + UTF-8 + 1.8 + 1.8 + + + + + junit + junit + 4.11 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/eureka/eureka-ha/eureka-ha-customer/pom.xml b/eureka/eureka-ha/eureka-ha-customer/pom.xml new file mode 100644 index 0000000..8196f32 --- /dev/null +++ b/eureka/eureka-ha/eureka-ha-customer/pom.xml @@ -0,0 +1,80 @@ + + + + + eureka-ha + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + eureka-ha-customer + jar + + eureka-ha-customer + + + UTF-8 + 1.8 + 1.8 + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + + + maven-clean-plugin + 3.0.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.7.0 + + + maven-surefire-plugin + 2.20.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + + diff --git a/eureka/eureka-ha/eureka-ha-customer/src/main/java/kite/springcloud/eureak/ha/customer/Application.java b/eureka/eureka-ha/eureka-ha-customer/src/main/java/kite/springcloud/eureak/ha/customer/Application.java new file mode 100644 index 0000000..c86ea88 --- /dev/null +++ b/eureka/eureka-ha/eureka-ha-customer/src/main/java/kite/springcloud/eureak/ha/customer/Application.java @@ -0,0 +1,28 @@ +package kite.springcloud.eureak.ha.customer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.cloud.netflix.eureka.EnableEurekaClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; + +/** + * @author fengzheng + * Application + */ +@SpringBootApplication +@EnableEurekaClient +@EnableFeignClients +public class Application { + @LoadBalanced + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/eureka/eureka-ha/eureka-ha-customer/src/main/java/kite/springcloud/eureak/ha/customer/controller/ConsumerController.java b/eureka/eureka-ha/eureka-ha-customer/src/main/java/kite/springcloud/eureak/ha/customer/controller/ConsumerController.java new file mode 100644 index 0000000..aa9c095 --- /dev/null +++ b/eureka/eureka-ha/eureka-ha-customer/src/main/java/kite/springcloud/eureak/ha/customer/controller/ConsumerController.java @@ -0,0 +1,41 @@ +package kite.springcloud.eureak.ha.customer.controller; + +import kite.springcloud.eureak.ha.customer.service.IHelloService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +/** + * ConsumerController + * + * @author fengzheng + * @date 2018/9/25 + */ +@RestController +public class ConsumerController { + + + @Autowired + private RestTemplate restTemplate; + + @Autowired + private IHelloService helloService; + + private static final String applicationName = "ha-provider"; + + @GetMapping(value = "test") + public Object test() { + String url = "http://" + applicationName + "/hello"; + String s = restTemplate.getForObject(url, String.class); + return s; + } + + @GetMapping(value = "feign") + public Object feign() { + String s = helloService.nice(); + return s; + } + + +} diff --git a/eureka/eureka-ha/eureka-ha-customer/src/main/java/kite/springcloud/eureak/ha/customer/service/IHelloService.java b/eureka/eureka-ha/eureka-ha-customer/src/main/java/kite/springcloud/eureak/ha/customer/service/IHelloService.java new file mode 100644 index 0000000..2fe65e3 --- /dev/null +++ b/eureka/eureka-ha/eureka-ha-customer/src/main/java/kite/springcloud/eureak/ha/customer/service/IHelloService.java @@ -0,0 +1,20 @@ +package kite.springcloud.eureak.ha.customer.service; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * IHelloService + * + * @author fengzheng + * @date 2018/9/26 + */ +@FeignClient(value = "ha-provider") +public interface IHelloService { + + @RequestMapping(value = "/hello") + String hello(); + + @RequestMapping(value = "nice") + String nice(); +} diff --git a/eureka/eureka-ha/eureka-ha-customer/src/main/resources/application.yml b/eureka/eureka-ha/eureka-ha-customer/src/main/resources/application.yml new file mode 100644 index 0000000..4dc8b60 --- /dev/null +++ b/eureka/eureka-ha/eureka-ha-customer/src/main/resources/application.yml @@ -0,0 +1,8 @@ +server: + port: 1992 +eureka: + client: + serviceUrl: + defaultZone: http://localhost:1989/eureka,http://localhost:1988/eureka + instance: + preferIpAddress: true \ No newline at end of file diff --git a/eureka/eureka-ha/eureka-ha-customer/src/main/resources/bootstrap.yml b/eureka/eureka-ha/eureka-ha-customer/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..e72bbe5 --- /dev/null +++ b/eureka/eureka-ha/eureka-ha-customer/src/main/resources/bootstrap.yml @@ -0,0 +1,3 @@ +spring: + application: + name: ha-customer \ No newline at end of file diff --git a/eureka/eureka-ha/eureka-ha-provider/pom.xml b/eureka/eureka-ha/eureka-ha-provider/pom.xml new file mode 100644 index 0000000..03a4db9 --- /dev/null +++ b/eureka/eureka-ha/eureka-ha-provider/pom.xml @@ -0,0 +1,33 @@ + + + + eureka-ha + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + eureka-ha-provider + jar + + + UTF-8 + 1.8 + 1.8 + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + org.springframework.boot + spring-boot-starter-web + + + + \ No newline at end of file diff --git a/eureka/eureka-ha/eureka-ha-provider/src/main/java/kite/springcloud/eureka/.DS_Store b/eureka/eureka-ha/eureka-ha-provider/src/main/java/kite/springcloud/eureka/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..77c82b07f7d752c6b5505864fb71ff0835571775 GIT binary patch literal 6148 zcmeHK%}T>S5Z2@1RDv7q^UiWLVN)qK)w3& z7@{xXgZKc>>~2M=-bAF#!0b0WJG0Av2|K%tFW;XSo@)$)vH0g83h+Xyq#`|EKs4@Pg<3v8T$rHpCp!V4IZhYL52qa;3semAxoLr4q| z1H?eTFrd#jW29d;MEf8Hh=E^Y0M7>-6w%R`E0jkEG!bA>Ph z!c{7uO6B^A!Bsl=Z5`)m%oVD1#^uT|k6xMU7YdiFgWs0nj5`XcB?gFruM7;Ru7&k~ z^XK>f*Cgr@1H?dIF~Ex(?nVW+q-$%>=CIbcRectGePAZeh682D2L-T~j;UdI3c literal 0 HcmV?d00001 diff --git a/eureka/eureka-ha/eureka-ha-provider/src/main/java/kite/springcloud/eureka/ha/.DS_Store b/eureka/eureka-ha/eureka-ha-provider/src/main/java/kite/springcloud/eureka/ha/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 services = discoveryClient.getServices(); + for(String s : services){ + log.info(s); + } + return "hello spring cloud!"; + } + + @GetMapping(value = "nice") + public String nice(){ + List services = discoveryClient.getServices(); + for(String s : services){ + log.info("gogogo" + s); + } + return "nice to meet you!"; + } +} diff --git a/eureka/eureka-ha/eureka-ha-provider/src/main/resources/application.yml b/eureka/eureka-ha/eureka-ha-provider/src/main/resources/application.yml new file mode 100644 index 0000000..358be0d --- /dev/null +++ b/eureka/eureka-ha/eureka-ha-provider/src/main/resources/application.yml @@ -0,0 +1,35 @@ +spring: + profiles: ha-provider1 + application: + name: ha-provider + security: + user: + name: root + password: root +server: + port: 1990 +eureka: + instance: + preferIpAddress: true + client: + serviceUrl: + defaultZone: http://localhost:1989/eureka,http://localhost:1988/eureka + + +--- +spring: + profiles: ha-provider2 + application: + name: ha-provider + security: + user: + name: root + password: root +server: + port: 1991 +eureka: + instance: + preferIpAddress: true + client: + serviceUrl: + defaultZone: http://localhost:1989/eureka,http://localhost:1988/eureka diff --git a/eureka/eureka-ha/eureka-ha-server/pom.xml b/eureka/eureka-ha/eureka-ha-server/pom.xml new file mode 100644 index 0000000..6896957 --- /dev/null +++ b/eureka/eureka-ha/eureka-ha-server/pom.xml @@ -0,0 +1,72 @@ + + + + + eureka-ha + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + eureka-ha-server + jar + + eureka-ha-server + + + + UTF-8 + 1.8 + 1.8 + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-server + + + + org.springframework.boot + spring-boot-starter-security + + + + + + + + maven-clean-plugin + 3.0.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.7.0 + + + maven-surefire-plugin + 2.20.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + + diff --git a/eureka/eureka-ha/eureka-ha-server/src/main/java/kite/springcloud/eureka/ha/server/Application.java b/eureka/eureka-ha/eureka-ha-server/src/main/java/kite/springcloud/eureka/ha/server/Application.java new file mode 100644 index 0000000..188c6ee --- /dev/null +++ b/eureka/eureka-ha/eureka-ha-server/src/main/java/kite/springcloud/eureka/ha/server/Application.java @@ -0,0 +1,33 @@ +package kite.springcloud.eureka.ha.server; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +/** + * kite.Application + * + * @author fengzheng + * @date 2018/9/18 + */ + +@EnableEurekaServer +@SpringBootApplication +public class Application { + + @EnableWebSecurity + static class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().ignoringAntMatchers("/eureka/**"); + } + } + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/eureka/eureka-ha/eureka-ha-server/src/main/resources/application.yml b/eureka/eureka-ha/eureka-ha-server/src/main/resources/application.yml new file mode 100644 index 0000000..ea47d5b --- /dev/null +++ b/eureka/eureka-ha/eureka-ha-server/src/main/resources/application.yml @@ -0,0 +1,32 @@ +spring: + profiles: eureka-center1 +server: + port: 1989 +eureka: + instance: + hostname: ha-eureak-center1 + appname: 注册中心 + client: + registerWithEureka: true + fetchRegistry: true + serviceUrl: + defaultZone: http://localhost:1988/eureka + + +--- +spring: + profiles: eureka-center2 +server: + port: 1988 +eureka: + instance: + hostname: ha-eureak-center2 + appname: 注册中心 + client: + registerWithEureka: true + fetchRegistry: true + serviceUrl: + defaultZone: http://localhost:1989/eureka + + + diff --git a/eureka/eureka-ha/eureka-ha-server/src/main/resources/bootstrap.yml b/eureka/eureka-ha/eureka-ha-server/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..2e28fc9 --- /dev/null +++ b/eureka/eureka-ha/eureka-ha-server/src/main/resources/bootstrap.yml @@ -0,0 +1,11 @@ +spring: + application: + name: eureka-ha-center + cloud: + inetutils: + ignoredInterfaces: + - docker0 + - veth.* + - VM.* + preferredNetworks: + - 192.168 diff --git a/eureka/eureka-ha/pom.xml b/eureka/eureka-ha/pom.xml new file mode 100644 index 0000000..2b1280a --- /dev/null +++ b/eureka/eureka-ha/pom.xml @@ -0,0 +1,22 @@ + + + + eureka + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + eureka-ha + pom + + eureka-ha-server + eureka-ha-provider + eureka-ha-customer + + + + \ No newline at end of file diff --git a/eureka/eureka-single/eureka-single-customer/pom.xml b/eureka/eureka-single/eureka-single-customer/pom.xml new file mode 100644 index 0000000..906355a --- /dev/null +++ b/eureka/eureka-single/eureka-single-customer/pom.xml @@ -0,0 +1,89 @@ + + + + + eureka-single + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + eureka-single-customer + jar + + eureka-single-customer + + + UTF-8 + 1.8 + 1.8 + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + + + + + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + + + maven-clean-plugin + 3.0.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.7.0 + + + maven-surefire-plugin + 2.20.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + + diff --git a/eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/SingleCustomerApplication.java b/eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/SingleCustomerApplication.java new file mode 100644 index 0000000..c15c5a6 --- /dev/null +++ b/eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/SingleCustomerApplication.java @@ -0,0 +1,34 @@ +package kite.springcloud.eureka.single.customer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.cloud.netflix.eureka.EnableEurekaClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; + +/** + * @Author fengzheng + * SingleCustomerApplication + */ +@SpringBootApplication +@EnableEurekaClient +@EnableFeignClients +public class SingleCustomerApplication { + + /** + * 注入 RestTemplate + * 并用 @LoadBalanced 注解,用负载均衡策略请求服务提供者 + * @return + */ + @LoadBalanced + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } + + public static void main(String[] args) { + SpringApplication.run(SingleCustomerApplication.class, args); + } +} diff --git a/eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/aop/SimplePerformanceMonitor.java b/eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/aop/SimplePerformanceMonitor.java new file mode 100644 index 0000000..301f8fe --- /dev/null +++ b/eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/aop/SimplePerformanceMonitor.java @@ -0,0 +1,50 @@ +package kite.springcloud.eureka.single.customer.aop; + +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.stereotype.Component; + +/** + * SimplePerformanceMonitor + * + * @author fengzheng + * @date 2019/3/14 + */ +@Aspect +@Component +@Slf4j +public class SimplePerformanceMonitor { + + @Pointcut("within(kite.springcloud.eureka.single.customer..*)") + public void logTime(){ + + } + + @Around("logTime()") + public Object timeAround(ProceedingJoinPoint joinPoint) { + // 定义返回对象、得到方法需要的参数 + Object obj = null; + Object[] args = joinPoint.getArgs(); + long startTime = System.currentTimeMillis(); + + try { + obj = joinPoint.proceed(args); + } catch (Throwable e) { + e.printStackTrace(); + log.error("统计某方法执行耗时环绕通知出错", e); + } + + // 获取执行的方法名 + long endTime = System.currentTimeMillis(); + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + String methodName = signature.getDeclaringTypeName() + "." + signature.getName(); + + // 打印耗时的信息 + log.info(String.format("「%s」执行时间为:%d ms",methodName, endTime - startTime)); + return obj; + } +} diff --git a/eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/conf/WebSecurityConfig.java b/eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/conf/WebSecurityConfig.java new file mode 100755 index 0000000..300bddb --- /dev/null +++ b/eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/conf/WebSecurityConfig.java @@ -0,0 +1,43 @@ +//package kite.springcloud.eurek.single.customer.conf; +// +//import org.springframework.beans.factory.annotation.Value; +//import org.springframework.context.annotation.Bean; +//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +//import org.springframework.security.config.annotation.web.builders.HttpSecurity; +//import org.springframework.security.config.annotation.web.builders.WebSecurity; +//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +// +///** +// * 开启 security 时才需要 +// */ +//@EnableWebSecurity +//class WebSecurityConfig extends WebSecurityConfigurerAdapter { +// +// @Value("${spring.security.user.name}") +// private String userName; +// @Value("${spring.security.user.password}") +// private String password; +// @Bean +// public BCryptPasswordEncoder passwordEncoder() { +// return new BCryptPasswordEncoder(); +// } +// +// +// @Override +// protected void configure(AuthenticationManagerBuilder auth) throws Exception { +// auth.inMemoryAuthentication().withUser(userName).password(passwordEncoder().encode(password)).roles("ADMIN"); +// } +// +// @Override +// public void configure(WebSecurity web) throws Exception { +// super.configure(web); +// } +// +// @Override +// protected void configure(HttpSecurity http) throws Exception { +// http.csrf().ignoringAntMatchers("/eureka/**"); +// super.configure(http); +// } +//} diff --git a/eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/controller/ConsumerController.java b/eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/controller/ConsumerController.java new file mode 100644 index 0000000..68d0319 --- /dev/null +++ b/eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/controller/ConsumerController.java @@ -0,0 +1,49 @@ +package kite.springcloud.eureka.single.customer.controller; + +import kite.springcloud.eureka.single.customer.service.IHelloService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + + + +/** + * ConsumerController + * + * @author fengzheng + * @date 2018/9/25 + */ +@RestController +public class ConsumerController { + + @Autowired + private RestTemplate restTemplate; + + @Autowired + private IHelloService helloService; + + private static final String applicationName = "single-provider"; + + @RequestMapping(value = "feignRequest") + public Object feignRequest(){ + + String s = helloService.nice(); + return s; + } + + @RequestMapping(value = "commonRequest") + public Object commonRequest(){ + String url = "http://"+ applicationName +"/hello"; + String s = restTemplate.getForObject(url,String.class); + return s; + } + + + @GetMapping(value = "donothing") + public String donothing(){ + return "hello eureka!"; + } + +} diff --git a/eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/service/IHelloService.java b/eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/service/IHelloService.java new file mode 100644 index 0000000..bf48c16 --- /dev/null +++ b/eureka/eureka-single/eureka-single-customer/src/main/java/kite/springcloud/eureka/single/customer/service/IHelloService.java @@ -0,0 +1,20 @@ +package kite.springcloud.eureka.single.customer.service; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * IHelloService + * 配置服务提供者:single-provider 是服务提供者的 application.name + * @author fengzheng + * @date 2018/9/26 + */ +@FeignClient("single-provider") +public interface IHelloService { + + @RequestMapping(value = "/hello") + String hello(); + + @RequestMapping(value = "nice") + String nice(); +} diff --git a/eureka/eureka-single/eureka-single-customer/src/main/resources/application.yml b/eureka/eureka-single/eureka-single-customer/src/main/resources/application.yml new file mode 100644 index 0000000..1d778bb --- /dev/null +++ b/eureka/eureka-single/eureka-single-customer/src/main/resources/application.yml @@ -0,0 +1,16 @@ +server: + port: 3002 +eureka: + client: + serviceUrl: + register-with-eureka: true + fetch-registry: true + defaultZone: http://test:123456@localhost:3000/eureka/ + instance: + preferIpAddress: true +spring: + application: + name: single-customer +feign: + okhttp: + enabled: true \ No newline at end of file diff --git a/eureka/eureka-single/eureka-single-provider/pom.xml b/eureka/eureka-single/eureka-single-provider/pom.xml new file mode 100644 index 0000000..abf179c --- /dev/null +++ b/eureka/eureka-single/eureka-single-provider/pom.xml @@ -0,0 +1,37 @@ + + + + eureka-single + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + eureka-single-provider + jar + + + UTF-8 + 1.8 + 1.8 + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + + + \ No newline at end of file diff --git a/eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/.DS_Store b/eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f22cc162129e8fa0ae857389ef4c2477dc8c0de2 GIT binary patch literal 8196 zcmeI1U2GLa6vxjg1!fntTP)H=F1=Ea0tIeMkq-fHzl1`ugkESV(97PtBVFC@UUv81 zR*OiWCa_+TO`iN=ITjGE|!zW8V~nE0e;cD5Dz@!*4E!fvv2 zX6BqTv-_Xl?sjeg09%S?13)zZFgk_RW>GQ8A^hT;aFj(oS^U5G!y~Dj?nuNjim1M|MQo@YO*@xCJ09 zwgBNlb=n7nImyVTBRe8(m`Y>H-2+Cc7;Q07rjtJ@!pWv1J0h)22bAf6(aad_P%xaG z@{(aVU|QO^j1`C#n5ckwd>9nK0~boy?%#8^ndAeH(C%chl2pD~ju>MT`J zE7XJC1MX0FU<5_K#qjov)-EF$$QfQ%ThMKpoN7Im84P5&({A$;ce=bzBj7SLJ1VM#jv7sC*B(EvFn#Ho-Te=qIQ7!$GjF{4*4rP4Nr2J21S(~Fth`9I z38L73sa1+n_Tprs=pEbD&a5`4M7Ppa2rSp}_j1oCo7F0OQl}&DI=ehB{5^TsE)F_= zR;$b#cD`tnF3q;xZ5`!)Z@`BGQS0+vFK7(|vzk`)`EE{eR*AP!wBKvda3V}Y<=pJK ziA8sWYP zxk=r^DzRSa&AWqxbU(iAZq{3wc8T?ixjPL%=qhlBrVsC~M&HWVKH+ILO>VN9NhgJ05*#-yb*Q^4Zgs0&YJOiiUbvO_2!iVq~T!PQx3%Cs5!H@7W{0hIp zRrnqLM1~5^!r7?fBCN&5n8FRX5jWvxY{4DaiT7g{X7C{P;~_NgFc$C#`WWCN_$WSx zPvTSfJf6Xq@fCa(-@*6s1H6D2@e}+Kzrri>`pQPJ-5FhPWbk{cOonYC!nS`hY!mJG zsoQQ0w%^VctX9sst!nPV+PamE>ozryE$6ruycVXA9|=eZ&L|k+GG0$3t-C(|4mGid z_~OIkpM+7?wV8q>CMeNsl8J;S5R%QsOQ=~!l*{I_P#mDgpd={T09$z3H&*E$2=<66q-}%YtD|LI0?K+3aH%jgGX>seuDKJe=T`l(i z?Nk5$f8#DNo;g+^R^VS(0L$CD+gfOvsb0}yubrgx5S`)>aU;@(DO89M(I0Nd$&UTQ ikm||EmyYa+wB(`VKmQ@%@4tlO?|=OL4;j1}i@yMG(E+Rg literal 0 HcmV?d00001 diff --git a/eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/.DS_Store b/eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c569d7ef7b4436a25b2d5c259f90659caa1b7aae GIT binary patch literal 6148 zcmeHKJ8r`;3?&;6M!RIps4MgaLXe)I7YJf!Gh(2h-BZt%qxJDK#4rkUNEYMKpq@nY zNzfZiQ$%$C-M@-#MWlrr%8w08v-jo;d&-Cc;n?FtMj7y&G5enx_gOmdF7kED??1cY zG>(HM(5L_vpaN8Y3Q&Q&DUhYLeYx9?+=vQLfwd@L--iM>tcg>ge>yOD3jk~ocEj9z z31G1RuqIA{h`=Dr;FA=j#PjO%oW(g za%=Vf4gN>}KPPcT1*pKP6wv1Ie%RwmSz8yEvszo=N4Vu&;bxdS1%sDkpqFDTtQ_w= cDe{WV@xCTbflf!<=|KJrm@YIb@Mr~o0SBNJzW@LL literal 0 HcmV?d00001 diff --git a/eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/SingleProviderApplication.java b/eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/SingleProviderApplication.java new file mode 100644 index 0000000..aca0806 --- /dev/null +++ b/eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/SingleProviderApplication.java @@ -0,0 +1,21 @@ +package kite.springcloud.eureka.single.provider; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.eureka.EnableEurekaClient; + +/** + * SingleProviderApplication + * + * @author fengzheng + * @date 2018/11/20 + */ +@EnableEurekaClient +@SpringBootApplication +public class SingleProviderApplication { + + public static void main(String[] args) { + SpringApplication.run(SingleProviderApplication.class, args); + } +} diff --git a/eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/aop/SimplePerformanceMonitor.java b/eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/aop/SimplePerformanceMonitor.java new file mode 100644 index 0000000..183b382 --- /dev/null +++ b/eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/aop/SimplePerformanceMonitor.java @@ -0,0 +1,50 @@ +package kite.springcloud.eureka.single.provider.aop; + +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.stereotype.Component; + +/** + * SimplePerformanceMonitor + * + * @author fengzheng + * @date 2019/3/14 + */ +@Aspect +@Component +@Slf4j +public class SimplePerformanceMonitor { + + @Pointcut("within(kite.springcloud.eureka.single.provider..*)") + public void logTime(){ + + } + + @Around("logTime()") + public Object timeAround(ProceedingJoinPoint joinPoint) { + // 定义返回对象、得到方法需要的参数 + Object obj = null; + Object[] args = joinPoint.getArgs(); + long startTime = System.currentTimeMillis(); + + try { + obj = joinPoint.proceed(args); + } catch (Throwable e) { + e.printStackTrace(); + log.error("统计某方法执行耗时环绕通知出错", e); + } + + // 获取执行的方法名 + long endTime = System.currentTimeMillis(); + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + String methodName = signature.getDeclaringTypeName() + "." + signature.getName(); + + // 打印耗时的信息 + log.info(String.format("「%s」执行时间为:%d ms",methodName, endTime - startTime)); + return obj; + } +} diff --git a/eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/conf/WebSecurityConfig.java b/eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/conf/WebSecurityConfig.java new file mode 100755 index 0000000..7be09e3 --- /dev/null +++ b/eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/conf/WebSecurityConfig.java @@ -0,0 +1,43 @@ +//package kite.springcloud.eureka.single.provider.conf; +// +//import org.springframework.beans.factory.annotation.Value; +//import org.springframework.context.annotation.Bean; +//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +//import org.springframework.security.config.annotation.web.builders.HttpSecurity; +//import org.springframework.security.config.annotation.web.builders.WebSecurity; +//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +// +///** +// * 开启 security 时才需要 +// */ +//@EnableWebSecurity +//class WebSecurityConfig extends WebSecurityConfigurerAdapter { +// +// @Value("${spring.security.user.name}") +// private String userName; +// @Value("${spring.security.user.password}") +// private String password; +// @Bean +// public BCryptPasswordEncoder passwordEncoder() { +// return new BCryptPasswordEncoder(); +// } +// +// +// @Override +// protected void configure(AuthenticationManagerBuilder auth) throws Exception { +// auth.inMemoryAuthentication().withUser(userName).password(passwordEncoder().encode(password)).roles("ADMIN"); +// } +// +// @Override +// public void configure(WebSecurity web) throws Exception { +// super.configure(web); +// } +// +// @Override +// protected void configure(HttpSecurity http) throws Exception { +// http.csrf().ignoringAntMatchers("/eureka/**"); +// super.configure(http); +// } +//} diff --git a/eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/controller/.DS_Store b/eureka/eureka-single/eureka-single-provider/src/main/java/kite/springcloud/eureka/single/provider/controller/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 services = discoveryClient.getServices(); + for(String s : services){ + log.info(s); + } + return "hello spring cloud!"; + } + + @RequestMapping(value = "/nice") + public String nice(){ + List services = discoveryClient.getServices(); + for(String s : services){ + log.info("gogogo" + s); + } + return "nice to meet you!"; + } + +} diff --git a/eureka/eureka-single/eureka-single-provider/src/main/resources/application.yml b/eureka/eureka-single/eureka-single-provider/src/main/resources/application.yml new file mode 100644 index 0000000..0c08bcd --- /dev/null +++ b/eureka/eureka-single/eureka-single-provider/src/main/resources/application.yml @@ -0,0 +1,23 @@ +server: + port: 3001 + +#eureka: +# instance: +# preferIpAddress: true +# client: +# serviceUrl: +# defaultZone: http://test:123456@localhost:3000/eureka + +eureka: + instance: + statusPageUrlPath: /actuator/info + healthCheckUrlPath: /actuator/health + prefer-ip-address: true + client: + register-with-eureka: true + fetch-registry: true + service-url: + defaultZone: http://test:123456@localhost:3000/eureka/ +spring: + application: + name: single-provider \ No newline at end of file diff --git a/eureka/eureka-single/eureka-single-server/pom.xml b/eureka/eureka-single/eureka-single-server/pom.xml new file mode 100644 index 0000000..4bccb8d --- /dev/null +++ b/eureka/eureka-single/eureka-single-server/pom.xml @@ -0,0 +1,80 @@ + + + + + eureka-single + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + eureka-single-server + jar + + eureka-single-server + + + UTF-8 + 1.8 + 1.8 + + + + + + + + + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-server + + + + org.springframework.boot + spring-boot-starter-security + + + + + + + + + maven-clean-plugin + 3.0.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.7.0 + + + maven-surefire-plugin + 2.20.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + + diff --git a/eureka/eureka-single/eureka-single-server/src/main/java/kite/springcloud/eureka/single/server/Application.java b/eureka/eureka-single/eureka-single-server/src/main/java/kite/springcloud/eureka/single/server/Application.java new file mode 100644 index 0000000..8552711 --- /dev/null +++ b/eureka/eureka-single/eureka-single-server/src/main/java/kite/springcloud/eureka/single/server/Application.java @@ -0,0 +1,21 @@ +package kite.springcloud.eureka.single.server; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; + + +/** + * Application + * + * @author fengzheng + * @date 2018/11/20 + */ +@EnableEurekaServer +@SpringBootApplication +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/eureka/eureka-single/eureka-single-server/src/main/java/kite/springcloud/eureka/single/server/conf/WebSecurityConfig.java b/eureka/eureka-single/eureka-single-server/src/main/java/kite/springcloud/eureka/single/server/conf/WebSecurityConfig.java new file mode 100755 index 0000000..1cad84a --- /dev/null +++ b/eureka/eureka-single/eureka-single-server/src/main/java/kite/springcloud/eureka/single/server/conf/WebSecurityConfig.java @@ -0,0 +1,43 @@ +package kite.springcloud.eureka.single.server.conf; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.builders.WebSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +/** + * 开启 security 时才需要 + */ +@EnableWebSecurity +class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Value("${spring.security.user.name}") + private String userName; + @Value("${spring.security.user.password}") + private String password; + @Bean + public BCryptPasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } + + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.inMemoryAuthentication().withUser(userName).password(passwordEncoder().encode(password)).roles("ADMIN"); + } + + @Override + public void configure(WebSecurity web) throws Exception { + super.configure(web); + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().ignoringAntMatchers("/eureka/**"); + super.configure(http); + } +} diff --git a/eureka/eureka-single/eureka-single-server/src/main/resources/application.yml b/eureka/eureka-single/eureka-single-server/src/main/resources/application.yml new file mode 100644 index 0000000..3085f3b --- /dev/null +++ b/eureka/eureka-single/eureka-single-server/src/main/resources/application.yml @@ -0,0 +1,18 @@ +server: + port: 3000 +eureka: + instance: + hostname: eureka-center + appname: 注册中心 + client: + registerWithEureka: false # 单点的时候设置为 false 禁止注册自身 + fetchRegistry: false + serviceUrl: + defaultZone: http://test:123456@localhost:3000/eureka + server: + enableSelfPreservation: false + evictionIntervalTimerInMs: 4000 + + + + diff --git a/eureka/eureka-single/eureka-single-server/src/main/resources/bootstrap.yml b/eureka/eureka-single/eureka-single-server/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..cf65967 --- /dev/null +++ b/eureka/eureka-single/eureka-single-server/src/main/resources/bootstrap.yml @@ -0,0 +1,15 @@ +spring: + application: + name: kite-eureka-center + security: + user: + name: test # 用户名 + password: 123456 # 密码 + cloud: + inetutils: ## 网卡设置 + ignoredInterfaces: ## 忽略的网卡 + - docker0 + - veth.* + - VM.* + preferredNetworks: ## 优先的网段 + - 192.168 diff --git a/eureka/eureka-single/pom.xml b/eureka/eureka-single/pom.xml new file mode 100644 index 0000000..f7c5ef3 --- /dev/null +++ b/eureka/eureka-single/pom.xml @@ -0,0 +1,23 @@ + + + + eureka + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + eureka-single + pom + + eureka-single-server + eureka-single-provider + eureka-single-customer + + + + + \ No newline at end of file diff --git a/eureka/pom.xml b/eureka/pom.xml new file mode 100644 index 0000000..c6f1d6c --- /dev/null +++ b/eureka/pom.xml @@ -0,0 +1,77 @@ + + + + + parent + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + eureka + pom + + eureka + + + eureka-single + eureka-ha + + + + UTF-8 + 1.8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-actuator + + + junit + junit + 4.11 + test + + + + + + + + maven-clean-plugin + 3.0.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.7.0 + + + maven-surefire-plugin + 2.20.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..a10313a --- /dev/null +++ b/pom.xml @@ -0,0 +1,78 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.1.3.RELEASE + + + kite.springcloud + parent + pom + 1.0-SNAPSHOT + + eureka + consul + stream + common + docker + sleuth + actuator + admin + config + + + + + org.projectlombok + lombok + 1.18.2 + provided + + + + + + + + org.springframework.cloud + spring-cloud-dependencies + Finchley.SR2 + pom + import + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/libs-snapshot + + true + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.8 + 1.8 + UTF-8 + + + + + + + \ No newline at end of file diff --git a/sleuth/pom.xml b/sleuth/pom.xml new file mode 100644 index 0000000..f630f02 --- /dev/null +++ b/sleuth/pom.xml @@ -0,0 +1,87 @@ + + + + + parent + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + sleuth + + sleuth + + + UTF-8 + 1.8 + 1.8 + + + + + org.springframework.cloud + spring-cloud-starter-sleuth + + + + org.springframework.boot + spring-boot-starter-web + + + + junit + junit + 4.11 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/sleuth/src/main/java/kite/springcloud/sleuth/SleuthApplication.java b/sleuth/src/main/java/kite/springcloud/sleuth/SleuthApplication.java new file mode 100644 index 0000000..e836fc9 --- /dev/null +++ b/sleuth/src/main/java/kite/springcloud/sleuth/SleuthApplication.java @@ -0,0 +1,16 @@ +package kite.springcloud.sleuth; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Sleuth 启动类 + */ +@SpringBootApplication +public class SleuthApplication { + + public static void main(String[] args) { + SpringApplication.run(SleuthApplication.class, args); + } +} diff --git a/sleuth/src/main/java/kite/springcloud/sleuth/controller/SleuthController.java b/sleuth/src/main/java/kite/springcloud/sleuth/controller/SleuthController.java new file mode 100644 index 0000000..7164ec1 --- /dev/null +++ b/sleuth/src/main/java/kite/springcloud/sleuth/controller/SleuthController.java @@ -0,0 +1,19 @@ +package kite.springcloud.sleuth.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * SleuthController + * + * @author fengzheng + * @date 2019/3/17 + */ +@RestController +public class SleuthController { + + @GetMapping(value = "sleuth") + public String say(String value){ + return "hello sleuth " + value; + } +} diff --git a/sleuth/src/main/resources/application.yml b/sleuth/src/main/resources/application.yml new file mode 100644 index 0000000..f6b6a63 --- /dev/null +++ b/sleuth/src/main/resources/application.yml @@ -0,0 +1,5 @@ +server: + port: 3101 +spring: + application: + name: sleuth-application \ No newline at end of file diff --git a/sleuth/src/test/java/kite/springcloud/AppTest.java b/sleuth/src/test/java/kite/springcloud/AppTest.java new file mode 100644 index 0000000..03cc220 --- /dev/null +++ b/sleuth/src/test/java/kite/springcloud/AppTest.java @@ -0,0 +1,20 @@ +package kite.springcloud; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/stream/pom.xml b/stream/pom.xml new file mode 100644 index 0000000..922677c --- /dev/null +++ b/stream/pom.xml @@ -0,0 +1,34 @@ + + + + parent + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + kite.springcloud + stream + pom + + stream-rabbit-producer + stream-rabbit-customer + stream-rabbit-customer-another + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/stream/stream-rabbit-customer/pom.xml b/stream/stream-rabbit-customer/pom.xml new file mode 100644 index 0000000..8321cc6 --- /dev/null +++ b/stream/stream-rabbit-customer/pom.xml @@ -0,0 +1,73 @@ + + + + + stream + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + + stream-rabbit-customer + jar + + stream-rabbit-customer + + + UTF-8 + 1.8 + 1.8 + + + + + org.springframework.cloud + spring-cloud-starter-stream-rabbit + + + + kite.springcloud + common + 1.0-SNAPSHOT + compile + + + + + + + + maven-clean-plugin + 3.0.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.7.0 + + + maven-surefire-plugin + 2.20.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + + diff --git a/stream/stream-rabbit-customer/src/main/java/kite/springcloud/stream/rabbit/customer/CustomerApplication.java b/stream/stream-rabbit-customer/src/main/java/kite/springcloud/stream/rabbit/customer/CustomerApplication.java new file mode 100644 index 0000000..0762a68 --- /dev/null +++ b/stream/stream-rabbit-customer/src/main/java/kite/springcloud/stream/rabbit/customer/CustomerApplication.java @@ -0,0 +1,28 @@ +package kite.springcloud.stream.rabbit.customer; + +import kite.springcloud.common.stream.MyProcessor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.cloud.stream.annotation.StreamListener; +import org.springframework.cloud.stream.messaging.Processor; +import org.springframework.cloud.stream.messaging.Sink; +import org.springframework.messaging.handler.annotation.SendTo; + +/** + * CustomerApplication + * + * @author fengzheng + * @date 2018/12/12 + */ +@SpringBootApplication +@EnableBinding(value = {MyProcessor.class}) +@Slf4j +public class CustomerApplication { + + public static void main(String[] args) { + SpringApplication.run(CustomerApplication.class, args); + } + +} diff --git a/stream/stream-rabbit-customer/src/main/java/kite/springcloud/stream/rabbit/customer/DefaultApplication.java b/stream/stream-rabbit-customer/src/main/java/kite/springcloud/stream/rabbit/customer/DefaultApplication.java new file mode 100644 index 0000000..d35c6f3 --- /dev/null +++ b/stream/stream-rabbit-customer/src/main/java/kite/springcloud/stream/rabbit/customer/DefaultApplication.java @@ -0,0 +1,26 @@ +package kite.springcloud.stream.rabbit.customer; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.cloud.stream.annotation.StreamListener; +import org.springframework.cloud.stream.messaging.Processor; + +/** + * DefaultApplication + * + * @author fengzheng + * @date 2018/12/24 + */ +@SpringBootApplication +@EnableBinding(value = {Processor.class}) +@Slf4j +public class DefaultApplication { + + public static void main(String[] args) { + SpringApplication.run(DefaultApplication.class, args); + } + + +} diff --git a/stream/stream-rabbit-customer/src/main/java/kite/springcloud/stream/rabbit/customer/service/DefaultMessageListener.java b/stream/stream-rabbit-customer/src/main/java/kite/springcloud/stream/rabbit/customer/service/DefaultMessageListener.java new file mode 100644 index 0000000..35db92d --- /dev/null +++ b/stream/stream-rabbit-customer/src/main/java/kite/springcloud/stream/rabbit/customer/service/DefaultMessageListener.java @@ -0,0 +1,23 @@ +package kite.springcloud.stream.rabbit.customer.service; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.cloud.stream.annotation.StreamListener; +import org.springframework.cloud.stream.messaging.Processor; +import org.springframework.stereotype.Component; + +/** + * DefaultMessageListener + * + * @author fengzheng + * @date 2018/12/25 + */ +@Slf4j +@Component +public class DefaultMessageListener { + + @StreamListener(Processor.INPUT) + public void processMyMessage(String message) { + log.info("接收到消息:" + message); + } + +} diff --git a/stream/stream-rabbit-customer/src/main/java/kite/springcloud/stream/rabbit/customer/service/LogMessageListener.java b/stream/stream-rabbit-customer/src/main/java/kite/springcloud/stream/rabbit/customer/service/LogMessageListener.java new file mode 100644 index 0000000..4a6be59 --- /dev/null +++ b/stream/stream-rabbit-customer/src/main/java/kite/springcloud/stream/rabbit/customer/service/LogMessageListener.java @@ -0,0 +1,50 @@ +package kite.springcloud.stream.rabbit.customer.service; + +import kite.springcloud.common.stream.LogInfo; +import kite.springcloud.common.stream.MyProcessor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.cloud.stream.annotation.StreamListener; +import org.springframework.messaging.handler.annotation.SendTo; +import org.springframework.stereotype.Component; + +/** + * LogMessageListener + * + * @author fengzheng + * @date 2018/12/26 + */ +@Slf4j +@Component +public class LogMessageListener { + + /** + * 通过 MyProcessor.MESSAGE_INPUT 接收消息 + * 然后通过 SendTo 将处理后的消息发送到 MyProcessor.LOG_FORMAT_OUTPUT + * @param message + * @return + */ + @StreamListener(MyProcessor.MESSAGE_INPUT) + @SendTo(MyProcessor.LOG_FORMAT_OUTPUT) + public String processLogMessage(String message) { + log.info("接收到原始消息:" + message); + return "「" + message +"」"; + } + +// @StreamListener(MyProcessor.MESSAGE_INPUT) +// @SendTo(MyProcessor.LOG_FORMAT_OUTPUT) +// public String processObjectLogMessage(LogInfo logInfo) { +// log.info("接收到原始 object 消息:" + logInfo.toString()); +// return "「" + logInfo.toString() +"」"; +// } + + /** + * 接收来自 MyProcessor.LOG_FORMAT_INPUT 的消息 + * 也就是加工后的消息,也就是通过上面的 SendTo 发送来的 + * 因为 MyProcessor.LOG_FORMAT_OUTPUT 和 MyProcessor.LOG_FORMAT_INPUT 是指向同一 exchange + * @param message + */ + @StreamListener(MyProcessor.LOG_FORMAT_INPUT) + public void processFormatLogMessage(String message) { + log.info("接收到格式化后的消息:" + message); + } +} diff --git a/stream/stream-rabbit-customer/src/main/resources/application.yml b/stream/stream-rabbit-customer/src/main/resources/application.yml new file mode 100644 index 0000000..dcd25d2 --- /dev/null +++ b/stream/stream-rabbit-customer/src/main/resources/application.yml @@ -0,0 +1,84 @@ +spring: + profiles: + active: stream-rabbit-customer-group1 + +--- +spring: + profiles: stream-rabbit-customer-group1 + cloud: + stream: + bindings: +# input: +# destination: default.messages +# binder: local_rabbit +# output: +# destination: default.messages +# binder: local_rabbit + log_input: + destination: kite.log.messages + binder: local_rabbit + group: logConsumer-group1 + log_output: + destination: kite.log.messages + binder: local_rabbit + group: logConsumer-group1 + log_format_input: + destination: kite.log.format.messages + binder: local_rabbit + group: logFormat-group1 + log_format_output: + destination: kite.log.format.messages + binder: local_rabbit + group: logFormat-group1 + binders: + local_rabbit: + type: rabbit + environment: + spring: + rabbitmq: + host: localhost + port: 32775 + username: guest + password: guest +server: + port: 8201 + +--- +spring: + profiles: stream-rabbit-customer-group2 + cloud: + stream: + bindings: +# input: +# destination: default.messages +# binder: local_rabbit +# output: +# destination: default.messages +# binder: local_rabbit + log_input: + destination: kite.log.messages + binder: local_rabbit + group: logConsumer-group2 + log_output: + destination: kite.log.messages + binder: local_rabbit + log_format_input: + destination: kite.log.format.messages + binder: local_rabbit + group: logFormat-group1 + log_format_output: + destination: kite.log.format.messages + binder: local_rabbit + group: logFormat-group1 + binders: + local_rabbit: + type: rabbit + environment: + spring: + rabbitmq: + host: localhost + port: 32775 + username: guest + password: guest +server: + port: 8203 diff --git a/stream/stream-rabbit-producer/pom.xml b/stream/stream-rabbit-producer/pom.xml new file mode 100644 index 0000000..218c5de --- /dev/null +++ b/stream/stream-rabbit-producer/pom.xml @@ -0,0 +1,72 @@ + + + + + stream + kite.springcloud + 1.0-SNAPSHOT + + 4.0.0 + + + stream-rabbit-producer + jar + stream-rabbit-producer + + + UTF-8 + 1.8 + 1.8 + + + + + org.springframework.cloud + spring-cloud-starter-stream-rabbit + + + kite.springcloud + common + 1.0-SNAPSHOT + compile + + + + + + + + + maven-clean-plugin + 3.0.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.7.0 + + + maven-surefire-plugin + 2.20.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + + diff --git a/stream/stream-rabbit-producer/src/main/java/kite/springcloud/stream/rabbit/producer/ProducerApplication.java b/stream/stream-rabbit-producer/src/main/java/kite/springcloud/stream/rabbit/producer/ProducerApplication.java new file mode 100644 index 0000000..f3542b9 --- /dev/null +++ b/stream/stream-rabbit-producer/src/main/java/kite/springcloud/stream/rabbit/producer/ProducerApplication.java @@ -0,0 +1,26 @@ +package kite.springcloud.stream.rabbit.producer; + +import kite.springcloud.common.stream.MyProcessor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.cloud.stream.messaging.Processor; +import org.springframework.cloud.stream.messaging.Source; + +/** + * ProducerApplication + * + * @author fengzheng + * @date 2018/12/12 + */ + +@SpringBootApplication +@EnableBinding(value = { MyProcessor.class}) +@Slf4j +public class ProducerApplication { + + public static void main(String[] args) { + SpringApplication.run(ProducerApplication.class, args); + } +} diff --git a/stream/stream-rabbit-producer/src/main/java/kite/springcloud/stream/rabbit/producer/controller/MyMessageController.java b/stream/stream-rabbit-producer/src/main/java/kite/springcloud/stream/rabbit/producer/controller/MyMessageController.java new file mode 100644 index 0000000..45ea8bb --- /dev/null +++ b/stream/stream-rabbit-producer/src/main/java/kite/springcloud/stream/rabbit/producer/controller/MyMessageController.java @@ -0,0 +1,46 @@ +package kite.springcloud.stream.rabbit.producer.controller; + +import kite.springcloud.common.stream.LogInfo; +import kite.springcloud.common.stream.MyProcessor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.messaging.Message; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.time.Instant; +import java.time.LocalTime; +import java.util.Date; + +/** + * MyMessageController + * + * @author fengzheng + * @date 2018/12/14 + */ +@Slf4j +@RestController +@EnableBinding(value = {MyProcessor.class}) +public class MyMessageController { + + @Autowired + private MyProcessor myProcessor; + + @GetMapping(value = "sendLogMessage") + public void sendLogMessage(String message){ + Message stringMessage = org.springframework.messaging.support.MessageBuilder.withPayload(message).build(); + myProcessor.logOutput().send(stringMessage); + } + + @GetMapping(value = "sendObjectLogMessage") + public void sendObjectLogMessage(){ + LogInfo logInfo = new LogInfo(); + logInfo.setClientIp("192.168.1.111"); + logInfo.setClientVersion("1.0"); + logInfo.setUserId("198663383837434"); + logInfo.setTime(Date.from(Instant.now())); + Message stringMessage = org.springframework.messaging.support.MessageBuilder.withPayload(logInfo).build(); + myProcessor.logOutput().send(stringMessage); + } +} diff --git a/stream/stream-rabbit-producer/src/main/resources/application.yml b/stream/stream-rabbit-producer/src/main/resources/application.yml new file mode 100644 index 0000000..2349fb6 --- /dev/null +++ b/stream/stream-rabbit-producer/src/main/resources/application.yml @@ -0,0 +1,21 @@ +spring: + cloud: + stream: + bindings: + log_output: + destination: kite.log.messages + binder: local_rabbit + group: logConsumer-group1 + binders: + local_rabbit: + type: rabbit + environment: + spring: + rabbitmq: + host: localhost + port: 32775 + username: guest + password: guest +server: + port: 8202 +