8 Reactive programming

 

This chapter covers

  • Learning what reactive programming is
  • Identifying why we want to write reactive code
  • Explaining SmallRye Mutiny as the reactive library used in Quarkus
  • Analyzing how the reactive paradigm integrates into the Quarkus architecture

8.1 Being Reactive

As we learned in previous chapters, the reactive programming paradigm is an alternative way of writing software programs. In contrast to the imperative model, which executes the program as a sequence of ordered steps, reactive programming focuses on asynchronous executions that notify the caller about the result only when the result computes or an error occurs. In this way, the caller is free to do any other work in the meantime and return to the request processing only when there is progress. This means that reactive systems can be more responsive and scalable as the same resources (both software and hardware) can do more work in the same time window.

Quarkus is built on top of a reactive engine, meaning writing reactive programs is straightforward. However, if you prefer the imperative model, you can still write the same applications you are used to.

8.1.1 Handling of I/O operations

8.1.2 Writing reactive code

8.2 Mutiny

8.2.1 Reactive streams

8.2.2 Mutiny API

8.2.3 Using Mutiny in user applications

8.3 Reactive engine

8.4 Making Car Rental reactive

8.4.1 Reservation service

8.4.2 Inventory service

8.5 Virtual threads with project Loom

8.5.1 Project Loom in Quarkus

8.5.2 Problems with project Loom

8.6 Wrap up and next steps

8.7 Summary