• Stars
    star
    110
  • Rank 316,770 (Top 7 %)
  • Language
    Java
  • License
    Other
  • Created over 11 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

# Vert.x 2.x is **deprecated** - use instead

Vert.x 2.x is deprecated - use instead http://vertx.io/docs/vertx-rx/java/

mod-rxvertx

Vert.x module which uses RxJava to add support for Reactive Extensions (RX) using the RxJava library. This allows VertX developers to use the RxJava type-safe composable API to build VertX verticles.

Dependencies

  • The module wraps the VertX core objects to add Observable support so it is tightly bound to the VertX release.
  • This module also contains the Netflix RxJava library.

Status

Currently Observable wrappers are provided for

  • EventBus
  • HttpServer
  • HttpClient
  • NetServer
  • NetClient
  • Timer

There are also base Observable adapters that map Handler and AsyncResultHandler to Observable that can be used to call other Handler based APIs.

Support coming soon for

  • FileSystem
  • SockJSServer

Usage

This is a non-runnable module, which means you add it to your module via the "includes" attribute of mod.json.

All standard API methods of the form

void method(args...,Handler<T> handler)

are typically available in the form

Observable<T> method(args...)

where the operation is executed immediately or

Observable<T> observeMethod(args...)

where the operation is executed on subscribe. This latter form is the more 'pure' Rx method and should be used where possible (required to maintain semantics of concat eg)

EventBus

RxEventBus rxEventBus = new RxEventBus(vertx.eventBus());
rxEventBus.<String>registerHandler("foo").subscribe(new Action1<RxMessage<String>>() {
  public void call(RxMessage<String> message) {
    // Send a single reply
    message.reply("pong!");
  }
});

Observable<RxMessage<String>> obs = rxEventBus.send("foo", "ping!");

obs.subscribe(
  new Action1<RxMessage<String>>() {
    public void call(RxMessage<String> message) {
      // Handle response 
    }
  },
  new Action1<Throwable>() {
    public void call(Throwable err) {
     // Handle error
    }
  }
);

Scheduler

The standard RxJava schedulers are not compatible with VertX. In order to preserve the Vert.x Threading Model all callbacks to a Verticle must be made in the context of that Verticle instance.

RxVertx provides a custom Scheduler implementation that uses the Verticle context to scheduler timers and ensure callbacks run on the correct context.

In the following example the scheduler is used to run a Timer and then buffer the output.

Note: The RxVertx scheduler must always be used to observe results inside the Verticle. It is possible to use the other Schedulers (eg for blocking calls) as long as you always use observeOn to route the callbacks onto the Verticle EventLoop. For timers it is more efficient to just use the Vert.x scheduler

RxVertx rx = new RxVertx(vertx);
Observable o = (some observable source)

Observable
      .timer(10, 10, TimeUnit.MILLISECONDS, rx.contextScheduler())
      .buffer(100,TimeUnit.MILLISECONDS,rx.contextScheduler())
      .take(10)
      .subscribe(...)

Timer

The timer functions are provided via the RxVertx wrapper. The timer is set on-subscribe. To cancel a timer that has not first, or a periodic timer, just unsubscribe.

RxVertx rx = new RxVertx(vertx);
rx.setTimer(100).subscribe(new Action1<Long>() {
  public void call(Long t) {
    // Timer fired
  }
});

The new Scheduler means you can use the native RxJava Timer methods - this Timer may be deprecated in future

Helper

The support class RxSupport provides several helper methods for some standard tasks

Streams

There are two primary wrappers

Observable RxSupport.toObservable(ReadStream)

Convert a ReadStream into an Observable<Buffer>

RxSupport.stream(Observable,WriteStream)

Stream the output of an Observable to a WriteStream.

please note that this method does not handle writeQueueFull so cannot be used as a pump

More Repositories

1

vertx-examples

Vert.x 2.x is deprecated - use instead
CSS
355
star
2

vert.x

The Vert.x main project
251
star
3

vertx-gradle-template

Vert.x 2.x is **deprecated** - use instead
Java
82
star
4

mod-lang-scala

Vert.x 2.x is deprecated - use instead
Scala
78
star
5

mod-lang-clojure

Vert.x 2.x is deprecated - use instead
Clojure
74
star
6

mod-mongo-persistor

# Vert.x 2.x is **deprecated** - use instead
JavaScript
55
star
7

mod-mysql-postgresql

Vert.x 2.x is deprecated - use instead
Scala
50
star
8

mod-web-server

Vert.x 2.x is deprecated - use instead
Java
45
star
9

vertx-mods

Vert.x 2.x is deprecated - use instead
HTML
41
star
10

mod-redis

Vert.x 2.x is deprecated - use instead
Java
39
star
11

mod-work-queue

Vert.x 2.x is deprecated - use instead
Java
35
star
12

mod-lang-php

Vert.x 2.x is deprecated - use instead
Java
30
star
13

mod-lang-nashorn

Vert.x 2.x is deprecated - use instead
Java
21
star
14

vert-x.github.io

The Vert.x 2.x website
HTML
21
star
15

mod-auth-mgr

Vert.x 2.x is deprecated - use instead
JavaScript
19
star
16

openshift-cartridge

Vert.x 2.x is deprecated - use instead
HTML
17
star
17

mod-mailer

Vert.x 2.x is deprecated - use instead
Java
17
star
18

mod-lang-jruby

Vert.x 2.x is deprecated - use instead
Ruby
16
star
19

mod-lang-groovy

Vert.x 2.x is deprecated - use instead
Groovy
15
star
20

mod-lang-js

Vert.x 2.x is deprecated - use instead
JavaScript
14
star
21

mod-lang-jython

Vert.x 2.x is deprecated - use instead
Python
11
star
22

mod-lang-dynjs

Vert.x 2.x is deprecated - use instead
Java
11
star
23

testtools

Vert.x 2.x is deprecated - use instead
Java
10
star
24

openshift-vertx

Vert.x 2.x is deprecated - use instead
CSS
8
star
25

jca-adaptor

Vert.x 2.x is deprecated - use instead
Java
8
star
26

vertx-junit-annotations

Vert.x 2.x is deprecated - use instead
Java
8
star
27

mod-lang-rhino

Vert.x 2.x is deprecated - use instead
Java
7
star
28

mod-formupload

Vert.x 2.x is deprecated - use instead
Java
6
star
29

mod-unzip

Vert.x 2.x is deprecated - use instead
Java
4
star
30

mod-lang-ceylon

Vert.x 2.x is deprecated - use instead
Ceylon
4
star
31

vertx-planning

Vert.x 2.x is deprecated - use instead
4
star
32

mod-eventbus3-bridge-client

3
star
33

test-tools-tests

Vert.x 2.x is deprecated - use instead
Java
3
star
34

vertx-testframework

Vert.x 2.x is deprecated - use instead
Java
2
star
35

vertx-downloads

Vert.x 2.x is deprecated - use instead
1
star