Giter Club home page Giter Club logo

aws-dropwizard's Introduction

aws-dropwizard

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

  • Group ID: io.interact
  • Artifact ID: sqs-dropwizard

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

  • Add the following settings to your configuration yaml file:
# Amazon SQS settings.
awsFactory:
  awsAccessKeyId: ...
  awsSecretKey: ...
  awsRegion: ...

sqsListenQueueUrl: https://sqs...
  • Add the Aws factory and the listen queue URL to your configuration class:
    @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

  • Extend the MessageHandler class and process the messages that you expect to receive in the handle() method (you can register multiple MessageHandler instances with the queue listener):
package ...;

import io.interact.sqsdw.sqs.MessageHandler;

public class MessageHandlerImpl extends MessageHandler {

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

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

}
  • Register the queue listener in the run() method of your application class (you can inject the constructor arguments into an SqsListenerImpl instance with Guice):
    @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));
    }
  • Send messages to SQS from your client with the MessageDispatcher helper class:
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

  • You can also build an SNS client with your AwsFactory instance using the credentials and region specified in your .yaml file. The client will automatically be shutdown at the end of the application's lifecycle.
    @Override
    public void run(IlinkSfdcConfiguration conf, Environment env) {
        final AmazonSNS sns = conf.getSqsFactory().buildSNSClient(env);
        sns.publish("arn", "hello world");
   
    }

That's it!

aws-dropwizard's People

Contributors

bascan avatar stve avatar teddywilson avatar

Watchers

 avatar  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.