Code Monkey home page Code Monkey logo

ahoy's Introduction

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.

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:

ahoy's People

Contributors

aglover avatar danveloper avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.