ralscha / sse-eventbus

EventBus library for sending events from a Spring appliction to the web browser with SSE
Apache License 2.0
83 stars 28 forks source link

Support for Unicast over SSE #20

Closed Zaky7 closed 3 years ago

Zaky7 commented 3 years ago

hi, want to use unicast. How can I use this library for unicasting?. We can create a new method for publishing to a single client.

ralscha commented 3 years ago

Hi

What you need to do is in the register method store the id somewhere.

  @GetMapping("/register/{id}")
  public SseEmitter register(@PathVariable("id") String id) {
     // id is the client id. store it somewhere
  }

Then in the publishing code you specify the client which should receive the event

SseEvent.builder()
    .event("msg").data("payload")
    .addClientIds("client1")  // or multiple client .addClientIds("client1", "client2", "client3")
    .build();
Zaky7 commented 3 years ago

thanks I will give it a try

Zaky7 commented 3 years ago

it works thanks @ralscha