Vert.x RxJava extension examples
Here you will find examples demonstrating Vert.x RxJava extension in action.
Vert.x RxJava extension provides Rxified version of the Vert.x APIs. Please consult the Vert.x RxJava manual for detailed documentation on Vert.x core.
RxJava Http examples
These examples shows the Rxified HTTP api.
A simple http server and client.
The server uses an
Observable<HttpServerRequest> to serve request:
The client uses an
Observable<HttpClientRequest and applies
flatMap to get a
Same as simple example however the client applies several operations on this observable to end with the http client response:
reducemerge all response buffers in a single buffer
maptransform the buffer to a string
subscribedelivers the response content
A variation of the simple example with two client requests mapped to an
and then zipped in a single json object.
The main interest is to get the final result when the two responses are delivered.
The http client json response is unmarshalled to a Java object: the
RxHelper.unmarshaller static method
creates an Rx operator applied to the response via the
RxJava event bus examples
The event bus provides a natural fit with the Rx api.
Publish / Subscribe
A reinterpreation of the core publish / subscribe example with the subscriber using the Rx api.
Ping / Pong
An example of sending, receiving and replying to messages using the Rx api.
RxJava Database examples
An example showing the Jdbc Service Rxified api, after the client connected to the database, it chains
operations via the
flatMap operation and then subscribes to the result.
An example showing the Mongo Service Rxified api, after the client connected to Mongo, it chains
insert via flatMap and then subscribes to the result to do a query
in the onComplete.
Vertx for RxJava provides schedulers for performing delayed, periodic actions.
RxJava timer can use Vertx scheduler for scheduling actions on the event loop, this example shows a 1 second periodic observable scheduled on Vertx event loop.
Blocking action example
When an Observable operation is blocking, a blocking Vertx scheduler can be used to perform the action, this examples shows how blocking operation can be scheduled on Vert.x