1.maxwell基础
参考http://seanlook.com/2018/01/13/maxwell-binlog/
这里写下我的基础配置
2.python 消费者伪代码
启动
[root@ip-10-1-2-175 sh]# python cus.py
3.启动maxwel
4.模拟数据库操作
5.查看消费者
6.根据上面的思路可以写出增量同步的伪代码
其它:
https://mp.weixin.qq.com/s/aGqwWNd6Q2Gm2jilxXS0RA
参考http://seanlook.com/2018/01/13/maxwell-binlog/
这里写下我的基础配置
- [root@ip-10-1-2-175 maxwell-1.12.0]# more config.properties
-
- log_level=info
- kafka.bootstrap.servers=localhost:9092
- producer=kafka
- host=10.1.2.175
- user=dbaadmin
- password=
- schema_database=maxwell
- kafka.compression.type=snappy
- kafka.retries=0
- kafka.acks=1
- kinesis_stream=maxwell
- sqs_queue_uri=aws_sqs_queue_uri
- producer=kafka ###生产者选择kafka
- kafka.bootstrap.servers=10.1.2.175:9092
- kafka_topic=test ####主题
-
- output_ddl = true ####ddl输出到 maxwell_ddl topic
ddl_kafka_topic=maxwell_ddl - producer_partition_by=database
2.python 消费者伪代码
- import time, json
- from pykafka import KafkaClient
- client = KafkaClient(hosts="10.1.2.175:9092")
- topic = client.topics['test']
- balanced_consumer = topic.get_balanced_consumer(consumer_group='goods_group',auto_commit_enable=True,zookeeper_connect='localhost:2181')
-
- for message in balanced_consumer:
- print message.offset, message.value
启动
[root@ip-10-1-2-175 sh]# python cus.py
3.启动maxwel
- [root@ip-10-1-2-175 maxwell-1.12.0]# ./bin/maxwell
4.模拟数据库操作
- mysql> insert into testwell(name) values ('fuck');
- Query OK, 1 row affected (0.00 sec)
-
- mysql> insert into testwell(name) values ('fuck');
- Query OK, 1 row affected (0.00 sec)
-
- mysql> insert into testwell(name) values ('fuck');
- Query OK, 1 row affected (0.00 sec)
-
- mysql>
5.查看消费者
- [root@ip-10-1-2-175 sh]# python cus.py
- 67 {"database":"test","table":"testwell","type":"insert","ts":1526290515,"xid":208818,"commit":true,"data":{"id":3050,"name":"fuck"}}
- 68 {"database":"test","table":"testwell","type":"insert","ts":1526290515,"xid":208819,"commit":true,"data":{"id":3051,"name":"fuck"}}
- 69 {"database":"test","table":"testwell","type":"insert","ts":1526290517,"xid":208820,"commit":true,"data":{"id":3052,"name":"fuck"}}
- 70 {"database":"test","table":"testwell","type":"insert","ts":1526290519,"xid":208822,"commit":true,"data":{"id":3053,"name":"fuck"}}
6.根据上面的思路可以写出增量同步的伪代码
- [root@ip-10-1-2-175 sh]#
- import time, json
- from pykafka import KafkaClient
- client = KafkaClient(hosts="10.1.2.175:9092")
- topic = client.topics['test']
- balanced_consumer = topic.get_balanced_consumer(consumer_group='goods_group',auto_commit_enable=True,zookeeper_connect='localhost:2181')
-
- for message in balanced_consumer:
- print message.offset, message.value
- # 对数据库进行操作
- if message.value ['type'] == 'insert':
- mysql_insert()
- elif message.value['type'] == 'update':
- mysql_update()
- elif message.value['type'] == 'delete':
- mysql_delete()
- else:
- order_option()
其它:
https://mp.weixin.qq.com/s/aGqwWNd6Q2Gm2jilxXS0RA
Kafka Connect 如何实现同步RDS binlog数据?
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29096438/viewspace-2154470/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29096438/viewspace-2154470/