From 585010de82feeaecb976ad51ce7a7f1d855da867 Mon Sep 17 00:00:00 2001 From: andrewshan Date: Mon, 10 Jan 2022 16:35:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81eureka=E7=9A=84?= =?UTF-8?q?=E6=A0=B7=E4=BE=8B=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eureka/eureka-java/.gitignore | 46 +++++++++++++++ eureka/eureka-java/consumer/pom.xml | 55 ++++++++++++++++++ .../examples/eureka/consumer/Config.java | 16 ++++++ .../consumer/EurekaConsumerApplication.java | 38 +++++++++++++ .../src/main/resources/application.yml | 11 ++++ eureka/eureka-java/pom.xml | 21 +++++++ eureka/eureka-java/provider/pom.xml | 56 +++++++++++++++++++ .../provider/EurekaProviderApplication.java | 23 ++++++++ .../src/main/resources/application.yml | 11 ++++ 9 files changed, 277 insertions(+) create mode 100644 eureka/eureka-java/.gitignore create mode 100644 eureka/eureka-java/consumer/pom.xml create mode 100644 eureka/eureka-java/consumer/src/main/java/cn/polarismesh/examples/eureka/consumer/Config.java create mode 100644 eureka/eureka-java/consumer/src/main/java/cn/polarismesh/examples/eureka/consumer/EurekaConsumerApplication.java create mode 100644 eureka/eureka-java/consumer/src/main/resources/application.yml create mode 100644 eureka/eureka-java/pom.xml create mode 100644 eureka/eureka-java/provider/pom.xml create mode 100644 eureka/eureka-java/provider/src/main/java/cn/polarismesh/examples/eureka/provider/EurekaProviderApplication.java create mode 100644 eureka/eureka-java/provider/src/main/resources/application.yml diff --git a/eureka/eureka-java/.gitignore b/eureka/eureka-java/.gitignore new file mode 100644 index 0000000..ba517bb --- /dev/null +++ b/eureka/eureka-java/.gitignore @@ -0,0 +1,46 @@ +# Eclipse project files +.project +.classpath +.settings + +# IntelliJ IDEA project files and directories +*.iml +*.ipr +*.iws +.idea/ + +# Build targets +**/target/* + +# Mac-specific directory that no other operating system needs. +.DS_Store + +# JVM crash logs +hs_err_pid*.log + +dependency-reduced-pom.xml + +*/.unison.* + +# exclude docker-sync stuff +.docker-sync +*/.docker-sync + +# exclude vscode files +.vscode/ +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.factorypath + +# Maven ignore +.flattened-pom.xml + +# misc +*classes +*.class +.svn +logs/ +lib/ +backup/ \ No newline at end of file diff --git a/eureka/eureka-java/consumer/pom.xml b/eureka/eureka-java/consumer/pom.xml new file mode 100644 index 0000000..d68cfcf --- /dev/null +++ b/eureka/eureka-java/consumer/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + cn.polarismesh.examples + eureka-java-example + 1.0.0-SNAPSHOT + + + eureka-consumer + + + + + org.springframework.cloud + spring-cloud-dependencies + Hoxton.SR2 + pom + import + + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + org.springframework.boot + spring-boot-starter-web + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + cn.polarismesh.examples.eureka.consumer.EurekaConsumerApplication + ZIP + + + + + repackage + + + + + + + \ No newline at end of file diff --git a/eureka/eureka-java/consumer/src/main/java/cn/polarismesh/examples/eureka/consumer/Config.java b/eureka/eureka-java/consumer/src/main/java/cn/polarismesh/examples/eureka/consumer/Config.java new file mode 100644 index 0000000..097c1a8 --- /dev/null +++ b/eureka/eureka-java/consumer/src/main/java/cn/polarismesh/examples/eureka/consumer/Config.java @@ -0,0 +1,16 @@ +package cn.polarismesh.examples.eureka.consumer; + +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class Config { + @LoadBalanced + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } + +} diff --git a/eureka/eureka-java/consumer/src/main/java/cn/polarismesh/examples/eureka/consumer/EurekaConsumerApplication.java b/eureka/eureka-java/consumer/src/main/java/cn/polarismesh/examples/eureka/consumer/EurekaConsumerApplication.java new file mode 100644 index 0000000..54f596a --- /dev/null +++ b/eureka/eureka-java/consumer/src/main/java/cn/polarismesh/examples/eureka/consumer/EurekaConsumerApplication.java @@ -0,0 +1,38 @@ +package cn.polarismesh.examples.eureka.consumer; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +@SpringBootApplication +@RestController +@EnableDiscoveryClient +public class EurekaConsumerApplication { + + private static final String PROVIDER_SERVICE_NAME = "eureka-provider-service"; + + @Autowired + private RestTemplate restTemplate; + + @RequestMapping("/echo") + public String echo(@RequestParam String value) { + return restTemplate.getForObject( + String.format("http://%s/echo1?value=%s", PROVIDER_SERVICE_NAME, value), String.class); + } + + + @RequestMapping("/services") + public String services() { + return restTemplate.getForObject(String.format("http://%s/eureka/v2/apps", PROVIDER_SERVICE_NAME), String.class); + } + + public static void main(String[] args) { + SpringApplication.run(EurekaConsumerApplication.class, args); + } +} diff --git a/eureka/eureka-java/consumer/src/main/resources/application.yml b/eureka/eureka-java/consumer/src/main/resources/application.yml new file mode 100644 index 0000000..cba982c --- /dev/null +++ b/eureka/eureka-java/consumer/src/main/resources/application.yml @@ -0,0 +1,11 @@ +server: + port: 20002 +spring: + application: + name: eureka-consumer-service +eureka: + instance: + lease-renew-interval-in-seconds: 3 + client: + serviceUrl: + defaultZone: http://127.0.0.1:8761/eureka/ \ No newline at end of file diff --git a/eureka/eureka-java/pom.xml b/eureka/eureka-java/pom.xml new file mode 100644 index 0000000..4cab762 --- /dev/null +++ b/eureka/eureka-java/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.2.1.RELEASE + + + cn.polarismesh.examples + eureka-java-example + 1.0.0-SNAPSHOT + pom + + + consumer + provider + + \ No newline at end of file diff --git a/eureka/eureka-java/provider/pom.xml b/eureka/eureka-java/provider/pom.xml new file mode 100644 index 0000000..ee7c994 --- /dev/null +++ b/eureka/eureka-java/provider/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + + cn.polarismesh.examples + eureka-java-example + 1.0.0-SNAPSHOT + + eureka-provider + + + + + + org.springframework.cloud + spring-cloud-dependencies + Hoxton.SR2 + pom + import + + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + org.springframework.boot + spring-boot-starter-web + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + cn.polarismesh.examples.eureka.provider.EurekaProviderApplication + ZIP + + + + + repackage + + + + + + + \ No newline at end of file diff --git a/eureka/eureka-java/provider/src/main/java/cn/polarismesh/examples/eureka/provider/EurekaProviderApplication.java b/eureka/eureka-java/provider/src/main/java/cn/polarismesh/examples/eureka/provider/EurekaProviderApplication.java new file mode 100644 index 0000000..3f0e96c --- /dev/null +++ b/eureka/eureka-java/provider/src/main/java/cn/polarismesh/examples/eureka/provider/EurekaProviderApplication.java @@ -0,0 +1,23 @@ +package cn.polarismesh.examples.eureka.provider; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@SpringBootApplication +@RestController +@EnableDiscoveryClient +public class EurekaProviderApplication { + + @RequestMapping("/echo1") + public String echo1(@RequestParam String value) { + return "echo: " + value; + } + + public static void main(String[] args) { + SpringApplication.run(EurekaProviderApplication.class, args); + } +} diff --git a/eureka/eureka-java/provider/src/main/resources/application.yml b/eureka/eureka-java/provider/src/main/resources/application.yml new file mode 100644 index 0000000..114ab53 --- /dev/null +++ b/eureka/eureka-java/provider/src/main/resources/application.yml @@ -0,0 +1,11 @@ +server: + port: 20001 +spring: + application: + name: eureka-provider-service +eureka: + instance: + lease-renew-interval-in-seconds: 3 + client: + serviceUrl: + defaultZone: http://127.0.0.1:8761/eureka/ \ No newline at end of file From ce93712e52a10ab0e5ed71b2ef307d7ff214b540 Mon Sep 17 00:00:00 2001 From: andrewshan Date: Mon, 10 Jan 2022 16:52:00 +0800 Subject: [PATCH 2/2] fix: remove not supported methods --- .../examples/eureka/consumer/EurekaConsumerApplication.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/eureka/eureka-java/consumer/src/main/java/cn/polarismesh/examples/eureka/consumer/EurekaConsumerApplication.java b/eureka/eureka-java/consumer/src/main/java/cn/polarismesh/examples/eureka/consumer/EurekaConsumerApplication.java index 54f596a..4d11d96 100644 --- a/eureka/eureka-java/consumer/src/main/java/cn/polarismesh/examples/eureka/consumer/EurekaConsumerApplication.java +++ b/eureka/eureka-java/consumer/src/main/java/cn/polarismesh/examples/eureka/consumer/EurekaConsumerApplication.java @@ -26,12 +26,6 @@ public String echo(@RequestParam String value) { String.format("http://%s/echo1?value=%s", PROVIDER_SERVICE_NAME, value), String.class); } - - @RequestMapping("/services") - public String services() { - return restTemplate.getForObject(String.format("http://%s/eureka/v2/apps", PROVIDER_SERVICE_NAME), String.class); - } - public static void main(String[] args) { SpringApplication.run(EurekaConsumerApplication.class, args); }