Reactive programming tutorial: Introduction
Tutorial: Reactive programming introduction
This is the first of a four-part interactive tutorial on reactive programming and Vert.x. The tutorial can be viewed in full at developers.redhat.com/coderland/reactive/.
The reactive system built in this exercise represents data about the Reactica roller coaster at Coderland, an imaginary theme park that showcases modern technologies and techniques. The Reactica system contains multiple components that use Red Hat AMQ, Red Hat Data Grid, and the Vert.x event bus to pass data asynchronously. The end result is a web UI that calculates the current wait time for the coaster based on the number of people in line, the length of the ride, and how many people can ride at once.
The web UI also displays a list of users. That includes park guests who are still in line, guests who are currently on the ride, and a few of the guests who have already ridden the coaster. The entire display is driven by a sophisticated infrastructure that illustrates the power and flexibility of reactive programming.
Your assignment: Build the web UI that shows Coderland guests how long they'll have to wait before experiencing the awesomeness of the Reactica roller coaster.
- The Reactica roller coaster: github.com/reactica/rhte-demo
- A Vert.x starter application: github.com/redhat-developer-demos/vertx-starter
- Reactica Part 1: An introduction to reactive programming and Vert.x
- Reactica Part 2: Building a reactive system
- Reactica Part 3: A reactive system in action
- Free book - Building Reactive Microservices in Java
- The Reactive Manifesto
- Andre Staltz's reactive programming tutorial
The following is a Coderland presentation about our newest attraction, the Reactica roller coaster.
Greetings, Coders! This is Doug Tidwell. As we see the majestic Coderland Special rolling into the station with a load of happy coders, bituminous coal, and Da-RHEL, the best rhino there ever was, it's time for another exciting announcement from Coderland.
The park's extensive lineup of attractions now includes Reactica, a state-of-the-art roller coaster that takes guests through a terrifying journey on perhaps the most futuristic coaster ever built. Let's take a look at this 21st Century marvel in action.
[Video of a rickety old wooden roller coaster that crashes]
Clearly our engineers have outdone themselves in building this next-generation ride. As our early guests stared in slack-jawed wonder at this spectacle, many of them asked about the wait time for such a unique attraction.
Your assignment, should you choose to accept it, is to build a web interface that shows the continuously updated wait time for the ride. You'll use event data from the ride itself, including whenever the coaster leaves the station, when it returns, when the ride is shut down due to accidents, and of course, whenever the wreckage is cleared and the ride reopens.
In addition to ride events, you'll also process events from park guests. Every time the coaster leaves the station, the status a few lucky guests changes from "waiting in line" to "on the ride." A short time later, their status changes to "completed the ride." Your web UI needs to reflect all of those changes.
You may have already recognized this as a perfect scenario for reactive programming. That's the focus of what we'll cover here. The code uses the Eclipse Vert.x toolkit to handle the events that move through the system. Those events are delivered via the Red Hat AMQ message broker and Red Hat Data Grid.
The code uses the event infrastructure to generate this web UI. [Screen shot of the web UI]
It shows the current wait time as well as a list of the guests in line. This UI is displayed on monitors in the station as guests move through the queue, giving them constant feedback as to how the line is moving, uh, IF the line is moving.
For administrators, there is a second UI to manage the ride. We'll take a quick look at that as well.
There are three more videos to help you build this solution. The first serves as a quick introduction to reactive programming and Vert.x, then the second covers the different components and how they work together. The third shows you the ride in action, so you can see how events are generated by the ride and its riders and how those events are consumed by the components that calculate the wait time.
We think this is a great introduction to reactive programming and reactive systems. We had a lot of fun putting it together and we hope you enjoy it.
For Coderland, this is Doug Tidwell, saying may all your bugs be shallow. Cheers.
[train noises fading into the distance]