File tree Expand file tree Collapse file tree
java/com/fd/tryout/eureka
src/main/java/com/fd/eureka/dto
java/com/fd/tryout/eureka
java/com/fd/tryout/eureka Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <project xmlns =" http://maven.apache.org/POM/4.0.0"
3+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5+ <parent >
6+ <artifactId >eureka</artifactId >
7+ <groupId >com.fd</groupId >
8+ <version >1.0-SNAPSHOT</version >
9+ </parent >
10+ <modelVersion >4.0.0</modelVersion >
11+
12+ <artifactId >eureka-client</artifactId >
13+
14+ <dependencies >
15+ <dependency >
16+ <groupId >org.springframework.cloud</groupId >
17+ <artifactId >spring-cloud-starter-netflix-eureka-client</artifactId >
18+ </dependency >
19+
20+ <dependency >
21+ <groupId >org.springframework.boot</groupId >
22+ <artifactId >spring-boot-starter-web</artifactId >
23+ </dependency >
24+
25+ <dependency >
26+ <groupId >org.springframework.boot</groupId >
27+ <artifactId >spring-boot-starter-test</artifactId >
28+ <scope >test</scope >
29+ </dependency >
30+
31+ <dependency >
32+ <groupId >org.springframework.cloud</groupId >
33+ <artifactId >spring-cloud-starter-netflix-eureka-server</artifactId >
34+ <scope >test</scope >
35+ </dependency >
36+
37+ <dependency >
38+ <groupId >com.fd</groupId >
39+ <artifactId >eureka-dto</artifactId >
40+ <version >1.0-SNAPSHOT</version >
41+ </dependency >
42+ </dependencies >
43+
44+ </project >
Original file line number Diff line number Diff line change 1+ package com .fd .tryout .eureka ;
2+
3+ import org .springframework .boot .SpringApplication ;
4+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+ import org .springframework .cloud .client .discovery .EnableDiscoveryClient ;
6+
7+ /**
8+ * @author fdanismaz
9+ * date: 9/19/18 11:54 AM
10+ */
11+ @ EnableDiscoveryClient
12+ @ SpringBootApplication
13+ public class App {
14+
15+ public static void main (String [] args ) {
16+ SpringApplication .run (App .class , args );
17+ }
18+
19+ }
Original file line number Diff line number Diff line change 1+ package com .fd .tryout .eureka .controller ;
2+
3+ import com .fd .eureka .dto .User ;
4+ import org .springframework .http .ResponseEntity ;
5+ import org .springframework .web .bind .annotation .GetMapping ;
6+ import org .springframework .web .bind .annotation .PathVariable ;
7+ import org .springframework .web .bind .annotation .RequestMapping ;
8+ import org .springframework .web .bind .annotation .RestController ;
9+
10+ /**
11+ * @author fdanismaz
12+ * date: 9/19/18 11:55 AM
13+ */
14+ @ RestController
15+ @ RequestMapping ("/user" )
16+ public class UserController {
17+
18+ @ GetMapping ("/{id}" )
19+ public ResponseEntity <User > getUser (@ PathVariable String id ) {
20+ User user = User .builder ().id ("1" ).name ("John Doe" ).build ();
21+ return ResponseEntity .ok ().body (user );
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ spring :
2+ application :
3+ name : fd-user-service
4+
5+ server :
6+ port : 9091
7+ servlet :
8+ contextPath : /test
9+
10+ eureka :
11+ client :
12+ serviceUrl :
13+ defaultZone : ${EUREKA_URI:http://localhost:8761/eureka}
14+ instance :
15+ preferIpAddress : true
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <project xmlns =" http://maven.apache.org/POM/4.0.0"
3+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5+ <parent >
6+ <artifactId >eureka</artifactId >
7+ <groupId >com.fd</groupId >
8+ <version >1.0-SNAPSHOT</version >
9+ </parent >
10+ <modelVersion >4.0.0</modelVersion >
11+
12+ <artifactId >eureka-dto</artifactId >
13+
14+
15+ </project >
Original file line number Diff line number Diff line change 1+ package com .fd .eureka .dto ;
2+
3+ import lombok .AllArgsConstructor ;
4+ import lombok .Builder ;
5+ import lombok .Data ;
6+ import lombok .NoArgsConstructor ;
7+
8+ /**
9+ * @author fdanismaz
10+ * date: 9/19/18 11:57 AM
11+ */
12+ @ Data
13+ @ Builder
14+ @ NoArgsConstructor
15+ @ AllArgsConstructor
16+ public class User {
17+
18+ private String id ;
19+ private String name ;
20+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <project xmlns =" http://maven.apache.org/POM/4.0.0"
3+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5+ <parent >
6+ <artifactId >eureka</artifactId >
7+ <groupId >com.fd</groupId >
8+ <version >1.0-SNAPSHOT</version >
9+ </parent >
10+ <modelVersion >4.0.0</modelVersion >
11+
12+ <artifactId >eureka-feign-client</artifactId >
13+
14+ <dependencies >
15+ <dependency >
16+ <groupId >org.springframework.cloud</groupId >
17+ <artifactId >spring-cloud-starter-openfeign</artifactId >
18+ </dependency >
19+
20+ <dependency >
21+ <groupId >org.springframework.cloud</groupId >
22+ <artifactId >spring-cloud-starter-netflix-eureka-client</artifactId >
23+ </dependency >
24+
25+ <dependency >
26+ <groupId >org.springframework.boot</groupId >
27+ <artifactId >spring-boot-starter-web</artifactId >
28+ </dependency >
29+
30+ <dependency >
31+ <groupId >org.springframework.boot</groupId >
32+ <artifactId >spring-boot-starter-thymeleaf</artifactId >
33+ </dependency >
34+
35+ <dependency >
36+ <groupId >com.fd</groupId >
37+ <artifactId >eureka-dto</artifactId >
38+ <version >1.0-SNAPSHOT</version >
39+ </dependency >
40+ </dependencies >
41+
42+ </project >
Original file line number Diff line number Diff line change 1+ package com .fd .tryout .eureka ;
2+
3+ import org .springframework .boot .SpringApplication ;
4+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+ import org .springframework .cloud .netflix .eureka .EnableEurekaClient ;
6+ import org .springframework .cloud .openfeign .EnableFeignClients ;
7+
8+ /**
9+ * @author fdanismaz
10+ * date: 9/19/18 1:40 PM
11+ */
12+ @ EnableFeignClients
13+ @ EnableEurekaClient
14+ @ SpringBootApplication
15+ public class App {
16+
17+ public static void main (String [] args ) {
18+ SpringApplication .run (App .class , args );
19+ }
20+
21+ }
Original file line number Diff line number Diff line change 1+ package com .fd .tryout .eureka .client ;
2+
3+ import com .fd .eureka .dto .User ;
4+ import org .springframework .cloud .openfeign .FeignClient ;
5+ import org .springframework .http .ResponseEntity ;
6+ import org .springframework .web .bind .annotation .GetMapping ;
7+ import org .springframework .web .bind .annotation .PathVariable ;
8+
9+ /**
10+ * @author fdanismaz
11+ * date: 9/19/18 1:42 PM
12+ */
13+ public class FeignClients {
14+
15+ @ FeignClient ("${fd.microservice.user.name}" )
16+ public interface UserClient {
17+
18+ @ GetMapping ("/test/user/{id}" )
19+ ResponseEntity <User > getUser (@ PathVariable ("id" ) String id );
20+
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ package com .fd .tryout .eureka .controller ;
2+
3+ import com .fd .eureka .dto .User ;
4+ import com .fd .tryout .eureka .client .FeignClients ;
5+ import org .springframework .beans .factory .annotation .Autowired ;
6+ import org .springframework .http .HttpStatus ;
7+ import org .springframework .http .ResponseEntity ;
8+ import org .springframework .web .bind .annotation .GetMapping ;
9+ import org .springframework .web .bind .annotation .PathVariable ;
10+ import org .springframework .web .bind .annotation .RequestMapping ;
11+ import org .springframework .web .bind .annotation .RestController ;
12+
13+ /**
14+ * @author fdanismaz
15+ * date: 9/19/18 1:56 PM
16+ */
17+ @ RestController
18+ @ RequestMapping ("/user" )
19+ public class UserController {
20+
21+ @ Autowired
22+ private FeignClients .UserClient userClient ;
23+
24+ @ GetMapping ("/{id}" )
25+ public ResponseEntity <User > user (@ PathVariable String id ) {
26+ ResponseEntity <User > response = this .userClient .getUser (id );
27+ if (response .getStatusCode () == HttpStatus .OK ) {
28+ System .out .println (response .getBody ().toString ());
29+ return ResponseEntity .ok ().body (response .getBody ());
30+ }
31+ return ResponseEntity .status (HttpStatus .INTERNAL_SERVER_ERROR ).body (null );
32+
33+ }
34+
35+
36+ }
You can’t perform that action at this time.
0 commit comments