Hands-On Reactive Programming with Reactor

Book description

Discover how project Reactor enhances the reactive programming paradigm and allows you to build scalable asynchronous applications

Key Features

  • Use reactive APIs, Flux, and Mono to implement reactive extensions
  • Create concurrent applications without the complexity of Java's concurrent API
  • Understand techniques to implement event-driven and reactive applications

Book Description

Reactor is an implementation of the Java 9 Reactive Streams specification, an API for asynchronous data processing. This specification is based on a reactive programming paradigm, enabling developers to build enterprise-grade, robust applications with reduced complexity and in less time. Hands-On Reactive Programming with Reactor shows you how Reactor works, as well as how to use it to develop reactive applications in Java.

The book begins with the fundamentals of Reactor and the role it plays in building effective applications. You will learn how to build fully non-blocking applications and will later be guided by the Publisher and Subscriber APIs. You will gain an understanding how to use two reactive composable APIs, Flux and Mono, which are used extensively to implement Reactive Extensions. All of these components are combined using various operations to build a complete solution.

In addition to this, you will get to grips with the Flow API and understand backpressure in order to control overruns. You will also study the use of Spring WebFlux, an extension of the Reactor framework for building microservices.

By the end of the book, you will have gained enough confidence to build reactive and scalable microservices.

What you will learn

  • Explore benefits of the Reactive paradigm and the Reactive Streams API
  • Discover the impact of Flux and Mono implications in Reactor
  • Expand and repeat data in stream processing
  • Get to grips with various types of processors and choose the best one
  • Understand how to map errors to make corrections easier
  • Create robust tests using testing utilities offered by Reactor
  • Find the best way to schedule the execution of code

Who this book is for

If you're looking to develop event- and data-driven applications easily with Reactor, this book is for you. Sound knowledge of Java fundamentals is necessary to understand the concepts covered in the book.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On Reactive Programming with Reactor
  3. Packt Upsell
    1. Why subscribe?
    2. Packt.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  6. Getting Started with Reactive Streams
    1. Technical requirements 
    2. Reactive architecture
      1. Reactive programming
    3. ReactiveX
      1. Composite streams
      2. Flexible operators
    4. Reactive Streams
      1. Asynchronous processing
      2. Subscriber backpressure
      3. David Karnok's classification
        1. Zero generation
        2. First generation
        3. Second generation
        4. Third generation
        5. Fourth generation
        6. Fifth generation
    5. Reactor
      1. Infinite data streams
      2. Push-pull model
      3. Concurrency agnostic
      4. Operator vocabulary
      5. Project setup
    6. Summary
    7. Questions
    8. Further reading
  7. The Publisher and Subscriber APIs in a Reactor
    1. Technical requirements
    2. Stream publisher
    3. Stream subscriber
      1. Subscription
    4. Reactive Streams comparison
      1. The Observable interface
      2. Java Messaging Service API
      3. Learning about the Reactor Core API
    5. The Flux API
      1. Generating the Flux API
        1. The Flux.just method
        2. The Flux.from methods
        3. Utility methods
        4. The Flux.generate method
          1. SynchronousSink
        5. Flux.create
    6. The Mono API
      1. Generating a Mono
        1. The Mono.just method
        2. The Mono.from method
        3. Utility methods
        4. Mono.create
    7. Building subscribers to Flux and Mono
      1. Lifecycle hooks
      2. Trying a hands-on project
    8. Summary
    9. Questions
    10. Further reading
  8. Data and Stream Processing
    1. Technical requirements
      1. Generating data
    2. Filtering data
      1. The filter() operator
        1. The take operator
        2. The skip operator
    3. Converting data
      1. The map() operator
      2. The flatMap operator
      3. The repeat operator
        1. The collect operator
        2. The collectMap operator
      4. The reduce operator
      5. Conditional tests
      6. Appending data
        1. The concatWith operator
    4. Summary
    5. Questions
  9. Processors
    1. Technical requirements 
    2. An introduction to processors
      1. Understanding processor types
        1. The DirectProcessor type
        2. The UnicastProcessor type
        3. The EmitterProcessor type
        4. The ReplayProcessor type
        5. The TopicProcessor type
        6. The WorkQueueProcessor type
    3. Hot versus Cold publishers
    4. Summary
    5. Questions
  10. SpringWebFlux for Microservices
    1. Technical requirements
    2. Introduction to SpringWebFlux
      1. Configuring annotations
        1. SpringBoot Starter
        2. Adding a controller
        3. Method parameters
        4. Exception handling
      2. Configuring functions
        1. The handler function
        2. The router function
        3. HandlerFilter
        4. HttpHandler
        5. Fibonacci functional router
    3. Summary
    4. Questions
  11. Dynamic Rendering
    1. Technical requirements 
    2. View templates
      1. Resolving views
      2. Freemarker
      3. Thymeleaf
      4. Scripting
        1. Mustache
    3. Learning about static resources
    4. WebClient
    5. Summary
    6. Questions
  12. Flow Control and Backpressure
    1. Technical requirements
    2. Flow control
      1. The groupBy operator
      2. The buffer operator
      3. The window operator
      4. The sample operator
    3. Backpressure
      1. OnBackpressure
    4. Summary
    5. Questions
  13. Handling Errors
    1. Technical requirements
    2. Generating errors
      1. Checked exceptions
      2. The doOnError hook
      3. The doOnTerminate hook
      4. The doFinally hook
    3. Error recovery
      1. The onErrorReturn operator
      2. The onErrorResume operator
      3. The onErrorMap operator
    4. Timeout
    5. WebClient
    6. Summary
    7. Questions
  14. Execution Control
    1. Technical requirements
    2. Scheduler
      1. Reactor schedulers
        1. The immediate scheduler
        2. The single scheduler
        3. The parallel scheduler
        4. The elastic scheduler
        5. The ExecutorService scheduler
    3. Parallel processing
      1. PublishOn operator
      2. SubscribeOn operator
      3. ParallelFlux
    4. Broadcasting
      1. The replay operator
      2. The publish operator
    5. Summary
    6. Questions
  15. Testing and Debugging
    1. Technical requirements
    2. Testing Reactor pipelines
      1. StepVerifier
        1. expectError
        2. expectNext
        3. Capture values
        4. Verify
        5. Validating backpressure
        6. Validating time operations
      2. Publisher probe
      3. Publisher stubs
    3. Debugging Reactor streams
      1. Debug hook
      2. Checkpoint operator
      3. Stream logging
    4. Summary
    5. Questions
  16. Assessments
    1. Chapter 1: Getting Started with Reactive Streams
    2. Chapter 2: The Publisher and Subscriber APIs in a Reactor
    3. Chapter 3: Data and Stream Processing
    4. Chapter 4: Processors
    5. Chapter 5: SpringWebFlux for Microservices
    6. Chapter 6: Dynamic Rendering
    7. Chapter 7: Flow Control and Backpressure
    8. Chapter 8: Handling Errors
    9. Chapter 9: Execution Control
    10. Chapter 10: Testing and Debugging
  17. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Hands-On Reactive Programming with Reactor
  • Author(s): Rahul Sharma
  • Release date: September 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781789135794