Reactive Systems in Java

Book description

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.

  • Understand the fundamentals of reactive systems and event-driven architecture
  • Learn how to use Quarkus to build reactive applications
  • Combine Quarkus with Apache Kafka or AMQP to build reactive systems
  • Develop microservices that utilize messages with Quarkus for use in event-driven architectures
  • Learn how to integrate external messaging systems, such as Apache Kafka, with Quarkus
  • Build applications with Quarkus using reactive systems and reactive programming concepts

Table of contents

  1. Preface
    1. Who Should Read This Book?
    2. What About Quarkus?
    3. Navigating This Book
    4. Getting You Ready
    5. Conventions Used in This Book
    6. O’Reilly Online Learning
    7. How to Contact Us
    8. Acknowledgments
  2. I. Reactive and Quarkus Introduction
  3. 1. Reactive in a Nutshell
    1. What Do We Mean by Reactive?
    2. Reactive Software Is Not New
    3. The Reactive Landscape
    4. Why Are Reactive Architectures So Well-Suited for Cloud Native Applications?
    5. Reactive Is Not a Silver Bullet
  4. 2. Introduction to Quarkus
    1. Java on the Cloud
      1. Thorntail Example
      2. Quarkus Example
    2. The Quarkus Way
    3. Create Your First Quarkus Application
    4. Kubernetes with Quarkus in 10 Minutes
    5. Going Native
    6. Summary
  5. II. Reactive and Event-Driven Applications
  6. 3. The Dark Side of Distributed Systems
    1. What’s a Distributed System?
    2. The New Kids on the Block: Cloud Native and Kubernetes Native Applications
    3. The Dark Side of Distributed Systems
    4. Fallacies of Distributed Computing in a Kubernetes World
    5. A Question of Timing: The Synchronous Communication Drawback
    6. Summary
  7. 4. Design Principles of Reactive Systems
    1. Reactive Systems 101
    2. Commands and Events
      1. Commands
      2. Events
      3. Messages
      4. Commands Versus Events: An Example
    3. Destinations and Space Decoupling
    4. Time Decoupling
    5. The Role of Nonblocking Input/Output
      1. Blocking Network I/O, Threads, and Concurrency
      2. How Does Nonblocking I/O Work?
      3. Reactor Pattern and Event Loop
    6. Anatomy of Reactive Applications
    7. Summary
  8. 5. Reactive Programming: Taming the Asynchronicity
    1. Asynchronous Code and Patterns
    2. Using Futures
    3. Project Loom: Virtual Threads and Carrier Threads
    4. Reactive Programming
      1. Streams
      2. Operators
      3. Reactive Programming Libraries
    5. Reactive Streams and the Need for Flow Control
      1. Buffering Items
      2. Dropping Items
      3. What Is Backpressure?
      4. Introducing Reactive Streams
      5. Be Warned: It’s a Trap!
      6. Backpressure in Distributed Systems
    6. Summary
  9. III. Building Reactive Applications and Systems with Quarkus
  10. 6. Quarkus: Reactive Engine
    1. The Imperative Model
    2. The Reactive Model
    3. Unification of Reactive and Imperative
    4. A Reactive Engine
    5. A Reactive Programming Model
    6. Event-Driven Architecture with Quarkus
    7. Summary
  11. 7. Mutiny: An Event-Driven Reactive Programming API
    1. Why Another Reactive Programming Library?
    2. What Makes Mutiny Unique?
    3. Mutiny Usage in Quarkus
    4. Uni and Multi
    5. Mutiny and Flow Control
    6. Observing Events
    7. Transforming Events
    8. Chaining Asynchronous Actions
    9. Recovering from Failure
    10. Combining and Joining Items
    11. Selecting Items
    12. Collecting Items
    13. Summary
  12. 8. HTTP with Reactive in Mind
    1. The Journey of an HTTP Request
    2. Say Hello to RESTEasy Reactive!
    3. What’s the Benefit?
    4. Asynchronous Endpoints Returning Uni
    5. Dealing with Failure and Customizing the Response
    6. Streaming Data
      1. Raw Streaming
      2. Streaming JSON Array
      3. Using Server-Sent-Events
    7. Reactive Score
    8. Summary
  13. 9. Accessing Data Reactively
    1. The Problem with Data Access
    2. Nonblocking Interactions with Relational Databases
    3. Using a Reactive ORM: Hibernate Reactive
    4. What About NoSQL?
    5. Interacting with Redis
    6. Data-Related Events and Change Data Capture
    7. Using Debezium to Capture Change
    8. Summary
  14. IV. Connecting the Dots
  15. 10. Reactive Messaging: The Connective Tissue
    1. From Reactive Applications to Reactive Systems
      1. Channels and Messages
      2. Producing Messages
      3. Consuming Messages
      4. Processing Messages
      5. Acknowledgments
      6. Connectors
    2. Building Message-Based Applications
      1. Message and Acknowledgment
      2. Failures and Negative Acknowledgment
      3. Stream Manipulation
      4. Blocking Processing
      5. Retrying Processing
    3. Putting Everything Together
    4. Summary
  16. 11. The Event Bus: The Backbone
    1. Kafka or AMQP: Picking the Right Tool
    2. Building Reactive Systems with Kafka
      1. Apache Kafka
      2. Point-to-Point Communication
      3. Publish/Subscribe
      4. Elasticity Patterns
      5. Dealing with Failures
      6. Backpressure and Performance Considerations
      7. Kafka on Kubernetes
    3. Building Reactive Systems with AMQP
      1. AMQP 1.0
      2. Point-to-Point Communication
      3. Publish/Subscribe
      4. Elasticity Patterns
      5. Acknowledgment and Redelivery
      6. Credit-Flow Backpressure Protocol
      7. AMQP on Kubernetes
    4. Summary
  17. 12. Reactive REST Client: Connecting with HTTP Endpoints
    1. Interacting with an HTTP Endpoint
    2. The REST Client Reactive
      1. Mapping HTTP APIs to Java Interfaces
      2. Invoking the Service
    3. Blocking and Nonblocking
    4. Handling Failures
      1. Fallback
      2. Retries
      3. Time-out
      4. Bulkheads and Circuit Breaker
    5. Building API Gateways with the RESTEasy Reactive Client
    6. Using the REST Client in Messaging Applications
    7. Summary
  18. 13. Observing Reactive and Event-Driven Architectures
    1. Why Is Observability Important?
    2. Health with Messaging
    3. Metrics with Messaging
    4. Distributed Tracing with Messaging
    5. Summary
  19. Conclusion
    1. A Brief Summary
    2. Is That All?
    3. The Future of Reactive Systems
    4. The End of the Beginning
  20. Index

Product information

  • Title: Reactive Systems in Java
  • Author(s): Clement Escoffier, Ken Finnigan
  • Release date: November 2021
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781492091721