Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reactive Extensions for Java

Is there any equivalent of Reactive Extensions (.NET) for Java?

About Rx (Reactive Extensions)

Rx is a library for composing asynchronous and event-based programs using observable collections.

I am aware of rule engines such as Drools from JBOSS, but is there some other way that is closer to the Microsoft .NET approach?

like image 466
Timo Westkämper Avatar asked May 16 '10 18:05

Timo Westkämper


People also ask

What is Reactive Extensions Java?

Reactive Extensions: Popularly known as ReactiveX, they provide API for asynchronous programming with observable streams. These are available for multiple programming languages and platforms, including Java where it's known as RxJava.

What are reactive applications in Java?

#1 What is reactive programming in a few words? Reactive programming is a programming paradigm that deals with asynchronous data streams (sequences of events) and the specific propagation of change, which means it implements modifications to the execution environment (context) in a certain order.

What is Rx in Java?

RxJava is a Java library that enables Functional Reactive Programming in Android development. It raises the level of abstraction around threading in order to simplify the implementation of complex concurrent behavior.

Does Java support reactive programming?

Reactive programming with Reactor in Java supported us in handling blocking IO (e.g. Kafka, gRPC), backpressure, thread handling/scheduling, and error handling effectively.


1 Answers

RxJava (RX ported by Netflix) is available and stable here: https://github.com/ReactiveX/RxJava.

It even works with Java 8's lambda syntax pretty well! You can do stuff like that:

Observable
  .from(Arrays.asList(1, 2, 3, 4, 5))
  .filter(val -> val % 2 == 0)
  .map(val -> val * val)
  .scan(0, (prev, curr) -> prev + curr)
  .subscribe(System.out::println)

Pretty cool a?

like image 147
meddle Avatar answered Oct 01 '22 03:10

meddle