Advertisement
lukibeni

flux waiter

Jan 27th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. package hu.cobalt.anytime.controller;
  2.  
  3. import hu.cobalt.anytime.entity.Bookable;
  4. import org.springframework.http.MediaType;
  5. import org.springframework.web.bind.annotation.*;
  6. import reactor.core.publisher.DirectProcessor;
  7. import reactor.core.publisher.Flux;
  8. import reactor.core.publisher.FluxProcessor;
  9. import reactor.core.publisher.FluxSink;
  10. import java.time.ZonedDateTime;
  11.  
  12. @RestController
  13. @RequestMapping("/waiter")
  14. public class WaiterController {
  15. FluxProcessor<Object, Object> processor = DirectProcessor.create().serialize();
  16. FluxSink<Object> sink = processor.sink();
  17.  
  18. @PostMapping(value = "/add")
  19. void addWaiterCall(@RequestBody WaiterCall waiterCall) {
  20. sink.next(waiterCall);
  21. }
  22.  
  23. @GetMapping(value = "", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
  24. Flux<Object> getWaiterCallEvents() {
  25. return processor;
  26. }
  27.  
  28. static class WaiterCall {
  29. Bookable bookable;
  30. ZonedDateTime time = ZonedDateTime.now();
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement