-
Notifications
You must be signed in to change notification settings - Fork 0
/
Service2Application.java
56 lines (48 loc) · 1.56 KB
/
Service2Application.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.jmhreif.service2;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.retry.annotation.Retryable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
@SpringBootApplication
@EnableRetry
public class Service2Application {
public static void main(String[] args) {
SpringApplication.run(Service2Application.class, args);
}
@Bean
@LoadBalanced
WebClient.Builder createLoadBalancedBuilder() { return WebClient.builder(); }
@Bean
WebClient client(WebClient.Builder builder) { return builder.baseUrl("http://mongo-client").build(); }
}
@RestController
@RequestMapping("/goodreads")
@AllArgsConstructor
class BookController {
private final WebClient client;
@GetMapping
String liveCheck() { return "Service2 is up"; }
@Retryable
@GetMapping("/books")
Flux<Book> getBooks() {
return client.get()
.uri("/db/books")
.retrieve()
.bodyToFlux(Book.class);
}
}
@Data
class Book {
private String mongoId;
private String book_id;
private String title, format, isbn, isbn13, edition_information;
}