DEV Community

codebodhi
codebodhi

Posted on

Java SQS Listener: A Minimal, High-Performance Library for Polling AWS SQS

๐Ÿค” The Problem With Polling SQS in Java

Polling messages from Amazon SQS seems simple โ€” until itโ€™s not. You need to continuously fetch messages, process them concurrently, delete the successful ones, and retry failures with appropriate delays. Getting this right, especially at scale, means dealing with multithreading, visibility timeouts, and reliability โ€” often with verbose or heavyweight tooling.

Libraries like Springโ€™s SQS support exist, but they come with trade-offs: framework lock-in, complex dependency graphs, and upgrade pains that stall your agility.

Thatโ€™s exactly why I built java-sqs-listener โ€” a small, focused library designed for reliability without the bloat.

๐Ÿš€ Designed for Simplicity and Performance

java-sqs-listener is a lightweight (just 16 KB) Java library for polling Amazon SQS messages with minimal setup and maximum flexibility. Itโ€™s Java 8+ compatible, framework-agnostic, and battle-tested in real-world production environments.

๐Ÿ” What Makes It Stand Out

๐Ÿ’ก Lightweight
Just 16 KB โ€” ideal for containers, serverless, or any setup where lean is better.

โ˜• Java 8+ Compatible
Works seamlessly with Java 8 and up โ€” no need to upgrade your runtime.

๐Ÿงฉ Framework-Agnostic
Integrates with any Java application. Spring, Jakarta EE, Guice, or plain old Java โ€” no framework lock-in.

โš™๏ธ Minimal Setup
Start polling with just a queue name. Everything else is configurable, but optional.

โ™ป๏ธ Built-In Reliability
Automatically batches and deletes successful messages. Failed messages are retried with backoff.

๐Ÿ› ๏ธ Customizable and Extensible
Control concurrency, polling frequency, visibility timeout โ€” and even plug in your own SqsClient.

๐Ÿงช Production-Proven
Validated with Testcontainers and hardened in a high-throughput Spring Boot app on AWS EC2.

No magic, no bloat. Just a small, robust utility that does one thing โ€” and does it well.

๐Ÿ”ง Installation

Available on Maven Central:
Maven

<dependency>
 <groupId>com.codebodhi</groupId>
 <artifactId>java-sqs-listener</artifactId>
 <version>2.10.0</version>
</dependency>
Enter fullscreen mode Exit fullscreen mode

Gradle

implementation 'com.codebodhi:java-sqs-listener:2.10.0'

Enter fullscreen mode Exit fullscreen mode

๐Ÿ›  Example Usage

Minimal Plain Java Setup

new SqsListener("my-queue") {
    @Override
    public void process(String message) {
        // handle message
        System.out.println("Received: " + message);
    }
};
Enter fullscreen mode Exit fullscreen mode

With Custom Configuration

SqsListenerConfig config = SqsListenerConfig.builder()
    .parallelism(5)
    .pollingFrequency(Duration.ofSeconds(5))
    .visibilityTimeout(Duration.ofSeconds(60))
    .build();

new SqsListener("my-queue", config) {
    @Override
    public void process(String message) {
        // handle message
    }
};
Enter fullscreen mode Exit fullscreen mode

โ˜•๏ธ Spring Integration

Just define your config as a Spring bean:

@Configuration
public class SqsListenerConfiguration {
    @Bean("mySqsListenerConfig")
    public SqsListenerConfig config() {
        return SqsListenerConfig.builder()
            .parallelism(5)
            .pollingFrequency(Duration.ofSeconds(5))
            .visibilityTimeout(Duration.ofSeconds(60))
            .build();
    }
}
Enter fullscreen mode Exit fullscreen mode

Then wire up a Spring service that extends SqsListener:

@Service
public class MySqsListener extends SqsListener {
    public MySqsListener(
        @Value("${my-queue}") String queueName,
        @Qualifier("mySqsListenerConfig") SqsListenerConfig config
    ) {
        super(queueName, config);
    }

    @Override
    public void process(String message) {
        // process message
    }
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿ” Want to see it all in action?

Check out this fully working example on GitHub:

๐Ÿ‘‰ java-sqs-listener-springboot-example

๐Ÿ™Œ Wrap-Up

If youโ€™re building Java applications that polls AWS SQS and want a clean, dependency-free solution โ€” you might find java-sqs-listener just what you need.

๐Ÿ‘‰ View the GitHub repo

๐Ÿ“ฆ Check it out on Maven Central

๐Ÿ“‚ Explore the Spring Boot Example

Top comments (0)