Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jaxrs-dev] EventSouce reconnect

I think we should look at what the JAX-RS implementations actually do. What is Jersey doing? What is CXF doing? And then look if they all behave the same and specify that as the Default. It might be a good idea to specify an additional policy Annotation in case the implementations behave differently.

 

Von: Jim Ma
Gesendet: Mittwoch, 14. März 2018 05:49
An: jaxrs developer discussions
Betreff: [jaxrs-dev] EventSouce reconnect

 

When the EventSink is closed after send several events with the following resource method , should EventSource reconnect automatically? 

   @GET

   @Path("/closeAfterSent")

   @Produces(MediaType.SERVER_SENT_EVENTS)

   public void eventStream(@Context SseEventSink eventSink, @Context Sse sse) throws Exception {

      System.out.println("entering eventStream()");

      ExecutorService pool = Executors.newCachedThreadPool();

      OutboundSseEvent.Builder builder = sse.newEventBuilder().mediaType(MediaType.APPLICATION_XML_TYPE);

      pool.execute(new Thread()

      {

         public void run()

         {

            try (SseEventSink sink = eventSink) 

            {

               System.out.println("sending 3 events");

               eventSink.send(builder.data("thing1").build());

               eventSink.send(builder.data("thing2").build());

               eventSink.send(builder.data("thing3").build());

               System.out.println("sent 3 events");

            }

         }

      });

   }

 

In EventSource api doc, it says EventSource will reconnect after connection loss or missing events. Should we add some clarification for this situation ?  I know Firefox or Chrome's EventSource will automatically reconnect after event sink is closed.  Should jaxrs' EventSource do the same ?

 

Thanks,

Jim

 


Back to the top