Nitrite DateGate

If you are using Nitrite Database in your applications and want to synchronize the data in real-time across the devices, you need DataGate.

To enable synchronization, a Nitrite database needs to be connected to a running DataGate instance.

Usage

                                    
// connect to a DataGate server running at localhost 9090 port
DataGateClient dataGateClient = new DataGateClient("http://localhost:9090")
        .withAuth("userId", "password");
DataGateSyncTemplate syncTemplate
        = new DataGateSyncTemplate(dataGateClient, "remote-collection@userId");

// create sync handle
SyncHandle syncHandle = Replicator.of(db)
        .forLocal(collection)
        // a DataGate sync template implementation
        .withSyncTemplate(syncTemplate)
        // replication attempt delay of 1 sec
        .delay(timeSpan(1, TimeUnit.SECONDS))
        // both-way replication
        .ofType(ReplicationType.BOTH_WAY)
        // sync event listener
        .withListener(new SyncEventListener() {
            @Override
            public void onSyncEvent(SyncEventData eventInfo) {

            }
        })
        .configure();

// start sync in the background using handle
syncHandle.startSync();
                                    
                                

Configuration

DataGate needs a MongoDb database to store the data at server side. Java 1.8 is a minimum requirement to run DataGate server. DataGate is available as a zip distribution or as a docker image from docker hub.

Zipped Distribution

To configure the mongo details edit the file datagate.properties. The file can be found in the conf directory.

                                
# Mongo Config
datagate.mongo.host=
datagate.mongo.port=
datagate.mongo.user=
datagate.mongo.password=
datagate.mongo.database=
                                
                            

To run the server run the below command from the bin directory.

./datagate.sh
                            
Docker Image

The docker image for the DataGate server needs to be configured by a Dockerfile like below.

                                
FROM dizitart/nitrite-datagate

COPY keystore.jks /

## Connection details (Replace with your own values)
ENV DATAGATE_HOST "0.0.0.0"
ENV DATAGATE_HTTP_PORT "8080"
ENV DATAGATE_HTTPS_PORT "8443"
ENV DATAGATE_MONITOR_PORT "9090"
ENV DATAGATE_KEY_STORE "keystore.jks"
ENV DATAGATE_KEY_PASSWORD "s3cret"

## Mongo connection details (Replace with your own values)
ENV DATAGATE_MONGO_HOST "192.168.0.100"
ENV DATAGATE_MONGO_PORT "2706"
ENV DATAGATE_MONGO_USER "demo"
ENV DATAGATE_MONGO_PASSWORD "demoPass"
ENV DATAGATE_MONGO_DATABASE "demo"

## Starts the server
ENTRYPOINT [ "./datagate.sh" ]
                                
                            

Now build and run the docker image.

Admin Portal

DataGate comes with an Admin Portal to better manage connected clients and users to the system. To login to the admin portal an admin user needs to be created first using mongo shell using the below command.

                                
db.getCollection('no2.datagate.users').insert({
    userName: "admin",
    password: "password",
    accountNonExpired: true,
    accountNonLocked: true,
    credentialsNonExpired: true,
    enabled: true,
    authorities: ["ADMIN"]
});
                                
                            

Analytics

DataGate provides some rudimentary usage analytics. To enable analytics the user agent details needs to be provided in the DataGateClient while configuring replication in Nitrite database.

                                
UserAgent userAgent = new UserAgent();
userAgent.setAppName("MyAwesomeApp");
userAgent.setAppVersion("1.4.2");
userAgent.setDevice("Android");
userAgent.setClientId("cl154");

DataGateClient dataGateClient = new DataGateClient("http://localhost:9090")
    .withAuth("userId", "password")
    .withUserAgent(userAgent);

DataGateSyncTemplate syncTemplate
    = new DataGateSyncTemplate(dataGateClient, "remote-collection@userId");
                                
                            
RELEASE DOWNLOAD
1.0.1 Current Docker | Zip
1.0 Docker | Zip