Search in sources :

Example 1 with OutboundEvent

use of org.glassfish.jersey.media.sse.OutboundEvent in project jersey by jersey.

the class MessageStreamResource method putMessage.

/**
     * Put a new message to the stream.
     *
     * The message will be broadcast to all registered SSE clients.
     *
     * @param message message to be broadcast.
     */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public void putMessage(final Message message) {
    LOGGER.info("--> Message received.");
    final OutboundEvent event = new OutboundEvent.Builder().id(String.valueOf(nextMessageId.getAndIncrement())).mediaType(MediaType.APPLICATION_JSON_TYPE).data(Message.class, message).build();
    broadcaster.broadcast(event);
}
Also used : OutboundEvent(org.glassfish.jersey.media.sse.OutboundEvent) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Aggregations

Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 OutboundEvent (org.glassfish.jersey.media.sse.OutboundEvent)1