user3276247
user3276247

Reputation: 1084

Difference between vert.x and RxJava

We are evaluating reactive programming frameworks for one of our projects. I just went through vert.x tutorials. I checked RxJava presentation a bit. RxJava seemed more close to CompletableFuture. But despite the underlying patterns, both RxJava and Vert.x give access to non blocking programming. I am confused as to what is the difference between them. I will appreciate any help in this regard.

Upvotes: 23

Views: 11742

Answers (3)

inmyth
inmyth

Reputation: 9070

Vert.x is a bunch of modules and extensions collectively called a toolkit. The core module contains web server and concurrency model called Verticle. RxJava is a Java implementation of ReactiveX. Both are based on event-driven principles but a web server is not comparable to RxJava.

So I'm guessing the underlying comparison here is between Verticle vs RxJava.

Verticle is a class whose state is totally inaccessible from outside except through event bus. So messages come, queued, and popped sequentially in a single thread manner. The idea is to create a thread-safe environment without having to deal with Java's notorious locking mechanism. Also in concurrency lingo, such structure is known as Actor.

When to use: Whenever you need to work with Java's synchronized block. The situation where multiple threads need to access class variables a.k.a race condition is where you can drop synchronized for Verticle or Actor. And in Vert.x you can use Verticle without running a web server.

To explain RxJava think of Java 8 Stream which introduced streaming and higher-order functions like map, filter,zip etc on collections. RxJava's use case is when the stream is asynchronous.

When to use: When you want to manipulate streams. For example, matching frames from a movie stream with subtitles from another stream (RxJava was created by Netflix afterall). Or doing real time analysis from several stock market tickers.

Upvotes: 7

softjake
softjake

Reputation: 1076

From their own site:

Eclipse Vert.x is a toolkit for building reactive applications on the JVM.

It defines the fundamental APIs for writing asynchronous networked applications (eg: db connection, monitoring, authentication, service discovery, clustering, etc.)

Internally, it is based on the Netty project, a high-performance asynchronous networking library for the JVM. However, it provides a higher-level API easier to reason with and still highly performant.

You can use Vert.x callback-based API exclusively but Vert.x also implements an equivalent Rxified API using RxJava under the hood. This provides a great platform to integrate Vert.x modules within RxJava applications.

Vert.x is polyglot as it supports many other JVM based languages APIs such as Kotlin, Groovy, Ruby, Scala, and Ceylon. Moreover, since Vert.x is event-driven and message based, it also provides a JavaScript API quite useful to integrate frontend with backends.

Vert.x provides fluent HTTP endpoints and route configuration backed by handlers where the business logic is implemented. But the real nervous system is the event bus that acts as a telecom provider to all Vert.x local or distributed components.

This very event-bus supports:

  1. Point-to-point, request-response, and pub-sub messaging
  2. Communication between polyglot verticles within the same JVM instance
  3. Clustered communication between polyglot verticles in multiple JVM instances
  4. Bridge to Stomp or AMQP implementations for integration with other applications
  5. Bridge to SockJS for direct integration with Javascript frontends

The event-bus is supported by:

  1. Cluster managers such as Hazelcast, InfiniSpan, Ignite or ZooKeeper that provides distributed Maps, Locks, and Counters through a higher-level API access

  2. Vert.x service discovery API providing an address based abstraction to underlying complex addressing schemes

  3. SSL capable TCP service access points for bi-directional secured communication and maximum performance

Finally, Vert.x can be used by itself to develop a full-blown application or used collaboratively with frameworks such as SpringBoot, Fibers, etc.

More details here, here and here.

Hope this helps,

Softjake

Upvotes: 7

Jonas
Jonas

Reputation: 128995

VertX is a server framework for asynchronous servers while RxJava is a framework for asynchronous computations. VertX has support for RxJava and many use them together.

If you are going to create a web application and want a scalable backend, use VertX, possibly with RxJava. But if you are on another platform, just use RxJava.

Read more about using VertX and RxJava together at Vert.x API for RxJava

Upvotes: 32

Related Questions