All Projects → meltmedia → dropwizard-mongo

meltmedia / dropwizard-mongo

Licence: Apache-2.0 License
A Dropwizard bundle for MongoDB

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to dropwizard-mongo

dropwizard-crypto
A Crytpographic Bundle for Dropwizard
Stars: ✭ 14 (-30%)
Mutual labels:  dropwizard, dropwizard-bundle
keycloak-dropwizard-integration
This project shows how JBoss Keycloak and Dropwizard can be used together.
Stars: ✭ 49 (+145%)
Mutual labels:  dropwizard, dropwizard-bundle
mongofluxd
Real time sync from MongoDB into InfluxDB
Stars: ✭ 33 (+65%)
Mutual labels:  oplog
servant
Serving you with GoogleApiClients any way you like them
Stars: ✭ 17 (-15%)
Mutual labels:  rxjava
BookReader
📕 "任阅" 网络小说阅读器,3D翻页效果、txt/pdf/epub书籍阅读、Wifi传书~
Stars: ✭ 6,113 (+30465%)
Mutual labels:  rxjava
nakadi-java
🌀 Client library for the Nakadi Event Broker (examples: http://bit.ly/njc-examples, site: https://dehora.github.io/nakadi-java/)
Stars: ✭ 29 (+45%)
Mutual labels:  rxjava
Fineract-CN-mobile
DEPRECATED project - Check the Apache fineract-cn-mobile project instead
Stars: ✭ 17 (-15%)
Mutual labels:  rxjava
RxProperty
RxJava binding APIs for observable fields and observable collections from the Data Binding Library
Stars: ✭ 17 (-15%)
Mutual labels:  rxjava
Eyepetizer
An unofficial Eyepetizer(开眼视频) App built using Ijkplayer, RxJava2, Retrofit2, Dagger2, Room , DataBinding and Clean-MVVM Architecture.
Stars: ✭ 22 (+10%)
Mutual labels:  rxjava
Kotlin-Starter
☕ Kotlin starter with rx
Stars: ✭ 22 (+10%)
Mutual labels:  rxjava
WanAndroid
Kotlin版 玩Android 客户端
Stars: ✭ 37 (+85%)
Mutual labels:  rxjava
ReactiveBus
🚍 Reactive Event Bus for JVM (1.7+) and Android apps built with RxJava 2
Stars: ✭ 17 (-15%)
Mutual labels:  rxjava
SQLitePractice
数据库案例:1.使用时间和日期函数,增,查时间字段。2.利用ContentProvider,CursorLoader,SQLite实现数据库的观察者模式。3.RxJava,SQLBrite实现数据库的观察者模式。4.拷贝外部db文件到数据库中
Stars: ✭ 21 (+5%)
Mutual labels:  rxjava
RxFBase
🔥 wrapping firebase with rx
Stars: ✭ 12 (-40%)
Mutual labels:  rxjava
RxCamera2
Rx Java 2 wrapper for Camera2 google API
Stars: ✭ 27 (+35%)
Mutual labels:  rxjava
helloworld-web
Hello World web application in 39 different ways in Java
Stars: ✭ 18 (-10%)
Mutual labels:  dropwizard
rx-docker-client
RxJava based Docker REST API client for the JVM
Stars: ✭ 61 (+205%)
Mutual labels:  rxjava
WanAndroid-Java
一款采用Java语言、MVVM + Retrofit + RxJava架构开发的玩Android客户端 (https://www.wanandroid.com/) 。PS: Kotlin版 (https://github.com/chongyucaiyan/WanAndroid-Kotlin) 。
Stars: ✭ 32 (+60%)
Mutual labels:  rxjava
TMDB-App
Demo app using TMDB api
Stars: ✭ 13 (-35%)
Mutual labels:  rxjava
Android-RxFirebase
RxJava implementation for the Android Firebase client by Ezhome
Stars: ✭ 30 (+50%)
Mutual labels:  rxjava

Dropwizard Mongo

A Dropwizard bundle for MongoDB.

Build Status

Usage

Maven

Releases of this project are available on Maven Central. You can include the project with this dependency:

<dependency>
  <groupId>com.meltmedia.dropwizard</groupId>
  <artifactId>dropwizard-mongo</artifactId>
  <version>0.5.0</version>
</dependency>

To use SNAPSHOTs of this project, you will need to include the sonatype repository in your POM.

<repositories>
    <repository>
        <snapshots>
        <enabled>true</enabled>
        </snapshots>
        <id>sonatype-nexus-snapshots</id>
        <name>Sonatype Nexus Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
</repositories>

You will also need to include the project in your dependencies.

<dependency>
  <groupId>com.meltmedia.dropwizard</groupId>
  <artifactId>dropwizard-mongo</artifactId>
  <version>0.6.0-SNAPSHOT</version>
</dependency>

Java

Define the MongoConfiguration class somewhere in your applications configuration.

import com.meltmedia.dropwizard.mongo.MongoConfiguration;

...

  @JsonProperty
  protected MongoConfiguration mongo;

  public MongoConfiguration getMongo() {
    return mongo;
  }

Then include the bundle in the initialize method of your application.

import com.meltmedia.dropwizard.mongo.MongoBundle;

...
MongoBundle<ExampleConfiguration> mongoBundle;

@Override
public void initialize(Bootstrap<ExampleConfiguration> bootstrap) {
  bootstrap.addBundle(mongoBundle = MongoBundle.<ExampleConfiguration>builder()
    .withConfiguration(ExampleConfiguration::getMongo)
    .build());
}

Finally, use the bundle to access the client and database in your run method.

@Override
public void run(ExampleConfiguration config, Environment env) throws Exception {
  MongoClient client = mongoBundle.getClient();
  DB db = mongoBundle.getDB();
  // do something cool.
}

Configuration

Add the mongo configuraiton block to your applications config.

mongo:
  seeds:
  - host: localhost
    port: 27017
  database: example
  credentials:
    userName: example
    password: example

RxJava2 Oplog Service

Starting with version 0.4.0, this service provides an oplog watching service. It provides a hot, sharable observable, suitable for restarting processors on collection changes.

To use the service, include the JavaRx2 dependency.

<dependency>
  <groupId>io.reactivex.rxjava2</groupId>
  <artifactId>rxjava</artifactId>
  <version>2.0.4</version>
</dependency>

Then include the bundle in the initialize method of your application, after the bundle for the client.

import com.meltmedia.dropwizard.mongo.MongoBundle;
import com.meltmedia.dropwizard.mongo.rxoplog.RxOplogBundle;

...
MongoBundle<ExampleConfiguration> mongoBundle;
RxOplogBundle<ExampleConfiguration> oplogBundle;

@Override
public void initialize(Bootstrap<ExampleConfiguration> bootstrap) {
  bootstrap.addBundle(mongoBundle = MongoBundle.<ExampleConfiguration>builder()
    .withConfiguration(ExampleConfiguration::getMongo)
    .build());
  bootstrap.addBundle(oplogBundle = RxOplogBundle.<ExampleConfiguration>builder()
    .with(config->serviceBuilder->serviceBuilder
      .withMongoClient(mongoBundle::getClient)
      .matchDatabase(config.getMongo().getDatabase()))
    .build());
}

Then you can access the service in the run method.

@Override
public void run(ExampleConfiguration config, Environment env) throws Exception {
  RxOplogService oplog = oplogBundle.getOplogService();
  
  env.lifecycle().manage(new Managed() {
    Disposable disposable;
    @Override
    public void start() throws Exception {
      disposable = oplogBundle.getOplogService()
        .getOplog()
        .forEach(doc->{
          // do something cool
        });
    }

    @Override
    public void stop() throws Exception {
      if( disposable != null ) disposable.dispose();
    }
  });
}

Building

This project builds with Java8 and Maven 3. After cloning the repo, install the bundle from the root of the project.

mvn clean install

Integration Tests

You can also run integration tests while running the build. First, you will need to make sure the configuration passphrase is in the environment.

export EXAMPLE_PASSPHRASE='correct horse battery staple'

Second you need to install vagrant in version 1.5 and above.

Then run the build with the integration-tests profile.

mvn clean install -P integration-tests

Contributing

This project accepts PRs, so feel free to fork the project and send contributions back.

Formatting

This project contains formatters to help keep the code base consistent. The formatter will update Java source files and add headers to other files. When running the formatter, I suggest the following procedure:

  1. Make sure any outstanding stages are staged. This will prevent the formatter from destroying your code.
  2. Run mvn format, this will format the source and add any missing license headers.
  3. If the changes look good and the project still compiles, add the formatting changes to your staged code.

If things go wrong, you can run git checkout -- . to drop the formatting changes.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].