Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RestController
- class CustomerController {
- private final RSocketRequesterApplication.CustomerServiceAdapter customerServiceAdapter;
- CustomerController(RSocketRequesterApplication.CustomerServiceAdapter customerServiceAdapter) {
- this.customerServiceAdapter = customerServiceAdapter;
- }
- @GetMapping("/customers/{id}")
- Mono<CustomerResponse> getCustomer(@PathVariable String id) {
- return customerServiceAdapter.getCustomer(id);
- }
- @GetMapping(value = "/customers", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
- Publisher<CustomerResponse> getCustomers() {
- return customerServiceAdapter.getCustomers(getRandomIds(10));
- }
- @GetMapping(value = "/customers-channel", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
- Publisher<CustomerResponse> getCustomersChannel() {
- return customerServiceAdapter.getCustomerChannel(Flux.interval(Duration.ofMillis(1000))
- .map(id -> new CustomerRequest(UUID.randomUUID().toString())));
- }
- private List<String> getRandomIds(int amount) {
- return IntStream.range(0, amount)
- .mapToObj(n -> UUID.randomUUID().toString())
- .collect(toList());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement