Preface....7
Who Should Read This Book?....8
What About Quarkus?....9
Navigating This Book....9
Getting You Ready....11
Conventions Used in This Book....16
OReilly Online Learning....17
How to Contact Us....18
Acknowledgments....18
I. Reactive and Quarkus Introduction....20
1. Reactive in a Nutshell....21
What Do We Mean by Reactive?....21
Reactive Software Is Not New....22
The Reactive Landscape....23
Why Are Reactive Architectures So Well-Suited for Cloud Native Applications?....27
Reactive Is Not a Silver Bullet....27
2. Introduction to Quarkus....29
Java on the Cloud....29
Thorntail Example....34
Quarkus Example....37
The Quarkus Way....29
Create Your First Quarkus Application....29
Kubernetes with Quarkus in 10 Minutes....29
Going Native....59
Summary....64
II. Reactive and Event-Driven Applications....66
3. The Dark Side of Distributed Systems....67
Whats a Distributed System?....67
The New Kids on the Block: Cloud Native and Kubernetes Native Applications....67
The Dark Side of Distributed Systems....79
Fallacies of Distributed Computing in a Kubernetes World....80
A Question of Timing: The Synchronous Communication Drawback....83
Summary....91
4. Design Principles of Reactive Systems....93
Reactive Systems 101....93
Commands and Events....96
Commands....96
Events....97
Messages....97
Commands Versus Events: An Example....98
Destinations and Space Decoupling....102
Time Decoupling....105
The Role of Nonblocking InputOutput....93
Blocking Network IO, Threads, and Concurrency....107
How Does Nonblocking IO Work?....111
Reactor Pattern and Event Loop....93
Anatomy of Reactive Applications....116
Summary....121
5. Reactive Programming: Taming the Asynchronicity....122
Asynchronous Code and Patterns....122
Using Futures....129
Project Loom: Virtual Threads and Carrier Threads....132
Reactive Programming....122
Streams....137
Operators....139
Reactive Programming Libraries....145
Reactive Streams and the Need for Flow Control....145
Buffering Items....147
Dropping Items....148
What Is Backpressure?....149
Introducing Reactive Streams....149
Be Warned: Its a Trap!....153
Backpressure in Distributed Systems....153
Summary....154
III. Building Reactive Applications and Systems with Quarkus....156
6. Quarkus: Reactive Engine....157
The Imperative Model....157
The Reactive Model....161
Unification of Reactive and Imperative....157
A Reactive Engine....157
A Reactive Programming Model....171
Event-Driven Architecture with Quarkus....172
Summary....173
7. Mutiny: An Event-Driven Reactive Programming API....175
Why Another Reactive Programming Library?....175
What Makes Mutiny Unique?....177
Mutiny Usage in Quarkus....177
Uni and Multi....178
Mutiny and Flow Control....183
Observing Events....184
Transforming Events....185
Chaining Asynchronous Actions....186
Recovering from Failure....189
Combining and Joining Items....190
Selecting Items....192
Collecting Items....193
Summary....194
8. HTTP with Reactive in Mind....195
The Journey of an HTTP Request....196
Say Hello to RESTEasy Reactive!....198
Whats the Benefit?....201
Asynchronous Endpoints Returning Uni....204
Dealing with Failure and Customizing the Response....206
Streaming Data....210
Raw Streaming....210
Streaming JSON Array....212
Using Server-Sent-Events....215
Reactive Score....216
Summary....218
9. Accessing Data Reactively....220
The Problem with Data Access....220
Nonblocking Interactions with Relational Databases....223
Using a Reactive ORM: Hibernate Reactive....227
What About NoSQL?....231
Interacting with Redis....232
Data-Related Events and Change Data Capture....236
Using Debezium to Capture Change....239
Summary....243
IV. Connecting the Dots....245
10. Reactive Messaging: The Connective Tissue....246
From Reactive Applications to Reactive Systems....246
Channels and Messages....247
Producing Messages....248
Consuming Messages....252
Processing Messages....254
Acknowledgments....256
Connectors....258
Building Message-Based Applications....258
Message and Acknowledgment....260
Failures and Negative Acknowledgment....262
Stream Manipulation....263
Blocking Processing....265
Retrying Processing....266
Putting Everything Together....267
Summary....271
11. The Event Bus: The Backbone....272
Kafka or AMQP: Picking the Right Tool....272
Building Reactive Systems with Kafka....273
Apache Kafka....273
Point-to-Point Communication....280
PublishSubscribe....282
Elasticity Patterns....283
Dealing with Failures....284
Backpressure and Performance Considerations....287
Kafka on Kubernetes....272
Building Reactive Systems with AMQP....292
AMQP 1.0....292
Point-to-Point Communication....293
PublishSubscribe....295
Elasticity Patterns....296
Acknowledgment and Redelivery....297
Credit-Flow Backpressure Protocol....298
AMQP on Kubernetes....298
Summary....300
12. Reactive REST Client: Connecting with HTTP Endpoints....302
Interacting with an HTTP Endpoint....302
The REST Client Reactive....305
Mapping HTTP APIs to Java Interfaces....306
Invoking the Service....309
Blocking and Nonblocking....310
Handling Failures....311
Fallback....312
Retries....314
Time-out....315
Bulkheads and Circuit Breaker....315
Building API Gateways with the RESTEasy Reactive Client....317
Using the REST Client in Messaging Applications....324
Summary....328
13. Observing Reactive and Event-Driven Architectures....330
Why Is Observability Important?....330
Health with Messaging....332
Metrics with Messaging....339
Distributed Tracing with Messaging....344
Summary....348
Conclusion....350
A Brief Summary....350
Is That All?....351
The Future of Reactive Systems....352
The End of the Beginning....353
Index....354
Reactive systems and event-driven architecture are becoming indispensable to application design, and companies are taking note. Reactive systems ensure that applications are responsive, resilient, and elastic no matter what failures or errors may be occurring, while event-driven architecture offers a flexible and composable option for distributed systems. This practical book helps Java developers bring these approaches together using Quarkus 2.x, the Kubernetes-native Java framework.
Clement Escoffier and Ken Finnigan show you how to take advantage of event-driven and reactive principles to build robust distributed systems, reducing latency and increasing throughput, particularly in microservices and serverless applications. You'll also get a foundation in Quarkus to help you create true Kubernetes-native applications for the cloud.