1

My example Code :

@GET
@Path("/reactive")
@Produces(MediaType.SERVER_SENT_EVENTS)
@RestSseElementType(MediaType.APPLICATION_JSON)
public Multi<OutboundSseEvent> reactive() {

  return Multi.createFrom().ticks().every(Duration.ofSeconds(1))
                .onItem().transform(n -> creaMessaggioSse(n,"SseReactive"));
}

private OutboundSseEvent creaMessaggioSse(Long evt, String nome){

  return sse.newEventBuilder()
                .data("Evento-"+evt)
                .id("Id-"+evt)
                .name(nome)
                .build();

}

My output is :

data:{"name":"SseReactive","comment":null,"id":"Id-0","type":"java.lang.String","genericType":"java.lang.String","mediaType":{"type":"text","subtype":"plain","parameters":{},"wildcardType":false,"wildcardSubtype":false},"mediaTypeSet":false,"data":"Evento-0","reconnectDelay":-1,"escape":false,"reconnectDelaySet":false}``

instead of

id:Id-1
event:SseStandard
data:Evento-1

That's because the code executed is (finded by debug)

PublisherResponseHandler.onNext(Object item) {
            OutboundSseEventImpl event = new OutboundSseEventImpl.BuilderImpl().data(item).build();
            SseUtil.send(requestContext, event)

So the event "sent" has only data.

Where am I wrong ??

DaiNeko
  • 11
  • 1
  • Is there a specific reason to use `OutboundSseEvent`? – geoand Apr 01 '21 at 18:13
  • I think so since my client need an SSE channel, so I need @Produces(MediaType.SERVER_SENT_EVENTS) on my service. I hope that using OutboundSseEvent smallrye reactive trigger a specific payload manager. That's not the case since seems managed as a generic class and It is wrapper onto a OutboundSseEvent anyway – DaiNeko Apr 02 '21 at 12:05
  • Did you try not using that wrapper class? – geoand Apr 04 '21 at 05:28

0 Answers0