{ "info": { "author": "magic", "author_email": "guanpeixiang@foxmail.com", "bugtrack_url": null, "classifiers": [], "description": "# canal-py2\nFirst, canal-py2 is fork by https://github.com/haozi3156666/canal-python\nthx.\n\n## \u4e00.canal-py2 \u7b80\u4ecb\n\ncanal-py2 \u662f\u963f\u91cc\u5df4\u5df4\u5f00\u6e90\u9879\u76ee [Canal](https://github.com/alibaba/canal)\u662f\u963f\u91cc\u5df4\u5df4mysql\u6570\u636e\u5e93binlog\u7684\u589e\u91cf\u8ba2\u9605&\u6d88\u8d39\u7ec4\u4ef6 \u7684 python \u5ba2\u6237\u7aef\u3002\u4e3a python \u5f00\u53d1\u8005\u63d0\u4f9b\u4e00\u4e2a\u66f4\u53cb\u597d\u7684\u4f7f\u7528 Canal \u7684\u65b9\u5f0f\u3002Canal \u662fmysql\u6570\u636e\u5e93binlog\u7684\u589e\u91cf\u8ba2\u9605&\u6d88\u8d39\u7ec4\u4ef6\u3002\n\n\u57fa\u4e8e\u65e5\u5fd7\u589e\u91cf\u8ba2\u9605&\u6d88\u8d39\u652f\u6301\u7684\u4e1a\u52a1\uff1a\n\n1. \u6570\u636e\u5e93\u955c\u50cf\n2. \u6570\u636e\u5e93\u5b9e\u65f6\u5907\u4efd\n3. \u591a\u7ea7\u7d22\u5f15 (\u5356\u5bb6\u548c\u4e70\u5bb6\u5404\u81ea\u5206\u5e93\u7d22\u5f15)\n4. search build\n5. \u4e1a\u52a1cache\u5237\u65b0\n6. \u4ef7\u683c\u53d8\u5316\u7b49\u91cd\u8981\u4e1a\u52a1\u6d88\u606f\n\n\u5173\u4e8e Canal \u7684\u66f4\u591a\u4fe1\u606f\u8bf7\u8bbf\u95ee https://github.com/alibaba/canal/wiki\n\n\n## \u4e8c.\u5de5\u4f5c\u539f\u7406\n\ncanal-py2 \u662f Canal \u7684 python \u5ba2\u6237\u7aef\uff0c\u5b83\u4e0e Canal \u662f\u91c7\u7528\u7684Socket\u6765\u8fdb\u884c\u901a\u4fe1\u7684\uff0c\u4f20\u8f93\u534f\u8bae\u662fTCP\uff0c\u4ea4\u4e92\u534f\u8bae\u91c7\u7528\u7684\u662f Google Protocol Buffer 3.0\u3002\n\n## \u4e09.\u5de5\u4f5c\u6d41\u7a0b\n\n1.Canal\u8fde\u63a5\u5230mysql\u6570\u636e\u5e93\uff0c\u6a21\u62dfslave\n\n2.canal-py2 \u4e0e Canal \u5efa\u7acb\u8fde\u63a5\n\n2.\u6570\u636e\u5e93\u53d1\u751f\u53d8\u66f4\u5199\u5165\u5230binlog\n\n5.Canal\u5411\u6570\u636e\u5e93\u53d1\u9001dump\u8bf7\u6c42\uff0c\u83b7\u53d6binlog\u5e76\u89e3\u6790\n\n4.canal-py2 \u5411 Canal \u8bf7\u6c42\u6570\u636e\u5e93\u53d8\u66f4\n\n4.Canal \u53d1\u9001\u89e3\u6790\u540e\u7684\u6570\u636e\u7ed9canal-py2\n\n5.canal-py2 \u6536\u5230\u6570\u636e\uff0c\u6d88\u8d39\u6210\u529f\uff0c\u53d1\u9001\u56de\u6267\u3002\uff08\u53ef\u9009\uff09\n\n6.Canal\u8bb0\u5f55\u6d88\u8d39\u4f4d\u7f6e\u3002\n\n## \u56db.\u5feb\u901f\u542f\u52a8\n\n### \u5b89\u88c5Canal\n\nCanal \u7684\u5b89\u88c5\u4ee5\u53ca\u914d\u7f6e\u4f7f\u7528\u8bf7\u67e5\u770b https://github.com/alibaba/canal/wiki/QuickStart\n\n### \u73af\u5883\u8981\u6c42\npython 2.7 \uff08canal-python\u652f\u6301python3\uff09\n\n### \u6784\u5efacanal python\u5ba2\u6237\u7aef\n\n````shell\npip install canal-py2\n````\n\n### \u5efa\u7acb\u4e0eCanal\u7684\u8fde\u63a5\n````python\nimport time\n\nfrom canal.client import Client\nfrom canal.protocol import EntryProtocol_pb2\nfrom canal.protocol import CanalProtocol_pb2\n\nclient = Client()\nclient.connect(host='127.0.0.1', port=11111)\nclient.check_valid(username='canal', password='canal')\nclient.subscribe(client_id='1001', destination='example', filter='.*\\\\..*')\n\nwhile True:\n message = client.get(100)\n entries = message['entries']\n for entry in entries:\n entry_type = entry.entryType\n if entry_type in [EntryProtocol_pb2.EntryType.TRANSACTIONBEGIN, EntryProtocol_pb2.EntryType.TRANSACTIONEND]:\n continue\n row_change = EntryProtocol_pb2.RowChange()\n row_change.MergeFromString(entry.storeValue)\n event_type = row_change.eventType\n header = entry.header\n database = header.schemaName\n table = header.tableName\n event_type = header.eventType\n for row in row_change.rowDatas:\n format_data = dict()\n if event_type == EntryProtocol_pb2.EventType.DELETE:\n for column in row.beforeColumns:\n format_data = {\n column.name: column.value\n }\n elif event_type == EntryProtocol_pb2.EventType.INSERT:\n for column in row.afterColumns:\n format_data = {\n column.name: column.value\n }\n else:\n format_data['before'] = format_data['after'] = dict()\n for column in row.beforeColumns:\n format_data['before'][column.name] = column.value\n for column in row.afterColumns:\n format_data['after'][column.name] = column.value\n data = dict(\n db=database,\n table=table,\n event_type=event_type,\n data=format_data,\n )\n print(data)\n time.sleep(1)\n\nclient.disconnect()\n````", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/Guanpx/canal-python", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "canal-py2", "package_url": "https://pypi.org/project/canal-py2/", "platform": "", "project_url": "https://pypi.org/project/canal-py2/", "project_urls": { "Homepage": "https://github.com/Guanpx/canal-python" }, "release_url": "https://pypi.org/project/canal-py2/0.5/", "requires_dist": null, "requires_python": "", "summary": "A canal-cilent for python2", "version": "0.5" }, "last_serial": 5893963, "releases": { "0.2": [ { "comment_text": "", "digests": { "md5": "8696b1701610467cb31d1b04446c6631", "sha256": "a503a4751caf8f478355e156f5c1641ffaeb5c6ece7bc5b54bdb3cc93e8fd718" }, "downloads": -1, "filename": "canal-py2-0.2.tar.gz", "has_sig": false, "md5_digest": "8696b1701610467cb31d1b04446c6631", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10984, "upload_time": "2019-09-25T08:22:18", "url": "https://files.pythonhosted.org/packages/f1/af/1730c19111a86a17766d4b8d459c504f200e70c454dbf5b8ed7d92dfc0cf/canal-py2-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "d6b1ef1739ea6afb9f1fd59ac70edb04", "sha256": "b6153fbe61793653a1e79bc85193c4c1f3c9edfd5d9a0f46740554ed4fd11e9b" }, "downloads": -1, "filename": "canal-py2-0.3.tar.gz", "has_sig": false, "md5_digest": "d6b1ef1739ea6afb9f1fd59ac70edb04", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10952, "upload_time": "2019-09-25T08:27:24", "url": "https://files.pythonhosted.org/packages/bd/cf/4d0b2109488c0bb9daf91cbf83cf9423c4a2a380147ee22925d220e4868c/canal-py2-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "99968ec3ae8e27e4921e8024f3579b7e", "sha256": "9e5bc9e13af3aefd22cce83ffd0e0687135636896e26456d38d90e7fa866b6dd" }, "downloads": -1, "filename": "canal-py2-0.4.tar.gz", "has_sig": false, "md5_digest": "99968ec3ae8e27e4921e8024f3579b7e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22167, "upload_time": "2019-09-25T08:48:03", "url": "https://files.pythonhosted.org/packages/73/44/f7ba4216658ead0ab896b8abf1a92d36943d3ae4b803ba0d88621afd4456/canal-py2-0.4.tar.gz" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "39f5e000d38fe21cf90a829f7399d810", "sha256": "926132f1d0517571956f6cfeeaa0a4349e7ce7021079308afe054a15a36e0b12" }, "downloads": -1, "filename": "canal-py2-0.5.tar.gz", "has_sig": false, "md5_digest": "39f5e000d38fe21cf90a829f7399d810", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22424, "upload_time": "2019-09-27T03:58:57", "url": "https://files.pythonhosted.org/packages/e8/42/645c29028ba1c86f650c61e6f5490c6d10e045e68e18219ba846cbcc5191/canal-py2-0.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "39f5e000d38fe21cf90a829f7399d810", "sha256": "926132f1d0517571956f6cfeeaa0a4349e7ce7021079308afe054a15a36e0b12" }, "downloads": -1, "filename": "canal-py2-0.5.tar.gz", "has_sig": false, "md5_digest": "39f5e000d38fe21cf90a829f7399d810", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22424, "upload_time": "2019-09-27T03:58:57", "url": "https://files.pythonhosted.org/packages/e8/42/645c29028ba1c86f650c61e6f5490c6d10e045e68e18219ba846cbcc5191/canal-py2-0.5.tar.gz" } ] }