org.jboss.resteasy.annotations.SseElementType Java Examples

The following examples show how to use org.jboss.resteasy.annotations.SseElementType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerSentEventResource.java    From quarkus with Apache License 2.0 8 votes vote down vote up
@GET
@Path("/stream-xml")
@SseElementType(MediaType.TEXT_XML)
@Produces(MediaType.SERVER_SENT_EVENTS)
public void sendXmlData(@Context SseEventSink sink) {
    // send a stream of few events
    try {
        for (int i = 0; i < 3; i++) {
            final OutboundSseEvent.Builder builder = this.sse.newEventBuilder();
            builder.id(String.valueOf(i)).mediaType(MediaType.TEXT_XML_TYPE)
                    .data("<settings><foo bar=\"" + i + "\"/></settings>")
                    .name("stream of XML data");

            sink.send(builder.build());
        }
    } finally {
        sink.close();
    }
}
 
Example #2
Source File: EmitterResource.java    From quarkus-quickstarts with Apache License 2.0 6 votes vote down vote up
@Transactional
@GET
@Path("/prices")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseElementType(MediaType.TEXT_PLAIN)
public Publisher<Double> prices() {
    // get the next three prices from the price stream
    return Multi.createFrom().publisher(prices)
            .transform().byTakingFirstItems(3)
            .map(price -> {
                // store each price before we send them
                Price priceEntity = new Price();
                priceEntity.value = price;
                // here we are all in the same transaction
                // thanks to context propagation
                priceEntity.persist();
                return price;
                // the transaction is committed once the stream completes
            });
}
 
Example #3
Source File: TestResourceForConstructorProperties.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/sse")
@SseElementType(MediaType.APPLICATION_JSON)
@Produces(MediaType.SERVER_SENT_EVENTS)
public void serverSentEvents(@Context SseEventSink sink) {
    VanillaJavaImmutableData data = new VanillaJavaImmutableData("sse", "ssevalue");
    try {
        OutboundSseEvent.Builder builder = sse.newEventBuilder();
        builder.id(String.valueOf(1))
                .mediaType(MediaType.APPLICATION_JSON_TYPE)
                .data(data)
                .name("stream of json data");

        sink.send(builder.build());
    } finally {
        sink.close();
    }
}
 
Example #4
Source File: ServerSentEventResource.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/stream-html")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseElementType("text/html")
public void sendHtmlData(@Context SseEventSink sink) {
    // send a stream of few events
    try {
        for (int i = 0; i < 3; i++) {
            final OutboundSseEvent.Builder builder = this.sse.newEventBuilder();
            builder.id(String.valueOf(i)).mediaType(MediaType.TEXT_HTML_TYPE)
                    .data("<html><body>" + i + "</body></html>")
                    .name("stream of pages");

            sink.send(builder.build());
        }
    } finally {
        sink.close();
    }
}
 
Example #5
Source File: QuoteEndpoint.java    From Hands-On-Cloud-Native-Applications-with-Java-and-Quarkus with MIT License 5 votes vote down vote up
@GET
@Path("/stream")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseElementType("text/plain")
public Publisher<String> stream() {

    return quote;
}
 
Example #6
Source File: QuoteEndpoint.java    From Hands-On-Cloud-Native-Applications-with-Java-and-Quarkus with MIT License 5 votes vote down vote up
@GET
@Path("/stream")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseElementType("text/plain")
public Publisher<String> stream() {

    return quote;
}
 
Example #7
Source File: PriceResource.java    From quarkus-quickstarts with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/stream")
@Produces(MediaType.SERVER_SENT_EVENTS) // denotes that server side events (SSE) will be produced
@SseElementType("text/plain") // denotes that the contained data, within this SSE, is just regular text/plain data
public Publisher<Double> stream() {
    return prices;
}
 
Example #8
Source File: ReactiveGreetingResource.java    From quarkus-quickstarts with Apache License 2.0 5 votes vote down vote up
@GET
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseElementType(MediaType.TEXT_PLAIN)
@Path("/stream/{count}/{name}")
public Multi<String> greetingsAsStream(@PathParam int count, @PathParam String name) {
    return service.greetings(count, name);
}
 
Example #9
Source File: ReactiveBookRepositoryResource.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/stream")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseElementType(MediaType.APPLICATION_JSON)
public Publisher<Book> streamBooks(@QueryParam("sort") String sort) {
    if (sort != null) {
        return reactiveBookRepository.streamAll(Sort.ascending(sort));
    }
    return reactiveBookRepository.streamAll();
}
 
Example #10
Source File: ReactiveBookEntityResource.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/stream")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseElementType(MediaType.APPLICATION_JSON)
public Publisher<ReactiveBookEntity> streamBooks(@QueryParam("sort") String sort) {
    if (sort != null) {
        return ReactiveBookEntity.streamAll(Sort.ascending(sort));
    }
    return ReactiveBookEntity.streamAll();
}
 
Example #11
Source File: MutinyResource.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/pets")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseElementType(MediaType.APPLICATION_JSON)
public Multi<Pet> sse() {
    return service.getMorePets();
}