Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. @RestController
  2. class CustomerController {
  3.  
  4. private final RSocketRequesterApplication.CustomerServiceAdapter customerServiceAdapter;
  5.  
  6.  
  7. CustomerController(RSocketRequesterApplication.CustomerServiceAdapter customerServiceAdapter) {
  8. this.customerServiceAdapter = customerServiceAdapter;
  9. }
  10.  
  11. @GetMapping("/customers/{id}")
  12. Mono<CustomerResponse> getCustomer(@PathVariable String id) {
  13. return customerServiceAdapter.getCustomer(id);
  14. }
  15.  
  16. @GetMapping(value = "/customers", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
  17. Publisher<CustomerResponse> getCustomers() {
  18. return customerServiceAdapter.getCustomers(getRandomIds(10));
  19. }
  20.  
  21. @GetMapping(value = "/customers-channel", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
  22. Publisher<CustomerResponse> getCustomersChannel() {
  23. return customerServiceAdapter.getCustomerChannel(Flux.interval(Duration.ofMillis(1000))
  24. .map(id -> new CustomerRequest(UUID.randomUUID().toString())));
  25. }
  26.  
  27. private List<String> getRandomIds(int amount) {
  28. return IntStream.range(0, amount)
  29. .mapToObj(n -> UUID.randomUUID().toString())
  30. .collect(toList());
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement