Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Dropwizard Atomix Bundle

License

Notifications You must be signed in to change notification settings

smoketurner/dropwizard-atomix

Repository files navigation

Dropwizard Atomix

Build Status Maven Central GitHub license Become a Patron

A bundle for integrating Atomix in Dropwizard applications.

Usage

Within your Configuration class, add the following:

@Valid
@NotNull
private final AtomixFactory atomix = new AtomixFactory();

@JsonProperty
public AtomixFactory getAtomixFactory() {
    return atomix;
}

Then with your Application class, you can access an Atomix by doing the following:

@Override
public void initialize(Bootstrap<MyConfiguration> bootstrap) {
    bootstrap.addBundle(new AtomixBundle<MyConfiguration>() {
        @Override
        public AtomixFactory getAtomixFactory(MyConfiguration configuration) {
            return configuration.getAtomixFactory();
        }
    });
}

@Override
public void run(MyConfiguration configuration, Environment environment) throws Exception {
    Atomix atomix = configuration.getAtomixFactory().build();
}

Maven Artifacts

This project is available on Maven Central. To add it to your project simply add the following dependencies to your pom.xml:

<dependency>
    <groupId>com.smoketurner.dropwizard</groupId>
    <artifactId>atomix-core</artifactId>
    <version>1.3.7-1</version>
</dependency>

Example Application

To try the example application, checkout the code from Github then build the example hello world application.

git clone https://github.com/smoketurner/dropwizard-atomix.git
cd dropwizard-atomix
./mvnw compile package
cd atomix-example

You then need to open 3 separate terminal windows to launch 3 instances of the application:

java -jar target/atomix-example-1.3.7-2-SNAPSHOT.jar server config1.yml
java -jar target/atomix-example-1.3.7-2-SNAPSHOT.jar server config2.yml
java -jar target/atomix-example-1.3.7-2-SNAPSHOT.jar server config3.yml

Once a quorum has been reached, Jetty will start up as normal on a random port which you'll be able to see in the logs.

INFO  [2018-01-07 15:29:43,489] org.eclipse.jetty.server.handler.ContextHandler: Started i.d.j.MutableServletContextHandler@2ad99cf3{/admin,null,AVAILABLE}
INFO  [2018-01-07 15:29:43,494] org.eclipse.jetty.server.AbstractConnector: Started hello-world@554f0dfb{HTTP/1.1,[http/1.1]}{0.0.0.0:55419}
INFO  [2018-01-07 15:29:43,494] org.eclipse.jetty.server.Server: Started @13775ms

You can then visit http://localhost:55419/hello-world to see the Dropwizard Getting Started example, but using a distributed counter across the cluster.

Support

Please file bug reports and feature requests in GitHub issues.

License

Copyright (c) 2018 Smoke Turner, LLC

This library is licensed under the Apache License, Version 2.0.

See http://www.apache.org/licenses/LICENSE-2.0.html or the LICENSE file in this repository for the full license text.