23 changed files with 466 additions and 0 deletions
@ -0,0 +1,8 @@ |
|||||||
|
/.classpath |
||||||
|
/.project |
||||||
|
/.settings |
||||||
|
/bin/ |
||||||
|
/logs |
||||||
|
/target |
||||||
|
*.log |
||||||
|
/src/main/resources/static |
@ -0,0 +1,33 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<parent> |
||||||
|
<groupId>vip.xumy.learn</groupId> |
||||||
|
<artifactId>spring-cloud-demo</artifactId> |
||||||
|
<version>1.0.0.RELEASE</version> |
||||||
|
</parent> |
||||||
|
<artifactId>eureka-client-feign</artifactId> |
||||||
|
<version>1.0.0</version> |
||||||
|
<name>eureka-client-feign</name> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-web</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-starter-openfeign</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
</dependencies> |
||||||
|
|
||||||
|
</project> |
@ -0,0 +1,20 @@ |
|||||||
|
package vip.xumy.learn.eureka.client; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
@RestController |
||||||
|
public class HelloControler { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
SchedualServiceHi helloService; |
||||||
|
|
||||||
|
@GetMapping(value = "/hi/{name}") |
||||||
|
public String hi(@PathVariable("name") String name) { |
||||||
|
return helloService.sayHiFromClientOne( name ); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,16 @@ |
|||||||
|
package vip.xumy.learn.eureka.client; |
||||||
|
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestMethod; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
|
||||||
|
@FeignClient(value = "service-hi", fallback = SchedualServiceHiHystric.class) |
||||||
|
public interface SchedualServiceHi { |
||||||
|
@RequestMapping(value = "/hi",method = RequestMethod.GET) |
||||||
|
String sayHiFromClientOne(@RequestParam(value = "name") String name); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,12 @@ |
|||||||
|
package vip.xumy.learn.eureka.client; |
||||||
|
|
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
@Component |
||||||
|
public class SchedualServiceHiHystric implements SchedualServiceHi { |
||||||
|
@Override |
||||||
|
public String sayHiFromClientOne(String name) { |
||||||
|
return "sorry "+name; |
||||||
|
} |
||||||
|
} |
||||||
|
|
@ -0,0 +1,25 @@ |
|||||||
|
package vip.xumy.learn.eureka.client; |
||||||
|
|
||||||
|
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; |
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients; |
||||||
|
|
||||||
|
@SpringBootApplication |
||||||
|
@EnableEurekaClient |
||||||
|
@EnableDiscoveryClient |
||||||
|
@EnableFeignClients |
||||||
|
public class ServiceFeignApplication { |
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
SpringApplication.run( ServiceFeignApplication.class, args ); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,8 @@ |
|||||||
|
server.port=8765 |
||||||
|
|
||||||
|
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/ |
||||||
|
|
||||||
|
spring.application.name=eureka-feign |
||||||
|
|
||||||
|
feign.hystrix.enabled=true |
||||||
|
|
@ -0,0 +1,8 @@ |
|||||||
|
/.classpath |
||||||
|
/.project |
||||||
|
/.settings |
||||||
|
/bin/ |
||||||
|
/logs |
||||||
|
/target |
||||||
|
*.log |
||||||
|
/src/main/resources/static |
@ -0,0 +1,37 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<parent> |
||||||
|
<groupId>vip.xumy.learn</groupId> |
||||||
|
<artifactId>spring-cloud-demo</artifactId> |
||||||
|
<version>1.0.0.RELEASE</version> |
||||||
|
</parent> |
||||||
|
<artifactId>eureka-client-hi</artifactId> |
||||||
|
<version>1.0.0</version> |
||||||
|
<name>eureka-client-hi</name> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-web</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
</dependencies> |
||||||
|
|
||||||
|
<build> |
||||||
|
<plugins> |
||||||
|
<plugin> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId> |
||||||
|
</plugin> |
||||||
|
</plugins> |
||||||
|
</build> |
||||||
|
|
||||||
|
</project> |
@ -0,0 +1,31 @@ |
|||||||
|
package vip.xumy.learn.eureka.client; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.boot.SpringApplication; |
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||||
|
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
@SpringBootApplication |
||||||
|
@EnableEurekaClient |
||||||
|
@RestController |
||||||
|
public class ServiceHiApplication { |
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
SpringApplication.run( ServiceHiApplication.class, args ); |
||||||
|
} |
||||||
|
|
||||||
|
@Value("${server.port}") |
||||||
|
String port; |
||||||
|
|
||||||
|
@RequestMapping("/hi") |
||||||
|
public String home(@RequestParam(value = "name", defaultValue = "forezp") String name) { |
||||||
|
return "hi " + name + " ,i am from port:" + port; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,6 @@ |
|||||||
|
server.port=8762 |
||||||
|
|
||||||
|
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/ |
||||||
|
|
||||||
|
spring.application.name=eureka-hi |
||||||
|
|
@ -0,0 +1,8 @@ |
|||||||
|
/.classpath |
||||||
|
/.project |
||||||
|
/.settings |
||||||
|
/bin/ |
||||||
|
/logs |
||||||
|
/target |
||||||
|
*.log |
||||||
|
/src/main/resources/static |
@ -0,0 +1,39 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<parent> |
||||||
|
<groupId>vip.xumy.learn</groupId> |
||||||
|
<artifactId>spring-cloud-demo</artifactId> |
||||||
|
<version>1.0.0.RELEASE</version> |
||||||
|
</parent> |
||||||
|
<artifactId>eureka-client-ribbon</artifactId> |
||||||
|
<version>1.0.0</version> |
||||||
|
<name>eureka-client-ribbon</name> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-web</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
|
||||||
|
</dependencies> |
||||||
|
|
||||||
|
</project> |
@ -0,0 +1,20 @@ |
|||||||
|
package vip.xumy.learn.eureka.client; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
@RestController |
||||||
|
public class HelloControler { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
HelloService helloService; |
||||||
|
|
||||||
|
@GetMapping(value = "/hi/{name}") |
||||||
|
public String hi(@PathVariable("name") String name) { |
||||||
|
return helloService.hiService( name ); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
@ -0,0 +1,26 @@ |
|||||||
|
package vip.xumy.learn.eureka.client; |
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import org.springframework.web.client.RestTemplate; |
||||||
|
|
||||||
|
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; |
||||||
|
|
||||||
|
@Service |
||||||
|
public class HelloService { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
RestTemplate restTemplate; |
||||||
|
|
||||||
|
@HystrixCommand(fallbackMethod = "hiError") |
||||||
|
public String hiService(String name) { |
||||||
|
return restTemplate.getForObject("http://SERVICE-HI/hi?name="+name,String.class); |
||||||
|
} |
||||||
|
|
||||||
|
public String hiError(String name) { |
||||||
|
return "hi,"+name+",sorry,error!"; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
@ -0,0 +1,34 @@ |
|||||||
|
package vip.xumy.learn.eureka.client; |
||||||
|
|
||||||
|
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.netflix.eureka.EnableEurekaClient; |
||||||
|
import org.springframework.cloud.netflix.hystrix.EnableHystrix; |
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.web.client.RestTemplate; |
||||||
|
|
||||||
|
@SpringBootApplication |
||||||
|
@EnableEurekaClient |
||||||
|
@EnableDiscoveryClient |
||||||
|
@EnableHystrix |
||||||
|
public class ServiceRibbonApplication { |
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
SpringApplication.run( ServiceRibbonApplication.class, args ); |
||||||
|
} |
||||||
|
|
||||||
|
@Bean |
||||||
|
@LoadBalanced |
||||||
|
RestTemplate restTemplate() { |
||||||
|
return new RestTemplate(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,6 @@ |
|||||||
|
server.port=8764 |
||||||
|
|
||||||
|
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/ |
||||||
|
|
||||||
|
spring.application.name=eureka-ribbon |
||||||
|
|
@ -0,0 +1,8 @@ |
|||||||
|
/.classpath |
||||||
|
/.project |
||||||
|
/.settings |
||||||
|
/bin/ |
||||||
|
/logs |
||||||
|
/target |
||||||
|
*.log |
||||||
|
/src/main/resources/static |
@ -0,0 +1,24 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<parent> |
||||||
|
<groupId>vip.xumy.learn</groupId> |
||||||
|
<artifactId>spring-cloud-demo</artifactId> |
||||||
|
<version>1.0.0.RELEASE</version> |
||||||
|
</parent> |
||||||
|
<artifactId>eureka-server-demo</artifactId> |
||||||
|
<version>1.0.0</version> |
||||||
|
<name>eureka-server-demo</name> |
||||||
|
<packaging>jar</packaging> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
</dependencies> |
||||||
|
|
||||||
|
</project> |
@ -0,0 +1,20 @@ |
|||||||
|
package vip.xumy.learn.eureka.server; |
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication; |
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||||
|
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; |
||||||
|
|
||||||
|
/** Do not use for any commercial purposes without permission |
||||||
|
* @author: mengyxu |
||||||
|
* @date: 2022年2月24日 |
||||||
|
*/ |
||||||
|
|
||||||
|
@SpringBootApplication |
||||||
|
@EnableEurekaServer |
||||||
|
public class EurekaServerApplication { |
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
SpringApplication.run(EurekaServerApplication.class, args); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
server.port=8761 |
||||||
|
|
||||||
|
eureka.instance.hostname=localhost |
||||||
|
eureka.client.registerWithEureka=false |
||||||
|
eureka.client.fetchRegistry=false |
||||||
|
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/ |
||||||
|
|
||||||
|
spring.application.name=eureka-server |
||||||
|
|
@ -0,0 +1,8 @@ |
|||||||
|
/.classpath |
||||||
|
/.project |
||||||
|
/.settings |
||||||
|
/bin/ |
||||||
|
/logs |
||||||
|
/target |
||||||
|
*.log |
||||||
|
/src/main/resources/static |
@ -0,0 +1,60 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<parent> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-parent</artifactId> |
||||||
|
<version>2.0.3.RELEASE</version> |
||||||
|
</parent> |
||||||
|
<groupId>vip.xumy.learn</groupId> |
||||||
|
<artifactId>spring-cloud-demo</artifactId> |
||||||
|
<version>1.0.0.RELEASE</version> |
||||||
|
<name>spring-cloud-demo</name> |
||||||
|
<packaging>pom</packaging> |
||||||
|
|
||||||
|
<properties> |
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
||||||
|
<java.version>1.8</java.version> |
||||||
|
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version> |
||||||
|
</properties> |
||||||
|
|
||||||
|
<modules> |
||||||
|
<module>../eureka-server</module> |
||||||
|
<module>../service-hi</module> |
||||||
|
<module>../service-ribbon</module> |
||||||
|
</modules> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-test</artifactId> |
||||||
|
<scope>test</scope> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
</dependencies> |
||||||
|
|
||||||
|
<dependencyManagement> |
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-dependencies</artifactId> |
||||||
|
<version>${spring-cloud.version}</version> |
||||||
|
<type>pom</type> |
||||||
|
<scope>import</scope> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
</dependencyManagement> |
||||||
|
|
||||||
|
<build> |
||||||
|
<plugins> |
||||||
|
<plugin> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId> |
||||||
|
</plugin> |
||||||
|
</plugins> |
||||||
|
</build> |
||||||
|
|
||||||
|
</project> |
Loading…
Reference in new issue