Skip to content

Beispielkonfiguration des Java Mongo Treibers mit Spring-Data-MongoDB um Master Slave Switches eines Mongo Replication Sets zu kompensieren.

License

Notifications You must be signed in to change notification settings

ElazarNeeman/robust-mongo-config

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

robust-mongo-config

Example configuration of the Java MongoDB driver with Spring Data MongoDB to make the application more robust when a master slave switchover occures. The MongoTemplateWithRetry retries the most common database operations for three times. MongoDB specific exections will be catched and logged as warn. Only after the retry period the exeption will be thown as translated Spring database exception.

Requirements

For testing JRE 1.8 and Gradle is required.

For production use, just copy the MongoTemplateWithRetry.java and the MongoConfiguration.java into your project. Configure the MongoConfiguration file for your needs.

Starting a local MongoDB-Clusters for testing

Starting and initializing of three Mongo-Nodes:

mkdir -p /tmp/mongodb/rs0-1 /tmp/mongodb/rs0-2 /tmp/mongodb/rs0-3

mongod --port 27001 --replSet rs0 --smallfiles --oplogSize 128 --dbpath /tmp/mongodb/rs0-1
mongod --port 27002 --replSet rs0 --smallfiles --oplogSize 128 --dbpath /tmp/mongodb/rs0-2
mongod --port 27003 --replSet rs0 --smallfiles --oplogSize 128 --dbpath /tmp/mongodb/rs0-3

cat rs0.conf | mongo 127.0.0.1:27001

The ReplicaSet Configuration is saved in the file rs0.conf

Have a look at http://docs.mongodb.org/manual/tutorial/deploy-replica-set/

Check configuration:

mongo 127.0.0.1:27001
rs.conf()
rs.status()

runing tests

src/test/java/de/hypoport/repository/JustARepositoryTest.java

When the test is running kill the primary Mongo node. The data should be written without break in case of unsteady replica set state. An information message should be logged.

About

Beispielkonfiguration des Java Mongo Treibers mit Spring-Data-MongoDB um Master Slave Switches eines Mongo Replication Sets zu kompensieren.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Java 93.8%
  • Groovy 6.2%