Merge pull request #8125 from eugenp/revert-8119-BAEL-3275-2

Revert "BAEL-3275: Using blocking queue for pub-sub"
This commit is contained in:
Eric Martin
2019-10-31 20:43:47 -05:00
committed by GitHub
parent db85c8f275
commit 3225470df5
20543 changed files with 1642750 additions and 0 deletions
@@ -0,0 +1,5 @@
package com.baeldung.reactive.enums;
public enum Role {
ENGINEER, SENIOR_ENGINEER, LEAD_ENGINEER
}
@@ -0,0 +1,64 @@
package com.baeldung.reactive.model;
import com.baeldung.reactive.enums.Role;
public class Employee {
private Integer employeeId;
private String firstName;
private String lastName;
private Integer age;
private Role role;
public Employee() {
}
public Employee(Integer employeeId, String firstName, String lastName, Integer age, Role role) {
this.employeeId = employeeId;
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.role = role;
}
public Integer getEmployeeId() {
return employeeId;
}
public void setEmployeeId(Integer employeeId) {
this.employeeId = employeeId;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
}
@@ -0,0 +1,13 @@
package com.baeldung.reactive.model;
import lombok.AllArgsConstructor;
import lombok.Data;
@AllArgsConstructor
@Data
public class Foo {
private long id;
private String name;
}
@@ -0,0 +1,55 @@
package com.baeldung.reactive.service;
import com.baeldung.reactive.model.Employee;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
public class EmployeeService {
private WebClient webClient;
public static String PATH_PARAM_BY_ID = "/employee/{id}";
public static String ADD_EMPLOYEE = "/employee";
public EmployeeService(WebClient webClient) {
this.webClient = webClient;
}
public EmployeeService(String baseUrl) {
this.webClient = WebClient.create(baseUrl);
}
public Mono<Employee> getEmployeeById(Integer employeeId) {
return webClient
.get()
.uri(PATH_PARAM_BY_ID, employeeId)
.retrieve()
.bodyToMono(Employee.class);
}
public Mono<Employee> addNewEmployee(Employee newEmployee) {
return webClient
.post()
.uri(ADD_EMPLOYEE)
.syncBody(newEmployee)
.retrieve().
bodyToMono(Employee.class);
}
public Mono<Employee> updateEmployee(Integer employeeId, Employee updateEmployee) {
return webClient
.put()
.uri(PATH_PARAM_BY_ID,employeeId)
.syncBody(updateEmployee)
.retrieve()
.bodyToMono(Employee.class);
}
public Mono<String> deleteEmployeeById(Integer employeeId) {
return webClient
.delete()
.uri(PATH_PARAM_BY_ID,employeeId)
.retrieve()
.bodyToMono(String.class);
}
}
@@ -0,0 +1,65 @@
package com.baeldung.reactive.webclient.simultaneous;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers;
import java.util.List;
import java.util.logging.Logger;
public class Client {
private static final Logger LOG = Logger.getLogger(Client.class.getName());
private WebClient webClient;
public Client(String uri) {
this.webClient = WebClient.create(uri);
}
public Mono<User> getUser(int id) {
LOG.info(String.format("Calling getUser(%d)", id));
return webClient.get()
.uri("/user/{id}", id)
.retrieve()
.bodyToMono(User.class);
}
public Mono<Item> getItem(int id) {
return webClient.get()
.uri("/item/{id}", id)
.retrieve()
.bodyToMono(Item.class);
}
public Mono<User> getOtherUser(int id) {
return webClient.get()
.uri("/otheruser/{id}", id)
.retrieve()
.bodyToMono(User.class);
}
public Flux<User> fetchUsers(List<Integer> userIds) {
return Flux.fromIterable(userIds)
.parallel()
.runOn(Schedulers.elastic())
.flatMap(this::getUser)
.ordered((u1, u2) -> u2.id() - u1.id());
}
public Flux<User> fetchUserAndOtherUser(int id) {
return Flux.merge(getUser(id), getOtherUser(id))
.parallel()
.runOn(Schedulers.elastic())
.ordered((u1, u2) -> u2.id() - u1.id());
}
public Mono<UserWithItem> fetchUserAndItem(int userId, int itemId) {
Mono<User> user = getUser(userId).subscribeOn(Schedulers.elastic());
Mono<Item> item = getItem(itemId).subscribeOn(Schedulers.elastic());
return Mono.zip(user, item, UserWithItem::new);
}
}
@@ -0,0 +1,17 @@
package com.baeldung.reactive.webclient.simultaneous;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Item {
private int id;
@JsonCreator
public Item(@JsonProperty("id") int id) {
this.id = id;
}
public int id() {
return id;
}
}
@@ -0,0 +1,17 @@
package com.baeldung.reactive.webclient.simultaneous;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
public class User {
private int id;
@JsonCreator
public User(@JsonProperty("id") int id) {
this.id = id;
}
public int id() {
return id;
}
}
@@ -0,0 +1,19 @@
package com.baeldung.reactive.webclient.simultaneous;
public class UserWithItem {
private User user;
private Item item;
public UserWithItem(User user, Item item) {
this.user = user;
this.item = item;
}
public User user() {
return user;
}
public Item item() {
return item;
}
}