Latest commit 758915b Jul 11, 2018
Permalink
..
Failed to load latest commit information.
src/main Update for 3.5.1 staging Feb 11, 2018
README.adoc Small refactor, a source code url fix. Feb 5, 2018
pom.xml Update for 3.5.3 Jul 11, 2018

README.adoc

Vert.x RxJava2 extension examples

IMPORTANT: These examples use the RX Java 2 API. If you are interested by RX Java 1, check the rxjava-1-examples module.

Here you will find examples demonstrating Vert.x RxJava2 extension in action.

Vert.x RxJava 2 extension provides Rxified version of the Vert.x APIs. Please consult the Vert.x RxJava manual for detailed documentation on Vert.x core.

RxJava Web client examples

These examples shows the Rxified HTTP api.

Simple

A simple web client.

The client creates an Single<HttpRequest<String>> and then subscribe multiple times to the single to send the request.

Zip

A variation of the simple example with two client requests mapped to an Single<JsonObject> and then zipped in a single json object.

The main interest is to get the final result when the two responses are delivered.

Unmarshalling

The web client json response is unmarshalled to a Java object using the web client unmarshalling features.

RxJava Web examples

Real-time

This example demonstrates how an RxJava Flowable source can be sent real-time to the browser via a SockJSSocket.

SocksJS gives a WebSocket-like API in client side JavaScript even if the browser or network doesn’t support WebSockets.

This is ideal for so-called real-time web applications where you want quick, responsive communication between server and client and you’re probably rendering the user interface on the client side.

Run the server either in your IDE or on the command line, then open your browser and hit link:http://localhost:8080

This serves the index page which contains some JavaScript which opens an event bus connection to the server.

When the connection is open, a SockJS connection is opened on the /news-feed uri. When data arrives in the handler the script just uses some simple JQuery to write the message to the page.

On the server side, in the server when a SockJS connection arrives, we subscribe to an Flowable<String> (that is created from the EventBus, but it would be another source of data) and send to the browser the observed items.

When you get the index page in your browser you should see it update every second as it receives a message.

RxJava 2 Http examples

These examples shows the Rxified HTTP api.

Simple

A simple http server and client.

The server uses an Flowable<HttpServerRequest> to serve request:

The client uses an Flowable<HttpClientRequest and applies flatMap to get a Flowable<Buffer>

Reduce

Same as simple example however the client applies several operations on this flowable to end with the http client response:

  • flatMap transforms the Flowable<HttpClientResponse>Flowable<Buffer>

  • reduce merge all response buffers in a single buffer

  • map transform the buffer to a string

  • subscribe delivers the response content

Zip

A variation of the simple example with two client requests mapped to an Flowable<JsonObject> and then zipped in a single json object.

The main interest is to get the final result when the two responses are delivered.

Unmarshalling

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 lift.

Backpressure

The http server which uses Vert.x-Web router and defines a "drop" strategy when the server is overloaded (backpressure).

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.

Zip replies

The example Sender sends two messages over the event bus and wait for replies, the zip operation is applied to deliver a single reply when the two replies are received.

RxJava 2 Database examples

Jdbc example

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.

Jdbc Manual Transaction Handling

An example showing an Rxified Jdbc api to handle transactions manually then commit if all succeeded or rollback with exception propagation to the caller in case of anyone failed.

Mongo example

An example showing the Mongo Service Rxified api, after the client connected to Mongo, it chains createCollection and insert via flatMap and then subscribes to the result to do a query in the onComplete.

Scheduler examples

Vertx for RxJava provides schedulers for performing delayed, periodic actions.

Periodic events

RxJava timer can use Vertx scheduler for scheduling actions on the event loop, this example shows a 1 second periodic flowable scheduled on Vertx event loop.

Blocking action example

When an Flowable 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

Scheduler examples

These examples demonstrate usage of Vert.x net servers and clients with RxJava2

Greeter

This example combines RecordParser and RxJava2 for a TCP client/server exchange. When the client sends a name to the server, it replies with a greeting. Names and greetings are line-separated.

Services examples

Rxified Vert.x Services examples

Service Proxy example

This example shows you how to make your service proxy Rxified with RxJava2.