Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[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