Async Programming with Project Reactor and the new Azure SDK for Java

Async Programming with Project Reactor and the new Azure SDK for Java

When we started re-designing the new Azure SDK for Java, we initially only offered asynchronous clients for interacting with Azure services. These clients would have only provided asynchronous, non-blocking APIs that are ideal for network operations, as they do not block threads waiting to get a response from the service.

When we started re-designing the new Azure SDK for Java, we initially only offered asynchronous clients for interacting with Azure services. These clients would have only provided asynchronous, non-blocking APIs that are ideal for network operations, as they do not block threads waiting to get a response from the service. Our goal was to enable application developers using Azure SDK to utilize their system resources efficiently to build scalable applications. When we conducted user studies, we realized that it was important to include synchronous clients to cater to a wider audience, and also make our client libraries approachable for users not familiar with asynchronous programming. So, all new Azure SDK for Java offers both asynchronous and synchronous clients. We do, however, recommend using the asynchronous clients for production systems to maximize the utilization of your system resources. In this post we’ll cover basic reactive programming concepts that developers using Azure SDK for Java can apply to quickly get started on using async clients.

Reactive Streams

If you look at the async client in the new Azure SDK for Java design guidelines, you’ll notice that instead of using [CompletableFuture](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html) provided by Java 8, our async APIs use reactive types. Why did we choose reactive types over types that are natively available in JDK?

Java 8 introduced some very useful features like Streams, Lambdas and CompletableFuture. CompletableFutures provide callback-based, non-blocking capabilities and the CompletionStageinterface allowed for easy composition of a series of asynchronous operations. Lambdas make these push-based APIs more readable. Lastly, Streams provide functional-style operations to handle a collection of data elements. However, there are some limitations. Streams are synchronous and cannot be reused. CompletableFuture allows you to make a single request, provides support for a callback, and expects a single response. Many cloud services require the ability to stream data – Event Hubs for instance.

Reactive streams overcome these limitations by supporting streaming transfer of elements from a source to the subscriber of the data. When a subscriber requests data from a source, the source can send any number of results back. These results don’t have to be sent all at once. The transfer can happen over a period of time as and when the source has data to send. In this model, the subscriber registers event handlers to process data when it arrives. This push-based interaction notifies the subscriber when the source is ready to send data, when there is an error or when there’s no further data to send. This is accomplished by having distinct signals – onSubscribe() to indicate the data transfer is about to begin, onError() to indicate there was an error which also marks the end of data transfer, onComplete() to indicate successful completion of data transfer. Unlike Java Streams, reactive streams treat errors as first-class events and have a dedicated channel for the source to communicate any errors to the subscriber. Additionally, reactive streams allow subscriber to negotiate the rate at which the data is transferred that can transform these streams into a push-pull model.

azure sdk async programming azure-sdk java project reactor

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Azure SDK for Java Logging in Azure Functions | Azure SDK Blog

In this post we will learn about Azure SDK for Java application and HTTP logging scenarios in an Azure Functions environment. We will look at the scenario of managing secrets in the Azure Key Vault with the Key Vault and Identity client libraries and how to activate and access the SDK logs in the Azure Functions environment.

How to Install OpenJDK 11 on CentOS 8

What is OpenJDK? OpenJDk or Open Java Development Kit is a free, open-source framework of the Java Platform, Standard Edition (or Java SE).

Java NIO FileSystem APIs and the new Azure SDK for Java

The Azure SDK for Java recently released a preview of a custom implementation of Java’s FileSystem APIs (the azure-storage-blob-nio package on Maven), enabling developers to access Azure Blob Storage through a familiar file system interface. By adding this new dependency, you can easily instruct the JVM to point all file system operations to Azure Blob Storage rather than the local system.

Top Android Projects with Source Code

Android projects with source code - Work on real-time android projects. We’ll start project ideas from beginners level and later move to advance projects.

Azure SDK: What's new in the Azure Identity August 2020 General Availability Release

Since we shipped the first Azure Identity library preview in June 2019, it has been a vital part of building Azure cloud solutions. We have received great feedback from our development community and have added new features and have fixed many bugs.