edubriguenti edubriguenti - 1 year ago 57
Java Question

Is it possible to build a Reactive Application using a non-Functional language?

I would like to understand if the principles behind the Reactive Application manifesto can be achieved using a non-functional language.

Some people say that since FP use immutable states and free side-effects functions, they are easier to implement concurrent, distributed and resilient systems.

But how can we achieve that using Java for example?

There are some frameworks like Apache Camel, that have some components to work with, like Camel RX, and Camel SEDA.

Are these frameworks enough?

I will try to clarify my question:

I think of reactive programming as new programming paradigm, and a new programming paradigm requires new tools and frameworks.

Functional languages deals with objects differently, that's why there's a lot of articles about FRP working with things event-based and asynchronously.

But now, backing to Java, or other Object Oriented language, let's think in a Web Application:

  1. How can we create a java web application that makes use of good
    event-based frontend.

  2. These events then pass information asynchronously in a smooth way to the backend.

  3. The backend can scale easily and be resilient as well.

I know that is possible to create an application that accomplish these requirements using java, and servlets, and EJBs, but my question is, can we do it differently?
More close to a reactive approach?

I thought something like this:

  • A nice ajax framework in the frontend, that makes the "passing information" with the backend smoothly.

  • In the backend a way to use a framework or library (Camel SEDA ou Camel RX) to execute things in parallel.

Do you think this is a good approach?

Answer Source

Reactive Programming is not new, but it is new to most people. It is simply another name for dataflow that has been around since the 1960's. The Reactive Manifesto is just way to describe the best qualities of Dataflow and Reactive Programming.

A functional language is certainly not needed nor is a huge library. I've implemented many dataflow systems. Most of them are more of a collection of helper functions than what most would call a "library." It really depends what type of features you want in the system.

Dataflow is a very "wide" topic. The system could include many nice-to-have features or it could just have the basics. The core of dataflow is that the data controls execution. This is in contrast to "contol-flow" (used in all mainstream languages like C# and Java) where you tell the computer when, where and how to process the data. The most common form of dataflow is the Pipeline model... a series of boxes (or nodes) connected sequentially to one another with links (aka pipes, wires or arcs).

I have just started to examine the libraries available for Java dataflow programming so I can't give you a specific answer right now. It seems that RxJava is current "name-brand" for dataflow in Java so I would start there. In my upcoming book ( I will devote a whole section to the available dataflow libraries in common languages, including Java.