Giter VIP home page Giter VIP logo

dropwizard-rabbitmq's Introduction

Dropwizard RabbitMQ

Why doesn't this exist already...

Build Status Maven Central

Rabbitmq configuration, metrics, health-checks and lifecycle management integrated with dropwizard, focused on common use cases. Inspired by dropwizard-core and dropwizard-extra.

Configuration

Configurations are mapped to the class ConnectionConfiguration. Below is an example configuration for JobConsumerService which is configured by JobConsumerServiceConfiguration. Naturally you can have multiple configurations per application.

rabbitMqConsumer:
  username: guest
  password: guest
  virtualHost: /
  host: localhost
  port: 5672
  requestedChannelMax: 0
  requestedFrameMax: 0
  requestedHeartbeat: 0
  connectionTimeout: 0
  handshakeTimeout: 10000
  shutdownTimeout: 10000
  networkRecoveryInterval: 5000

However, please use the class ConnectionFactory in your configurations, which is a sub class of ConnectionConfiguration which knows how to create RabbitMQ connections. Here is the blurb from the examples.

public class JobConsumerServiceConfiguration extends Configuration {

    @Valid
    @NotNull
    private ConnectionFactory rabbitMqConsumer = new ConnectionFactory();

    @JsonProperty
    public ConnectionFactory getRabbitMqConsumer() {
        return rabbitMqConsumer;
    }

    @JsonProperty
    public void setRabbitMqConsumer(ConnectionFactory rabbitMqConsumer) {
        this.rabbitMqConsumer = rabbitMqConsumer;
    }
}

Simple Usage

Easy to use, but if initial connection fails no retry will be performed. This may be preferable if your application is running in a container manager which will reset your application on failure.

final ExecutorService deliveryExecutor = environment.lifecycle()
    .executorService("index-consumer-delivery-thread-pool")
    .maxThreads(configuration.getNumIndexingThreads())
    .build();
final Connection connection = configuration.getRabbitMq()
    .build(environment, deliveryExecutor, "index-consumer");

//give connection to some consumer/publisher

Better Usage

Will retry the initial connection, asynchronously calling the callback when it succeeds. The RabbitMQ connection class has reconnect/topology recreate features which are turned on by default in this library, which is why we only need to retry initial connect.

final ExecutorService deliveryExecutor = environment.lifecycle()
    .executorService("index-consumer-delivery-thread-pool")
    .maxThreads(configuration.getNumIndexingThreads())
    .build();

//this::connected is a callback
configuration.getRabbitMq()
    .buildRetryInitialConnect(environment, deliveryExecutor, "index-consumer", this::connected);

Examples

Producer/Consumer examples are located within the test directory. There is a producer, which sends id's to a queue, and a consumer which does fake work on those id's and publishes a status to a topic.

dropwizard-rabbitmq's People

Contributors

randyp avatar

Watchers

Iniyan Paramasivam 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.