Skip to content


Subversion checkout URL

You can clone with
Download ZIP
SQS async w/callbacks adapter
Java Groovy
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
LICENSE.txt added blog post as resource
build.gradle moved tests around and started a functional test that relies on a loc…

Ahoy! Asynchronous SQS

Ahoy! is an asynchronous SQS adapter for AWS's Java SQS library. While the SDK provided by AWS does include a AmazonSQSAsyncClient, this implementation uses Futures. I think Java's Futures are slick, however, they put the onus on the caller to poll for an end state. That is, you don't fire-and-forget -- you fire and poll. Then forget.

Ahoy! is designed to be fire-and-forget. Naturally, you don't necessarily want to forget receiving a message; thus, Ahoy! leverages callbacks. Callbacks in Java can be implemented via anonymous classes like so:

SQSAdapter sqs = new SQSAdapter("key", "secret", "some queue");
sqs.receive(new MessageReceivedCallback() {
  public void onReceive(String messageId, String message) {
    //do something w/the message!

In the code above, onReceive will be invoked once a message is popped off of an SQS queue named "some queue" -- note, the callback receives the message body as well as the messages ID (all provided via the SDK Message object).

You can attach a callback on a send as well:

SQSAdapter sqs = new SQSAdapter("key", "secret", "some queue");
sqs.send("Message", new MessageSentCallback() {
  public void onSend(String messageId) {
    //if you need to do something w/the messageId from AWS...

In this case, you can get a receipt in the form of the AWS ID attached to the SQS message. send is overridden; thus, you do not have to pass in an implementation of MessageSentCallback.

Notice something else? Yeah, that's right, you don't have to deal with the myriad AWS SDK classes required to receive or send a message. No dealing with SendMessageResult, Message, SendMessageRequest, DeleteMessageRequest, ReceiveMessageRequest, and the list goes on.

Maven, Gradle, etc

To build with Maven, add the dependencies listed below to your pom.xml file:


Alternatively, if you want to use Gradle, add this to your build.gradle file:

compile 'com.github.aglover:ahoy:1.0.1'

For other build tools like SBT, etc, see Ahoy's page.

Some more details

This is important so read up.

  • receive will delete the message off of the SQS queue
  • receive will listen for 20 seconds and grab up to 10 messages and the onReceive callback will be invoked for each message
  • reread that last point, please

Helpful resources

Check out these handy-dandy resources:

Something went wrong with that request. Please try again.