Skip to content

Commit 33da37b

Browse files
author
alex-muliarevych
committed
Added FeignFallback for RealtorService.
1 parent 7068f6b commit 33da37b

8 files changed

Lines changed: 158 additions & 14 deletions

File tree

realtor-service/pom.xml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,8 @@
4646
<version>1.16.12</version>
4747
</dependency>
4848
<dependency>
49-
<groupId>io.github.openfeign</groupId>
50-
<artifactId>feign-okhttp</artifactId>
51-
<version>9.3.1</version>
52-
</dependency>
53-
<dependency>
54-
<groupId>io.github.openfeign</groupId>
55-
<artifactId>feign-gson</artifactId>
56-
<version>9.3.1</version>
57-
</dependency>
58-
<dependency>
59-
<groupId>io.github.openfeign</groupId>
60-
<artifactId>feign-slf4j</artifactId>
61-
<version>9.3.1</version>
49+
<groupId>org.springframework.cloud</groupId>
50+
<artifactId>spring-cloud-starter-feign</artifactId>
6251
</dependency>
6352
</dependencies>
6453

realtor-service/src/main/java/com/lohika/jclub/ApartmentRecord.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@NoArgsConstructor
77
@AllArgsConstructor
88
@Data
9+
@ToString
910
public class ApartmentRecord {
1011
@NonNull
1112
private String location;

realtor-service/src/main/java/com/lohika/jclub/RealtorServiceApplication.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.lohika.jclub;
22

3+
import lombok.extern.slf4j.Slf4j;
34
import org.springframework.boot.SpringApplication;
45
import org.springframework.boot.autoconfigure.SpringBootApplication;
56
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
67
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
78
import org.springframework.cloud.netflix.feign.EnableFeignClients;
89
import org.springframework.cloud.netflix.feign.FeignClient;
910
import org.springframework.context.annotation.Bean;
11+
import org.springframework.stereotype.Component;
1012
import org.springframework.web.bind.annotation.PostMapping;
1113
import org.springframework.web.client.RestTemplate;
1214

@@ -15,6 +17,11 @@
1517
@SpringBootApplication
1618
public class RealtorServiceApplication {
1719

20+
/* @Bean
21+
public FeignApartmentFallback createFeignFallback() {
22+
return new FeignApartmentFallback();
23+
}*/
24+
1825
public static void main(String[] args) {
1926
SpringApplication.run(RealtorServiceApplication.class, args);
2027
}
@@ -26,8 +33,18 @@ public RestTemplate restTemplate() {
2633
}
2734
}
2835

29-
@FeignClient("storage-service")
36+
@FeignClient(value = "storage-service", fallback = FeignApartmentFallback.class)
3037
interface RealtorService {
3138
@PostMapping("/apartmentRecords")
3239
void storeApartment(ApartmentRecord apartmentRecord);
3340
}
41+
42+
@Slf4j
43+
@Component
44+
class FeignApartmentFallback implements RealtorService {
45+
46+
@Override
47+
public void storeApartment(ApartmentRecord apartmentRecord) {
48+
log.error("Error: {}", apartmentRecord);
49+
}
50+
}

storage-service/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
12+
### IntelliJ IDEA ###
13+
.idea
14+
*.iws
15+
*.iml
16+
*.ipr
17+
18+
### NetBeans ###
19+
nbproject/private/
20+
build/
21+
nbbuild/
22+
dist/
23+
nbdist/
24+
.nb-gradle/

storage-service/pom.xml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.lohika.jclub</groupId>
7+
<artifactId>storage-service</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>storage-service</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>1.5.3.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
<spring-cloud.version>Dalston.SR1</spring-cloud.version>
26+
</properties>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.springframework.cloud</groupId>
31+
<artifactId>spring-cloud-starter-eureka</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-data-jpa</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-starter-data-rest</artifactId>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>com.h2database</groupId>
44+
<artifactId>h2</artifactId>
45+
<scope>runtime</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.projectlombok</groupId>
49+
<artifactId>lombok</artifactId>
50+
<optional>true</optional>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-starter-test</artifactId>
55+
<scope>test</scope>
56+
</dependency>
57+
</dependencies>
58+
59+
<dependencyManagement>
60+
<dependencies>
61+
<dependency>
62+
<groupId>org.springframework.cloud</groupId>
63+
<artifactId>spring-cloud-dependencies</artifactId>
64+
<version>${spring-cloud.version}</version>
65+
<type>pom</type>
66+
<scope>import</scope>
67+
</dependency>
68+
</dependencies>
69+
</dependencyManagement>
70+
71+
<build>
72+
<plugins>
73+
<plugin>
74+
<groupId>org.springframework.boot</groupId>
75+
<artifactId>spring-boot-maven-plugin</artifactId>
76+
</plugin>
77+
</plugins>
78+
</build>
79+
80+
81+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.lohika.jclub;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6+
7+
@EnableDiscoveryClient
8+
@SpringBootApplication
9+
public class StorageServiceApplication {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(StorageServiceApplication.class, args);
13+
}
14+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
spring.application.name=storage-service
2+
server.port=8091
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.lohika.jclub;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.boot.test.context.SpringBootTest;
6+
import org.springframework.test.context.junit4.SpringRunner;
7+
8+
@RunWith(SpringRunner.class)
9+
@SpringBootTest
10+
public class StorageServiceApplicationTests {
11+
12+
@Test
13+
public void contextLoads() {
14+
}
15+
16+
}

0 commit comments

Comments
 (0)