This demo project showcases building reactive REST endpoints using Apache CXF, RxJava, andJAX-RS with Spring Boot.
It illustrates returning reactive types (Single, Flowable) and streaming responses using JAX-RS StreamingOutput.
mvn clean installmvn spring-boot:runAll endpoints are under the base path: http://localhost:8080/api/greet
-
GET /api/greet/{name}
Description: Returns a simple greeting message wrapped in an RxJava Single. Produces: application/json Example:
curl -N http://localhost:8080/api/greet/JohnResponse:
"Hello, John!"-
GET /api/greet/stream
Description: Streams plain text lines (one, two, three) as a JAX-RS StreamingOutput. Produces: text/plain Example:
curl -N http://localhost:8080/api/greet/streamResponse:
one
two
three-
GET /api/greet/stream-flowable
Description: Streams JSON array of greeting objects (Greeting POJO) using RxJava Flowable wrapped inside StreamingOutput. Produces: application/json Example:
curl -N http://localhost:8080/api/greet/stream-flowableResponse:
[
{"message":"Hello one"},
{"message":"Hello two"},
{"message":"Hello three"}
]-
GET /api/greet/flowable-plain
Description: Streams plain text lines (one, two, three) from an RxJava Flowable using StreamingOutput. Produces: text/plain Example:
curl -N http://localhost:8080/api/greet/flowable-plainResponse:
one
two
three-
GET /api/greet/flowable-sse
Description: Streams Server-Sent Events (SSE) with data events for one, two, three. Produces: text/event-stream Example:
curl -N http://localhost:8080/api/greet/flowable-sseResponse:
data: one
data: two
data: three
The -N option in curl is used to disable buffering and see streaming output immediately. The project uses RxJava 2 (Single and Flowable) for reactive programming. Jackson handles JSON serialization with a customized ObjectMapper.