Git Product home page Git Product logo

datasync's Introduction

datasync是什么?

datasync是一个mongodb数据同步工具,从mongo replicaset的oplog中持续监听数据变化并通知消费者

datasync怎么使用

datasync只提供一个轻微的监听内核,实现了持续监听oplog数据并通知消费者的能力。 你需要做的就是实现一个消费者(通过实现java.util.function.Consumer接口), 然后利用这个消费者构造一个OPLogSyncTask实例即可,通过运行OPLogSyncTask实例 你自定义消费者将接收到来自datasync通知过来的数据

datasync能做什么?

datasync虽然只实现了基本的监听功能,但通过强大的Consumer接口你可以实现任何想要的功能, 比如你可以实现一个KafkaConsumer用来将数据发往kafka。默认情况下datasync监听所有插入、更新、 删除操作记录。如果需要过滤特定的数据库或者集合,可以在自定义Consumer中实现过滤功能。

原理

mongodb replicaset之间是使用oplog来实现复制集数据同步的, 而我们也正式通过监听oplog来感知mongodb数据的变化, oplog存储在一个叫做oplog.rs的collection中,这个oplog.rs是一个特殊的collection, 因为他是一个固定大小的collection并且会循环覆盖数据,我们要做的就是从某个指定时间开始持续读取oplog.rs中的数据。

例子

下述例子演示了一个最简单的echo consumer的用法

Consumer<OPLogMessage> consumer = message -> {
    System.out.println("Recv:" + message);
};
OPLogSyncTask task = new OPLogSyncTask(collection, consumer);
task.start();
task.run();

datasync's People

Contributors

lhl4546 avatar

Stargazers

renyuyu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.