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)