Added Feign Client
This commit is contained in:
parent
e618804c75
commit
da1bdf90bf
|
@ -9,6 +9,7 @@
|
||||||
<modules>
|
<modules>
|
||||||
<module>spring-cloud-hystrix-rest-producer</module>
|
<module>spring-cloud-hystrix-rest-producer</module>
|
||||||
<module>spring-cloud-hystrix-rest-consumer</module>
|
<module>spring-cloud-hystrix-rest-consumer</module>
|
||||||
|
<module>spring-cloud-hystrix-feign-rest-consumer</module>
|
||||||
</modules>
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
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>
|
||||||
|
|
||||||
|
<artifactId>spring-cloud-hystrix-feign-rest-consumer</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>Spring Cloud Hystrix Feign REST Consumer</name>
|
||||||
|
<description>Spring Cloud Hystrix Feign Sample Implementation</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung.spring.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-hystrix</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<relativePath>..</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baeldung.spring.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-hystrix-rest-producer</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-hystrix</artifactId>
|
||||||
|
<version>1.1.5.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
|
||||||
|
<version>1.1.5.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-feign</artifactId>
|
||||||
|
<version>1.1.5.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
<version>1.4.0.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
|
<version>1.4.0.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
<version>1.4.0.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-parent</artifactId>
|
||||||
|
<version>Brixton.SR4</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.baeldung.spring.cloud.hystrix.rest.consumer;
|
||||||
|
|
||||||
|
import com.baeldung.spring.cloud.hystrix.rest.producer.GreetingController;
|
||||||
|
import org.springframework.cloud.netflix.feign.FeignClient;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
|
||||||
|
@FeignClient(
|
||||||
|
name = "rest-producer",
|
||||||
|
url = "http://localhost:9090/greeting/{username}",
|
||||||
|
fallback = GreetingClient.GreetingClientFallback.class
|
||||||
|
)
|
||||||
|
public interface GreetingClient extends GreetingController {
|
||||||
|
@Component
|
||||||
|
public static class GreetingClientFallback implements GreetingClient {
|
||||||
|
@Override
|
||||||
|
public String greeting(@PathVariable("username") String username) {
|
||||||
|
return "Hello User!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.baeldung.spring.cloud.hystrix.rest.consumer;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
|
||||||
|
import org.springframework.cloud.netflix.feign.EnableFeignClients;
|
||||||
|
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableCircuitBreaker
|
||||||
|
@EnableHystrixDashboard
|
||||||
|
@EnableFeignClients
|
||||||
|
@Controller
|
||||||
|
public class RestConsumerFeignApplication {
|
||||||
|
@Autowired
|
||||||
|
private GreetingClient greetingClient;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(RestConsumerFeignApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/get-greeting/{username}")
|
||||||
|
public String getGreeting(Model model, @PathVariable("username") String username) {
|
||||||
|
model.addAttribute("greeting", greetingClient.greeting(username));
|
||||||
|
return "greeting-view";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Greetings from Hystrix</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2 th:text="${greeting}"/>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue