Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Reactive Programming With Java 8

You're reading from   Learning Reactive Programming With Java 8 Learn how to use RxJava and its reactive Observables to build fast, concurrent, and powerful applications through detailed examples

Arrow left icon
Product type Paperback
Published in Jun 2015
Publisher Packt
ISBN-13 9781785288722
Length 182 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Nickolay Tzvetinov Nickolay Tzvetinov
Author Profile Icon Nickolay Tzvetinov
Nickolay Tzvetinov
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. An Introduction to Reactive Programming 2. Using the Functional Constructions of Java 8 FREE CHAPTER 3. Creating and Connecting Observables, Observers, and Subjects 4. Transforming, Filtering, and Accumulating Your Data 5. Combinators, Conditionals, and Error Handling 6. Using Concurrency and Parallelism with Schedulers 7. Testing Your RxJava Application 8. Resource Management and Extending RxJava Index

Why should we be reactive?

The easiest way for us to answer this question is to think about the requirements we have while building applications these days.

While 10-15 years ago it was normal for websites to go through maintenance or to have a slow response time, today everything should be online 24/7 and should respond with lightning speed; if it's slow or down, users would prefer an alternative service. Today slow means unusable or broken. We are working with greater volumes of data that we need to serve and process fast.

HTTP failures weren't something rare in the recent past, but now, we have to be fault-tolerant and give our users readable and reasonable message updates.

In the past, we wrote simple desktop applications, but today we write web applications, which should be fast and responsive. In most cases, these applications communicate with a large number of remote services.

These are the new requirements we have to fulfill if we want our software to be competitive. So in other words we have to be:

  • Modular/dynamic: This way, we will be able to have 24/7 systems, because modules can go offline and come online without breaking or halting the entire system. Additionally, this helps us better structure our applications as they grow larger and manage their code base.
  • Scalable: This way, we are going to be able to handle a huge amount of data or large numbers of user requests.
  • Fault-tolerant: This way, the system will appear stable to its users.
  • Responsive: This means fast and available.

Let's think about how to accomplish this:

  • We can become modular if our system is event-driven. We can divide the system into multiple micro-services/components/modules that are going to communicate with each other using notifications. This way, we are going to react to the data flow of the system, represented by notifications.
  • To be scalable means to react to the ever-growing data, to react to load without falling apart.
  • Reacting to failures/errors will make the system more fault-tolerant.
  • To be responsive means reacting to user activity in a timely manner.

If the application is event-driven, it can be decoupled into multiple self-contained components. This helps us become more scalable, because we can always add new components or remove old ones without stopping or breaking the system. If errors and failures are passed to the right component, which can handle them as notifications, the application can become more fault-tolerant or resilient. So if we build our system to be event-driven, we can more easily achieve scalability and failure tolerance, and a scalable, decoupled, and error-proof application is fast and responsive to users.

Why should we be reactive?

The Reactive Manifesto (http://www.reactivemanifesto.org/) is a document defining the four reactive principles that we mentioned previously. Each reactive system should be message-driven (event-driven). That way, it can become loosely coupled and therefore scalable and resilient (fault-tolerant), which means it is reliable and responsive (see the preceding diagram).

Note that the Reactive Manifesto describes a reactive system and is not the same as our definition of reactive programming. You can build a message-driven, resilient, scalable, and responsive application without using a reactive library or language.

Changes in the application data can be modeled with notifications, which can be propagated to the right handlers. So, writing applications using reactive programming is the easiest way to comply with the Manifesto.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime