Java uber jar connects to mongo db 4.0 via Java Driver API.
181
Demo/tutorial showing how to connect to mongo db 4.0 with Java Driver API.
The Java Application connects to an already running Mongo DB instance on port 27017 on the "admin" database using root user credentials used by looking at environmental variables "MONGO_INITDB_ROOT_USERNAME" and "MONGO_INITDB_ROOT_PASSWORD"
Once connected, the application will enter a loop in which it will insert a new Document into the "metrics" collection every 5 secods. The document consists of a randomly generated domain name (random string) along with a random hit/visit count.
Its compiled as an uber jar (contains all dependancies) needed in order to be run via the "java -jar demo-jar-with-dependencies.jar" command.
This demo is actually part of a larger demo which show cases deploying the jar into a Docker swarm environment in orer to showcase the benifits of using swarm as a developer.
You can check out the stack on GitHub - https://github.com/mvpjava/docker-swarm-development-env.git to get access to the full Docker swarm environment
Source code on GitHub - https://github.com/mvpjava/java-driver-api-mongo4.git
FROM openjdk:14
COPY demo-jar-with-dependencies.jar /tmp
CMD ls -l /tmp/demo-jar-with-dependencies.jar \
&& echo "Must be run from stack file - See https://github.com/mvpjava/docker-swarm-development-env.git"
Content type
Image
Digest
Size
247.8 MB
Last updated
over 6 years ago
docker pull mvpjava/java-driver-api-mongo4:v1