
As part of this article let’s try to understand how can we integrate Spring cloud @SqsListener with Reactive Spring. But before we start on actual topic let’s try to understand what is this Reactive Spring and what are the benefits.
Reactive Spring
As per official documentation
Reactive systems have certain characteristics that make them ideal for low-latency, high-throughput workloads. Project Reactor and the Spring portfolio work together to enable developers to build enterprise-grade reactive systems that are responsive, resilient, elastic, and message-driven.
Reactive Spring (Project Reactor) is a non-blocking foundation with in-built back pressure enabled framework which enables developer to build non-blocking application. Reactive system better utilizes modern hardwares, ensuring better resilience between decoupled components.
Benefits for Reactive Spring
Many of you might already have understood the benefits of reactive spring, but just to be on same page, let’s list down the benefits —
- Non-blocking
- Better throughput/performance
- Better utilization of hardware
- Declarative programming approach
SQS Listener
Now that we understood what is Reactive Spring, let’s try to understand what is the usage of @SqsListerner.
In Event Driven Architecture, we can make use of @SqsListener to receive messages from Queue and do the required processing. Many of us write something similar to the following code to receive a message from SQS and delete it from SQS once successfully processed.

But here the issue is that we are using .block(), because of this operator code will perform like a normal blocking codebase. If this happens, there is no real benefit of the Reactive framework. So, how can we use the full potential of the reactive approach? 🤔
Manual Acknowledgement
To utilize full potential of reactive, we have to make a couple of changes in our codebase.
First, add or update your SQS config with following configuration,

Once you are done with config modification, change the above receiveMessage method something like the following,

Now, as you can see in this example we are using the .subscribe() operator, which is a non-blocking operator, i.e. we achieved fully reactive code with @SqsListener.
PS: I hope you’ve enjoyed it, and if you’ve found it useful, please feel free to share with others or leave a comment 😃. Incase you want check the entire file, you can check it here.
Originally posted on medium.com.