Python:mysql mom 모듈 을 사용 하여 실시 간 으로 MySQL 데 이 터 를 Elastic Search 에 동기 화
13040 단어 python
설치 하 다.
pip install mysqlsmom
전량 동기 화
#
$ mom new test_mom/init_config.py -t init --force
#
$ vim ./test_mom/init_config.py #
#
$ mom run -c ./test_mom/init_config.py
증분 동기 화
세 개의 파일 설정
test_mom
├── binlog_config.py #
├── my_filters.py # watched
└── my_handlers.py # pipeline
새 설정
mom new test_mom/binlog_config.py -t binlog --force
1、binlog_config.py
# coding=utf-8
STREAM = "BINLOG" # "BINLOG" or "INIT"
SERVER_ID = 99
SLAVE_UUID = __name__
# BULK_SIZE elasticsearch, 1
BULK_SIZE = 1
BINLOG_CONNECTION = {
'host': '127.0.0.1',
'port': 3306,
'user': 'root',
'passwd': '123456'
}
# redis
REDIS = {
"host": "127.0.0.1",
"port": 6379,
"db": 0,
# "password": "password", #
}
NODES = [{"host": "127.0.0.1", "port": 9200}]
TASKS = [
{
"stream": {
"database": "demo",
"table": "student"
},
"jobs": [{
"actions": ["insert", "update"],
"watched": {
"filter_display": {}
},
"pipeline": [
{"only_fields": {"fields": ["id", "name", "age"]}},
{"change_name": {"key": "name", "prefix": "hot-"}},
{"set_id": {"field": "id"}}
],
"dest": {
"es": {
"action": "upsert",
"index": "demo",
"type": "student",
"nodes": NODES
}
}
},
{
"actions": ["delete"],
"pipeline": [
# {"only_fields": {"fields": ["id", "name", "age"]}},
{"set_id": {"field": "id"}}
],
"dest": {
"es": {
"action": "delete",
"index": "demo",
"type": "student",
"nodes": NODES
}
}
}
]
}
]
CUSTOM_ROW_HANDLERS = "./my_handlers.py"
CUSTOM_ROW_FILTERS = "./my_filters.py"
사용자 정의 프로세서 myhandlers.py
# -*- coding: utf-8 -*-
import copy
def change_name(row, key, prefix):
new_row = copy.deepcopy(row)
new_row[key] = "{}{}".format(prefix, row[key])
# ,
return new_row
사용자 정의 필터 myfilters.py
# -*- coding: utf-8 -*-
def filter_display(event):
# True False,
return event["values"]["display"] == 1
시동 을 걸다
mom run -c test_mom/binlog_config.py
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
로마 숫자를 정수로 또는 그 반대로 변환그 중 하나는 로마 숫자를 정수로 변환하는 함수를 만드는 것이었고 두 번째는 그 반대를 수행하는 함수를 만드는 것이었습니다. 문자만 포함합니다'I', 'V', 'X', 'L', 'C', 'D', 'M' ; 문자열이 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.