1 Star 0 Fork 13

云丽网络科技有限公司 / mbinlogmq

forked from Josin / mbinlogmq 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause-Clear

mbinlogmq 一个基于MySQL binlog协议的数据同步中间件

什么是mbinlogmq?

mbinlogmq 是一个使用C语言开发的基于 MySQL binlog 协议的一个中间件,通过模拟Slave 来实时获取 MySQL binlog日志,并将数据变更信息以及 DB 语句发送到 RabbitMQ,中间通过监听机制与校验机制来确保不宕机的情况下的100%抵达 RMQ

设计架构

安装&编译

  • mbinlog依赖于一些第三方库:

请先安装依赖软件: cURLmysqlrabbitmq,安装完成后记住其安装的路径,进入下面的步骤

  • 下载mbinlogmq源码
git clone https://gitee.com/josinli/mbinlogmq.git
  • 修改 CMakeLists.txt,将如下的几行变为您上面安装的路径:
set(MYSQL_INCLUDE     /usr/local/mysql/include)      # 您系统的MySQL头文件路径
set(MYSQL_LIBRARY_DIR /usr/local/mysql/lib)          # 您系统的MySQL库文件路径
set(CURL_DIR          /usr/local/Cellar/curl/7.58.0) # 您系统的curl安装路径
  • 执行编译安装命令
mkdir build
cd build
cmake .. && make && sudo make install	
  • 修改 /etc/mbinlogmq/binlog.xml 您的配置信息
<?xml version="1.0" encoding="UTF-8" author="Josin" date="2019-07-22"?>
<!--本配置文件安装位置:/etc/mbinlogmq/binlog.xml-->
<!--连接主库进行salve复制的信息-->
<!--请不要增加节点信息,系统会校验-->
<system for="slave">
    <mode>rabbitmq</mode> <!-- 目前仅支持rabbitmq -->
    <host>127.0.0.1</host>
    <user>root</user>
    <password>3333</password>
    <port>3306</port>
    <server_id>6</server_id>
    <daemon>1</daemon>
</system>

<!--用户需要配置好下方的rabbitmq的配置选项-->
<rabbitmq>
    <host>127.0.0.1</host>
    <user>guest</user>
    <password>guest</password>
    <port>15672</port>
    <delivery_mode>1</delivery_mode>
    <name>amq.default</name>
    <payload>Invalid</payload>
    <routing_key>fanout</routing_key>
    <vhost>/</vhost>
</rabbitmq>
  • 启动您的 minblogmq
mbinlogmq -k start

此时进入 MySQL 操作,同时登录 RabbitMQ 查看消息是否成功抵达,目前的版本存在一些或多或少的问题,切勿生产环境使用。

mbinlogmq会针对不同的binlog日志生成四种类型的消息,消息类型如下

  • 消息全部为 JSON 格式
  • 格式如下

1、UPDATE 语句,etype等于 1,包含一个pre对象 和 new对象,分别对应修改之前的数据和新的数据

{
    "etype": 1,
    "data" : {
        "pre": {
            "id":1,
            "ad":2
        },
        "new": {
            "id":1,
            "ad":3
        }
    }
}

2、INSERT 消息, etype 等于 2

{
    "etype": 2,
    "data" : {
        "id":1,
        "ad":3
    }
}

3、DELETE 消息, etype 等于 3

{
    "etype": 3,
    "data" : {
        "id":1,
        "ad":3
    }
}

4、SQL 语句 消息, etype 等于 4

{
    "etype": 4,
    "data": "ALTER TABLE `books`.`test_at` MODIFY COLUMN `cc` datetime(0) NULL DEFAULT NULL AFTER `bb`"
}

示例消息如下:

 [x] Received {"etype":4,"data":"ALTER TABLE `books`.`test_at` \nMODIFY COLUMN `bb` date NULL DEFAULT NULL AFTER `aa`"}
 [x] Received {"etype":4,"data":"ALTER TABLE `books`.`test_at` \nMODIFY COLUMN `bb` date NOT NULL AFTER `aa`"}
 [x] Received {"etype":4,"data":"BEGIN"}
 [x] Received {"etype":1,"data":{"pre":{"id":1,"book_name":"傲世丹神1","book_cover":"http://img.c0m.io/quanben.io/upload/thumbnail/book_0_999/book_1.jpg","add_time":"2019-7-23 14:28:43","author_name":"寂小贼111","introduction":"废柴少年得无上传承,获逆天神脉,学绝世神功,掌握超绝丹术,这使他...","test_date":"2019-7-29"},"new":{"id":1,"book_name":"傲世丹神1","book_cover":"http://img.c0m.io/quanben.io/upload/thumbnail/book_0_999/book_1.jpg","add_time":"2019-7-23 21:47:36","author_name":"寂小贼","introduction":"废柴少年得无上传承,获逆天神脉,学绝世神功,掌握超绝丹术,这使他...","test_date":"2019-7-29"}}}
 [x] Received {"etype":4,"data":"COMMIT"}
 [x] Received {"etype":4,"data":"BEGIN"}
 [x] Received {"etype":1,"data":{"pre":{"id":1,"book_name":"傲世丹神1","book_cover":"http://img.c0m.io/quanben.io/upload/thumbnail/book_0_999/book_1.jpg","add_time":"2019-7-23 21:47:36","author_name":"寂小贼","introduction":"废柴少年得无上传承,获逆天神脉,学绝世神功,掌握超绝丹术,这使他...","test_date":"2019-7-29"},"new":{"id":1,"book_name":"傲世丹神","book_cover":"http://img.c0m.io/quanben.io/upload/thumbnail/book_0_999/book_1.jpg","add_time":"2019-7-23 21:47:54","author_name":"寂小贼","introduction":"废柴少年得无上传承,获逆天神脉,学绝世神功,掌握超绝丹术,这使他...","test_date":"2019-7-29"}}}
 [x] Received {"etype":4,"data":"COMMIT"}

有问题可以及时通过 ISSUE 反馈,反馈地址:GITEE Go Go Go!!!

The Clear BSD License Copyright (c) 2019, Josin All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

mbinlogmq 一个基于MySQL binlog协议的数据同步中间件 展开 收起
C
BSD-3-Clause-Clear
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C
1
https://gitee.com/style1987/mbinlogmq.git
git@gitee.com:style1987/mbinlogmq.git
style1987
mbinlogmq
mbinlogmq
release

搜索帮助

14c37bed 8189591 565d56ea 8189591