REACTIVE PROGRAMMING WITH SPRING WEBFLUX
by Ualter Jr.

REACTIVE PROGRAMMING WITH SPRING WEBFLUX

REACTIVE PROGRAMMING

Recently we are frequently hearing about a new paradigm of coding that is gaining more and more attention, the so mentioned Reactive Programming. The flow of information on the internet regarding what this “hype” is all about is getting noisier, lots and lots of information explaining this model is flowing throughout several technology channels.

Reactive Programming is a model of coding where the communication mainly happens throughout a non-blocking stream of data. This model of programming, turn your code to be “reactive”, reacting to change and not being blocked, as performing operations that read and wait for responses from a database or file. Hence, in this manner, we enter in a mode where we are reacting to events, as data are becoming available. Its principles are based on the Reactive Manifesto.

BACKPRESSURE

One important aspect, worth to mention, regarding this non-blocking processing, is the concept of the backpressure. This is a mechanism that must ensure producers don’t overwhelm consumers. So, for instance, if the consumer can’t handle more than 100 HTTP Requests by second, if eventually, this occurs, the consumer must slow down the flow or even stop for a moment, until the situation gets normalized again.

Hence, in order to deal with an enormous flow of data, this is an important aspect to take into consideration, this way we can ensure the producers won’t overwhelm the consumers.

SPECIFICATION, IMPLEMENTATIONS, LIBRARIES AND SPRING WEBFLUX

Reactive ProgrammingReactive Streams, and Reactor. What do they have to do with each other? At the start, as we faced this terms reading about the subject, it might be confused figure out what is the difference between them, as we are always seeing those words being used interchangeably. But, actually, they are not exactly the same thing. So, Just to get a clearer view of them, let’s summarize:

  • Reactive Programming: this is the paradigm, the model that dictates and the reason for the existence of the others below
  • Reactive Streams: this is a specification that defines how should work an API that implements and follows the Reactive Programming paradigm. By the way, JDK 9 it comes already prepared with it.
  • Reactor: this is a Java implementation of the Reactive Streams specification, consequently bring to Java the Reactive Programming model.

Spring WebFlux, is the “reaction” of the Spring for this paradigm to use on web applications. It is a web framework that brings the support for the reactive programming model. The Spring WebFlux it is implemented using the Project Reactor, the library chosen by Spring.

The WebFlux It is not a replacement for the Spring MVC, actually, they can complement each other, working together at the same solution. We are going to use it in our sample to better understand how everything works.

THE PROBLEM AND THE SOLUTION, HANDS ON!

Let’s travel a little bit to the future, not so very far, we are kind of in this future already. Imagine a Highway, those with a heavy traffic, with a flow of vehicles that could reach something like 5.000 vehicles by hour at the highest peak of a day, even more on holidays. In this future, all vehicles are obligated to have installed an RFID that transmits some data calculated by the vehicle’s computer. In some places in this highway, we have receptors installed, receiving all information of the vehicles, like plate number, weight, speed, color, etc.

That information is flowing as a data stream all the time around to a host of...

Read the whole article at... (the source code is at GitHub)

https://ualterazambuja.com/2018/04/22/reactive-programming-with-spring-webflux/

要查看或添加评论,请登录

Ualter Otoni Pereira的更多文章

  • AWS Terraform Snitcher

    AWS Terraform Snitcher

    Snitch (chivato in Spanish, “dedo-duro” in slang Portuguese), if you usually watch CNN, mainly political subjects…

  • KUBERNETES OPERATORS IN GO

    KUBERNETES OPERATORS IN GO

    An Operator is a software application written to run over Kubernetes, extending its functionalities to manage other…

  • Microservices: Quarkus vs. Spring Boot

    Microservices: Quarkus vs. Spring Boot

    In the era of containers (the “Docker Age“) Java still keeps alive, being struggling for it or not. Java has always…

    3 条评论
  • AWS ECS EC2, Cloud & Containers, Part II

    AWS ECS EC2, Cloud & Containers, Part II

    In this two-part article about Cloud and Containers working together, here in the second part we will try out the AWS…

    1 条评论
  • AWS ECS Fargate, Cloud & Containers, Part I

    AWS ECS Fargate, Cloud & Containers, Part I

    Let’s talk about Cloud and Containers working together, in this article we’ll see (in practice) how to run, scale and…

  • BUILDING A CRYPTOCURRENCY WITH BLOCKCHAIN

    BUILDING A CRYPTOCURRENCY WITH BLOCKCHAIN

    If you have a cryptocurrency, then you own something digitally, you have an asset, considered to be a coin because it…

    1 条评论
  • OAUTH2 & GOOGLE API PART II

    OAUTH2 & GOOGLE API PART II

    In the first part of this article we have seen an introduction regard some basic concepts of this industry-standard…

  • OAUTH2 & GOOGLE API PART I

    OAUTH2 & GOOGLE API PART I

    OAuth 2.0, commonly pronounced “oh-auth”, is an industry-standard framework for *authentication and *authorization…

  • Web Services Asynchronous

    Web Services Asynchronous

    Perhaps something very different and weird to see around is an asynchronous web services, but yes! This beast really…

  • Messaging Request/Reply

    Messaging Request/Reply

    Messaging Integration Style Fire-and-Forget Pattern When we think integration using messaging style, what usually comes…

    1 条评论

社区洞察

其他会员也浏览了