Home

Awesome

aws-dropwizard

You can find the latest release on Maven Central: http://search.maven.org under:

Introduction

aws-dropwizard is a utility library that integrates the Amazon SQS and SNS offerings with the Dropwizard REST framework. It contains convenience classes for sending messages to - and receiving from - SQS queues while being managed by the Dropwizard framework. It also supports creating and managing SNS clients for push notifications.

Getting started

# Amazon SQS settings.
awsFactory:
  awsAccessKeyId: ...
  awsSecretKey: ...
  awsRegion: ...

sqsListenQueueUrl: https://sqs...
    @Valid
    @NotNull
    @JsonProperty
    private AwsFactory awsFactory;

    @NotNull
    @JsonProperty
    private String sqsListenQueueUrl;

    public AwsFactory getAwsFactory() {
        return sqsFactory;
    }

    public void setAwsFactory(AwsFactory awsFactory) {
        this.sqsFactory = sqsFactory;
    }

    public String getSqsListenQueueUrl() {
        return sqsListenQueueUrl;
    }

    public void setSqsListenQueueUrl(String sqsListenQueueUrl) {
        this.sqsListenQueueUrl = sqsListenQueueUrl;
    }

SQS

package ...;

import io.interact.sqsdw.sqs.MessageHandler;

public class MessageHandlerImpl extends MessageHandler {

	public MessageHandlerImpl() {
        super("MyMessageType");
    }

    public void handle(Message message) {
		// Message processing here.
    }

}
    @Override
    public void run(IlinkSfdcConfiguration conf, Environment env) {
        final AmazonSQS sqs = conf.getSqsFactory().buildSQSClient(env);

        final MessageHandler handler = ...

        final Set<MessageHandler> handlers = new HashSet<>();
        handlers.add(handler);
        
        final SqsListener sqsListener = new SqsListenerImpl(sqs, conf.getSqsListenQueueUrl(), handlers);

        env.lifecycle().manage(sqsListener);
        env.healthChecks().register("SqsListener", new SqsListenerHealthCheck(sqsListener));
    }
MessageDispatcher.dispatch(yourData, queueUrl, "MyMessageType", sqs);

Dispatched messages of type "MyMessageType" will be handled by your MessageHandlerImpl class now. You can loosely couple clients and message handlers by using several message types in your application(s).

You'll now have an extra health check called "SqsListener" that monitors the health of your queue.

SNS

    @Override
    public void run(IlinkSfdcConfiguration conf, Environment env) {
        final AmazonSNS sns = conf.getSqsFactory().buildSNSClient(env);
        sns.publish("arn", "hello world");
   
    }

That's it!