Simple MongoDB oplog reader written in java. Made to read the oplog from multiple sources.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This software is published under the GNUv3:

What's needed
Java 1.6

What is it?
This is a mongodb oplog reader.  It's easier to use (I think) than the sample code that Mongo provides.  This is what the mongo folks use as an example:

This is just a wrapper over this.

Also, it allows for a single process to "listen" to multiple mongodb's at one time.  This is useful if you want to replicate the mongo data to another data store or send as triggered events to a queue service.

The general architecture is straight forward:
1) Create a thread for each mongo connection
2) Run in a thread pool and use the same concurrent queue
3) have another thread listen for the events

Below is the sample code that uses this method on a single thread:

  public static void main(String args[]) {
    try {
      Mongo mongo = new Mongo("localhost");
      BlockingQueue<OplogLine> queue = new LinkedBlockingQueue<OplogLine>();
      OpLogReader reader = new OpLogReader(mongo, queue);
      ExecutorService executor = Executors.newSingleThreadExecutor();
      try {
        while (!executor.isTerminated()) {
          OplogLine line = queue.poll(30, TimeUnit.SECONDS);
"Line info: " + line);
      } catch (InterruptedException e) {"time to go.");
    } catch (UnknownHostException e) {
    } catch (MongoException e) {

As you see from above, you connect to mongo, allocate a new queue, and execute the log reader.  Once executed the concurrent queue will automatically fill up with OplogLine objects to poll from the queue object.

if you have any questions please email me.