Created
January 12, 2021 19:50
-
-
Save danielkec/8ecea60d9b34ff0812c51390b69a7f65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SubmissionPublisher<String> emitter = new SubmissionPublisher<>(); | |
SseBroadcaster sseBroadcaster; | |
@Incoming("from-wls") | |
public void receive(JmsMessage<String> msg) { | |
if (sseBroadcaster == null) { | |
System.out.println("No SSE client subscribed yet: " + msg.getPayload()); | |
return; | |
} | |
sseBroadcaster.broadcast(new OutboundEvent.Builder().data(msg.getPayload()).build()); | |
} | |
@Outgoing("to-wls") | |
public Publisher<String> registerPublisher() { | |
return FlowAdapters.toPublisher(emitter); | |
} | |
@POST | |
@Path("/send/{msg}") | |
public void send(@PathParam("msg") String msg) { | |
emitter.submit(msg); | |
} | |
@GET | |
@Path("sse") | |
@Produces(MediaType.SERVER_SENT_EVENTS) | |
public void listenToEvents(@Context SseEventSink eventSink, @Context Sse sse) { | |
if (sseBroadcaster == null) { | |
sseBroadcaster = sse.newBroadcaster(); | |
} | |
sseBroadcaster.register(eventSink); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment