{"id":1116,"date":"2019-01-08T14:07:35","date_gmt":"2019-01-08T06:07:35","guid":{"rendered":"https:\/\/blog.jsjs.org\/?p=1116"},"modified":"2019-01-08T14:07:35","modified_gmt":"2019-01-08T06:07:35","slug":"%e9%9c%87%e6%83%8a%e4%ba%86%ef%bc%81%e5%8e%9f%e6%9d%a5%e8%bf%99%e6%89%8d%e6%98%afkafka%ef%bc%81","status":"publish","type":"post","link":"https:\/\/blog.jsjs.org\/?p=1116","title":{"rendered":"\u9707\u60ca\u4e86\uff01\u539f\u6765\u8fd9\u624d\u662fkafka\uff01"},"content":{"rendered":"<div>\n<div>\n<h2>\u7b80\u4ecb<\/h2>\n<p>kafka\u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u6d88\u606f\u961f\u5217\u3002\u5177\u6709\u9ad8\u6027\u80fd\u3001\u6301\u4e45\u5316\u3001\u591a\u526f\u672c\u5907\u4efd\u3001\u6a2a\u5411\u6269\u5c55\u80fd\u529b\u3002\u751f\u4ea7\u8005\u5f80\u961f\u5217\u91cc\u5199\u6d88\u606f\uff0c\u6d88\u8d39\u8005\u4ece\u961f\u5217\u91cc\u53d6\u6d88\u606f\u8fdb\u884c\u4e1a\u52a1\u903b\u8f91\u3002\u4e00\u822c\u5728\u67b6\u6784\u8bbe\u8ba1\u4e2d\u8d77\u5230\u89e3\u8026\u3001\u524a\u5cf0\u3001\u5f02\u6b65\u5904\u7406\u7684\u4f5c\u7528\u3002<\/p>\n<p>kafka\u5bf9\u5916\u4f7f\u7528topic\u7684\u6982\u5ff5\uff0c\u751f\u4ea7\u8005\u5f80topic\u91cc\u5199\u6d88\u606f\uff0c\u6d88\u8d39\u8005\u4ece\u8bfb\u6d88\u606f\u3002\u4e3a\u4e86\u505a\u5230\u6c34\u5e73\u6269\u5c55\uff0c\u4e00\u4e2atopic\u5b9e\u9645\u662f\u7531\u591a\u4e2apartition\u7ec4\u6210\u7684\uff0c\u9047\u5230\u74f6\u9888\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u589e\u52a0partition\u7684\u6570\u91cf\u6765\u8fdb\u884c\u6a2a\u5411\u6269\u5bb9\u3002\u5355\u4e2aparition\u5185\u662f\u4fdd\u8bc1\u6d88\u606f\u6709\u5e8f\u3002<\/p>\n<p>\u6bcf\u65b0\u5199\u4e00\u6761\u6d88\u606f\uff0ckafka\u5c31\u662f\u5728\u5bf9\u5e94\u7684\u6587\u4ef6append\u5199\uff0c\u6240\u4ee5\u6027\u80fd\u975e\u5e38\u9ad8\u3002<\/p>\n<p>kafka\u7684\u603b\u4f53\u6570\u636e\u6d41\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<div class=\"image-package\">\n<div class=\"image-container\">\n<div class=\"image-container-fill\"><\/div>\n<div class=\"image-view\" data-width=\"1376\" data-height=\"1193\"><img decoding=\"async\" class=\"\" src=\"\/\/upload-images.jianshu.io\/upload_images\/2835676-f378607bc841309a.png?imageMogr2\/auto-orient\/strip%7CimageView2\/2\/w\/1000\/format\/webp\" data-original-src=\"\/\/upload-images.jianshu.io\/upload_images\/2835676-f378607bc841309a.png\" data-original-width=\"1376\" data-original-height=\"1193\" data-original-format=\"image\/png\" data-original-filesize=\"155422\" \/><\/div>\n<\/div>\n<div class=\"image-caption\">kafka data flow<\/div>\n<\/div>\n<p>\u5927\u6982\u7528\u6cd5\u5c31\u662f\uff0cProducers\u5f80Brokers\u91cc\u9762\u7684\u6307\u5b9aTopic\u4e2d\u5199\u6d88\u606f\uff0cConsumers\u4eceBrokers\u91cc\u9762\u62c9\u53bb\u6307\u5b9aTopic\u7684\u6d88\u606f\uff0c\u7136\u540e\u8fdb\u884c\u4e1a\u52a1\u5904\u7406\u3002<br \/>\n\u56fe\u4e2d\u6709\u4e24\u4e2atopic\uff0ctopic 0\u6709\u4e24\u4e2apartition\uff0ctopic 1\u6709\u4e00\u4e2apartition\uff0c\u4e09\u526f\u672c\u5907\u4efd\u3002\u53ef\u4ee5\u770b\u5230consumer gourp 1\u4e2d\u7684consumer 2\u6ca1\u6709\u5206\u5230partition\u5904\u7406\uff0c\u8fd9\u662f\u6709\u53ef\u80fd\u51fa\u73b0\u7684\uff0c\u4e0b\u9762\u4f1a\u8bb2\u5230\u3002<\/p>\n<p>\u5173\u4e8ebroker\u3001topics\u3001partitions\u7684\u4e00\u4e9b\u5143\u4fe1\u606f\u7528zk\u6765\u5b58\uff0c\u76d1\u63a7\u548c\u8def\u7531\u5565\u7684\u4e5f\u90fd\u4f1a\u7528\u5230zk\u3002<\/p>\n<hr \/>\n<h2>\u751f\u4ea7<\/h2>\n<p>\u57fa\u672c\u6d41\u7a0b\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<div class=\"image-package\">\n<div class=\"image-container\">\n<div class=\"image-container-fill\"><\/div>\n<div class=\"image-view\" data-width=\"1876\" data-height=\"1156\"><img decoding=\"async\" class=\"\" src=\"\/\/upload-images.jianshu.io\/upload_images\/2835676-66af39d6c3e1f769.png?imageMogr2\/auto-orient\/strip%7CimageView2\/2\/w\/1000\/format\/webp\" data-original-src=\"\/\/upload-images.jianshu.io\/upload_images\/2835676-66af39d6c3e1f769.png\" data-original-width=\"1876\" data-original-height=\"1156\" data-original-format=\"image\/png\" data-original-filesize=\"115460\" \/><\/div>\n<\/div>\n<div class=\"image-caption\">kafka sdk product flow.png<\/div>\n<\/div>\n<p>\u521b\u5efa\u4e00\u6761\u8bb0\u5f55\uff0c\u8bb0\u5f55\u4e2d\u4e00\u4e2a\u8981\u6307\u5b9a\u5bf9\u5e94\u7684topic\u548cvalue\uff0ckey\u548cpartition\u53ef\u9009\u3002 \u5148\u5e8f\u5217\u5316\uff0c\u7136\u540e\u6309\u7167topic\u548cpartition\uff0c\u653e\u8fdb\u5bf9\u5e94\u7684\u53d1\u9001\u961f\u5217\u4e2d\u3002kafka produce\u90fd\u662f\u6279\u91cf\u8bf7\u6c42\uff0c\u4f1a\u79ef\u6512\u4e00\u6279\uff0c\u7136\u540e\u4e00\u8d77\u53d1\u9001\uff0c\u4e0d\u662f\u8c03send()\u5c31\u8fdb\u884c\u7acb\u523b\u8fdb\u884c\u7f51\u7edc\u53d1\u5305\u3002<br \/>\n\u5982\u679cpartition\u6ca1\u586b\uff0c\u90a3\u4e48\u60c5\u51b5\u4f1a\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<ol>\n<li>key\u6709\u586b<br \/>\n\u6309\u7167key\u8fdb\u884c\u54c8\u5e0c\uff0c\u76f8\u540ckey\u53bb\u4e00\u4e2apartition\u3002\uff08\u5982\u679c\u6269\u5c55\u4e86partition\u7684\u6570\u91cf\u90a3\u4e48\u5c31\u4e0d\u80fd\u4fdd\u8bc1\u4e86\uff09<\/li>\n<li>key\u6ca1\u586b<br \/>\nround-robin\u6765\u9009partition<\/li>\n<\/ol>\n<p>\u8fd9\u4e9b\u8981\u53d1\u5f80\u540c\u4e00\u4e2apartition\u7684\u8bf7\u6c42\u6309\u7167\u914d\u7f6e\uff0c\u6512\u4e00\u6ce2\uff0c\u7136\u540e\u7531\u4e00\u4e2a\u5355\u72ec\u7684\u7ebf\u7a0b\u4e00\u6b21\u6027\u53d1\u8fc7\u53bb\u3002<\/p>\n<h3>API<\/h3>\n<p>\u6709high level api\uff0c\u66ff\u6211\u4eec\u628a\u5f88\u591a\u4e8b\u60c5\u90fd\u5e72\u4e86\uff0coffset\uff0c\u8def\u7531\u5565\u90fd\u66ff\u6211\u4eec\u5e72\u4e86\uff0c\u7528\u4ee5\u6765\u5f88\u7b80\u5355\u3002<br \/>\n\u8fd8\u6709simple api\uff0coffset\u5565\u7684\u90fd\u662f\u8981\u6211\u4eec\u81ea\u5df1\u8bb0\u5f55\u3002<\/p>\n<h3>partition<\/h3>\n<p>\u5f53\u5b58\u5728\u591a\u526f\u672c\u7684\u60c5\u51b5\u4e0b\uff0c\u4f1a\u5c3d\u91cf\u628a\u591a\u4e2a\u526f\u672c\uff0c\u5206\u914d\u5230\u4e0d\u540c\u7684broker\u4e0a\u3002<strong>kafka\u4f1a\u4e3apartition\u9009\u51fa\u4e00\u4e2aleader\uff0c\u4e4b\u540e\u6240\u6709\u8be5partition\u7684\u8bf7\u6c42\uff0c\u5b9e\u9645\u64cd\u4f5c\u7684\u90fd\u662fleader\uff0c\u7136\u540e\u518d\u540c\u6b65\u5230\u5176\u4ed6\u7684follower\u3002<\/strong>\u5f53\u4e00\u4e2abroker\u6b47\u83dc\u540e\uff0c\u6240\u6709leader\u5728\u8be5broker\u4e0a\u7684partition\u90fd\u4f1a\u91cd\u65b0\u9009\u4e3e\uff0c\u9009\u51fa\u4e00\u4e2aleader\u3002\uff08\u8fd9\u91cc\u4e0d\u50cf\u5206\u5e03\u5f0f\u6587\u4ef6\u5b58\u50a8\u7cfb\u7edf\u90a3\u6837\u4f1a\u81ea\u52a8\u8fdb\u884c\u590d\u5236\u4fdd\u6301\u526f\u672c\u6570\uff09<\/p>\n<p>\u7136\u540e\u8fd9\u91cc\u5c31\u6d89\u53ca\u4e24\u4e2a\u7ec6\u8282\uff1a\u600e\u4e48\u5206\u914dpartition\uff0c\u600e\u4e48\u9009leader\u3002<\/p>\n<p><strong>\u5173\u4e8epartition\u7684\u5206\u914d\uff0c\u8fd8\u6709leader\u7684\u9009\u4e3e\uff0c\u603b\u5f97\u6709\u4e2a\u6267\u884c\u8005\u3002\u5728kafka\u4e2d\uff0c\u8fd9\u4e2a\u6267\u884c\u8005\u5c31\u53ebcontroller\u3002<\/strong>kafka\u4f7f\u7528zk\u5728broker\u4e2d\u9009\u51fa\u4e00\u4e2acontroller\uff0c\u7528\u4e8epartition\u5206\u914d\u548cleader\u9009\u4e3e\u3002<\/p>\n<h4>partition\u7684\u5206\u914d<\/h4>\n<ol>\n<li>\u5c06\u6240\u6709Broker\uff08\u5047\u8bbe\u5171n\u4e2aBroker\uff09\u548c\u5f85\u5206\u914d\u7684Partition\u6392\u5e8f<\/li>\n<li>\u5c06\u7b2ci\u4e2aPartition\u5206\u914d\u5230\u7b2c\uff08i mod n\uff09\u4e2aBroker\u4e0a \uff08\u8fd9\u4e2a\u5c31\u662fleader\uff09<\/li>\n<li>\u5c06\u7b2ci\u4e2aPartition\u7684\u7b2cj\u4e2aReplica\u5206\u914d\u5230\u7b2c\uff08(i + j) mode n\uff09\u4e2aBroker\u4e0a<\/li>\n<\/ol>\n<h4>leader\u5bb9\u707e<\/h4>\n<p>controller\u4f1a\u5728Zookeeper\u7684\/brokers\/ids\u8282\u70b9\u4e0a\u6ce8\u518cWatch\uff0c\u4e00\u65e6\u6709broker\u5b95\u673a\uff0c\u5b83\u5c31\u80fd\u77e5\u9053\u3002\u5f53broker\u5b95\u673a\u540e\uff0ccontroller\u5c31\u4f1a\u7ed9\u53d7\u5230\u5f71\u54cd\u7684partition\u9009\u51fa\u65b0leader\u3002controller\u4ecezk\u7684\/brokers\/topics\/[topic]\/partitions\/[partition]\/state\u4e2d\uff0c\u8bfb\u53d6\u5bf9\u5e94partition\u7684ISR\uff08in-sync replica\u5df2\u540c\u6b65\u7684\u526f\u672c\uff09\u5217\u8868\uff0c\u9009\u4e00\u4e2a\u51fa\u6765\u505aleader\u3002<br \/>\n\u9009\u51faleader\u540e\uff0c\u66f4\u65b0zk\uff0c\u7136\u540e\u53d1\u9001LeaderAndISRRequest\u7ed9\u53d7\u5f71\u54cd\u7684broker\uff0c\u8ba9\u5b83\u4eec\u6539\u53d8\u77e5\u9053\u8fd9\u4e8b\u3002\u4e3a\u4ec0\u4e48\u8fd9\u91cc\u4e0d\u662f\u4f7f\u7528zk\u901a\u77e5\uff0c\u800c\u662f\u76f4\u63a5\u7ed9broker\u53d1\u9001rpc\u8bf7\u6c42\uff0c\u6211\u7684\u7406\u89e3\u53ef\u80fd\u662f\u8fd9\u6837\u505azk\u6709\u6027\u80fd\u95ee\u9898\u5427\u3002<\/p>\n<p>\u5982\u679cISR\u5217\u8868\u662f\u7a7a\uff0c\u90a3\u4e48\u4f1a\u6839\u636e\u914d\u7f6e\uff0c\u968f\u4fbf\u9009\u4e00\u4e2areplica\u505aleader\uff0c\u6216\u8005\u5e72\u8106\u8fd9\u4e2apartition\u5c31\u662f\u6b47\u83dc\u3002\u5982\u679cISR\u5217\u8868\u7684\u6709\u673a\u5668\uff0c\u4f46\u662f\u4e5f\u6b47\u83dc\u4e86\uff0c\u90a3\u4e48\u8fd8\u53ef\u4ee5\u7b49ISR\u7684\u673a\u5668\u6d3b\u8fc7\u6765\u3002<\/p>\n<h4>\u591a\u526f\u672c\u540c\u6b65<\/h4>\n<p>\u8fd9\u91cc\u7684\u7b56\u7565\uff0c\u670d\u52a1\u7aef\u8fd9\u8fb9\u7684\u5904\u7406\u662ffollower\u4eceleader\u6279\u91cf\u62c9\u53d6\u6570\u636e\u6765\u540c\u6b65\u3002\u4f46\u662f\u5177\u4f53\u7684\u53ef\u9760\u6027\uff0c\u662f\u7531\u751f\u4ea7\u8005\u6765\u51b3\u5b9a\u7684\u3002<br \/>\n\u751f\u4ea7\u8005\u751f\u4ea7\u6d88\u606f\u7684\u65f6\u5019\uff0c\u901a\u8fc7request.required.acks\u53c2\u6570\u6765\u8bbe\u7f6e\u6570\u636e\u7684\u53ef\u9760\u6027\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th>acks<\/th>\n<th>what happen<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>0<\/td>\n<td>which means that the producer never waits for an acknowledgement from the broker.\u53d1\u8fc7\u53bb\u5c31\u5b8c\u4e8b\u4e86\uff0c\u4e0d\u5173\u5fc3broker\u662f\u5426\u5904\u7406\u6210\u529f\uff0c\u53ef\u80fd\u4e22\u6570\u636e\u3002<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>which means that the producer gets an acknowledgement after the leader replica has received the data. \u5f53\u5199Leader\u6210\u529f\u540e\u5c31\u8fd4\u56de,\u5176\u4ed6\u7684replica\u90fd\u662f\u901a\u8fc7fetcher\u53bb\u540c\u6b65\u7684,\u6240\u4ee5kafka\u662f\u5f02\u6b65\u5199\uff0c\u4e3b\u5907\u5207\u6362\u53ef\u80fd\u4e22\u6570\u636e\u3002<\/td>\n<\/tr>\n<tr>\n<td>-1<\/td>\n<td>which means that the producer gets an acknowledgement after all in-sync replicas have received the data. \u8981\u7b49\u5230isr\u91cc\u6240\u6709\u673a\u5668\u540c\u6b65\u6210\u529f\uff0c\u624d\u80fd\u8fd4\u56de\u6210\u529f\uff0c\u5ef6\u65f6\u53d6\u51b3\u4e8e\u6700\u6162\u7684\u673a\u5668\u3002\u5f3a\u4e00\u81f4\uff0c\u4e0d\u4f1a\u4e22\u6570\u636e\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5728acks=-1\u7684\u65f6\u5019\uff0c\u5982\u679cISR\u5c11\u4e8emin.insync.replicas\u6307\u5b9a\u7684\u6570\u76ee\uff0c\u90a3\u4e48\u5c31\u4f1a\u8fd4\u56de\u4e0d\u53ef\u7528\u3002<\/p>\n<p>\u8fd9\u91ccISR\u5217\u8868\u4e2d\u7684\u673a\u5668\u662f\u4f1a\u53d8\u5316\u7684\uff0c\u6839\u636e\u914d\u7f6ereplica.lag.time.max.ms\uff0c\u591a\u4e45\u6ca1\u540c\u6b65\uff0c\u5c31\u4f1a\u4eceISR\u5217\u8868\u4e2d\u5254\u9664\u3002\u4ee5\u524d\u8fd8\u6709\u6839\u636e\u843d\u540e\u591a\u5c11\u6761\u6d88\u606f\u5c31\u8e22\u51faISR\uff0c\u57281.0\u7248\u672c\u540e\u5c31\u53bb\u6389\u4e86\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u503c\u5f88\u96be\u53d6\uff0c\u5728\u9ad8\u5cf0\u7684\u65f6\u5019\u5f88\u5bb9\u6613\u51fa\u73b0\u8282\u70b9\u4e0d\u65ad\u7684\u8fdb\u51faISR\u5217\u8868\u3002<\/p>\n<p>\u4eceISA\u4e2d\u9009\u51faleader\u540e\uff0cfollower\u4f1a\u4ece\u628a\u81ea\u5df1\u65e5\u5fd7\u4e2d\u4e0a\u4e00\u4e2a\u9ad8\u6c34\u4f4d\u540e\u9762\u7684\u8bb0\u5f55\u53bb\u6389\uff0c\u7136\u540e\u53bb\u548cleader\u62ff\u65b0\u7684\u6570\u636e\u3002\u56e0\u4e3a\u65b0\u7684leader\u9009\u51fa\u6765\u540e\uff0cfollower\u4e0a\u9762\u7684\u6570\u636e\uff0c\u53ef\u80fd\u6bd4\u65b0leader\u591a\uff0c\u6240\u4ee5\u8981\u622a\u53d6\u3002\u8fd9\u91cc\u9ad8\u6c34\u4f4d\u7684\u610f\u601d\uff0c\u5bf9\u4e8epartition\u548cleader\uff0c\u5c31\u662f\u6240\u6709ISR\u4e2d\u90fd\u6709\u7684\u6700\u65b0\u4e00\u6761\u8bb0\u5f55\u3002\u6d88\u8d39\u8005\u6700\u591a\u53ea\u80fd\u8bfb\u5230\u9ad8\u6c34\u4f4d\uff1b<\/p>\n<p>\u4eceleader\u7684\u89d2\u5ea6\u6765\u8bf4\u9ad8\u6c34\u4f4d\u7684\u66f4\u65b0\u4f1a\u5ef6\u8fdf\u4e00\u8f6e\uff0c\u4f8b\u5982\u5199\u5165\u4e86\u4e00\u6761\u65b0\u6d88\u606f\uff0cISR\u4e2d\u7684broker\u90fdfetch\u5230\u4e86\uff0c\u4f46\u662fISR\u4e2d\u7684broker\u53ea\u6709\u5728\u4e0b\u4e00\u8f6e\u7684fetch\u4e2d\u624d\u80fd\u544a\u8bc9leader\u3002<\/p>\n<p>\u4e5f\u6b63\u662f\u7531\u4e8e\u8fd9\u4e2a\u9ad8\u6c34\u4f4d\u5ef6\u8fdf\u4e00\u8f6e\uff0c\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\uff0ckafka\u4f1a\u51fa\u73b0\u4e22\u6570\u636e\u548c\u4e3b\u5907\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\uff0c0.11\u5f00\u59cb\uff0c\u4f7f\u7528leader epoch\u6765\u4ee3\u66ff\u9ad8\u6c34\u4f4d\u3002\uff08<a href=\"https:\/\/link.jianshu.com?t=https%3A%2F%2Fcwiki.apache.org%2Fconfluence%2Fdisplay%2FKAFKA%2FKIP-101%2B-%2BAlter%2BReplication%2BProtocol%2Bto%2Buse%2BLeader%2BEpoch%2Brather%2Bthan%2BHigh%2BWatermark%2Bfor%2BTruncation%23KIP-101-AlterReplicationProtocoltouseLeaderEpochratherthanHighWatermarkforTruncation-Scenario1%3AHighWatermarkTruncationfollowedbyImmediateLeaderElection\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/cwiki.apache.org\/confluence\/display\/KAFKA\/KIP-101+-+Alter+Replication+Protocol+to+use+Leader+Epoch+rather+than+High+Watermark+for+Truncation#KIP-101-AlterReplicationProtocoltouseLeaderEpochratherthanHighWatermarkforTruncation-Scenario1:HighWatermarkTruncationfollowedbyImmediateLeaderElection<\/a>\uff09<\/p>\n<p><strong><em>\u601d\u8003\uff1a<\/em><\/strong><br \/>\n\u5f53acks=-1\u65f6<\/p>\n<ol>\n<li>\u662ffollwers\u90fd\u6765fetch\u5c31\u8fd4\u56de\u6210\u529f\uff0c\u8fd8\u662f\u7b49follwers\u7b2c\u4e8c\u8f6efetch\uff1f<\/li>\n<li>leader\u5df2\u7ecf\u5199\u5165\u672c\u5730\uff0c\u4f46\u662fISR\u4e2d\u6709\u4e9b\u673a\u5668\u5931\u8d25\uff0c\u90a3\u4e48\u600e\u4e48\u5904\u7406\u5462\uff1f<\/li>\n<\/ol>\n<hr \/>\n<h2>\u6d88\u8d39<\/h2>\n<p>\u8ba2\u9605topic\u662f\u4ee5\u4e00\u4e2a\u6d88\u8d39\u7ec4\u6765\u8ba2\u9605\u7684\uff0c\u4e00\u4e2a\u6d88\u8d39\u7ec4\u91cc\u9762\u53ef\u4ee5\u6709\u591a\u4e2a\u6d88\u8d39\u8005\u3002\u540c\u4e00\u4e2a\u6d88\u8d39\u7ec4\u4e2d\u7684\u4e24\u4e2a\u6d88\u8d39\u8005\uff0c\u4e0d\u4f1a\u540c\u65f6\u6d88\u8d39\u4e00\u4e2apartition\u3002\u6362\u53e5\u8bdd\u6765\u8bf4\uff0c<strong>\u5c31\u662f\u4e00\u4e2apartition\uff0c\u53ea\u80fd\u88ab\u6d88\u8d39\u7ec4\u91cc\u7684\u4e00\u4e2a\u6d88\u8d39\u8005\u6d88\u8d39<\/strong>\uff0c\u4f46\u662f\u53ef\u4ee5\u540c\u65f6\u88ab\u591a\u4e2a\u6d88\u8d39\u7ec4\u6d88\u8d39\u3002\u56e0\u6b64\uff0c\u5982\u679c\u6d88\u8d39\u7ec4\u5185\u7684\u6d88\u8d39\u8005\u5982\u679c\u6bd4partition\u591a\u7684\u8bdd\uff0c\u90a3\u4e48\u5c31\u4f1a\u6709\u4e2a\u522b\u6d88\u8d39\u8005\u4e00\u76f4\u7a7a\u95f2\u3002<\/p>\n<div class=\"image-package\">\n<div class=\"image-container\">\n<div class=\"image-container-fill\"><\/div>\n<div class=\"image-view\" data-width=\"2508\" data-height=\"1414\"><img decoding=\"async\" class=\"\" src=\"\/\/upload-images.jianshu.io\/upload_images\/2835676-15c32e096cdbdabb.png?imageMogr2\/auto-orient\/strip%7CimageView2\/2\/w\/1000\/format\/webp\" data-original-src=\"\/\/upload-images.jianshu.io\/upload_images\/2835676-15c32e096cdbdabb.png\" data-original-width=\"2508\" data-original-height=\"1414\" data-original-format=\"image\/png\" data-original-filesize=\"173639\" \/><\/div>\n<\/div>\n<div class=\"image-caption\">untitled_page.png<\/div>\n<\/div>\n<h3>API<\/h3>\n<p>\u8ba2\u9605topic\u65f6\uff0c\u53ef\u4ee5\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u5982\u679c\u6709\u65b0topic\u5339\u914d\u4e0a\uff0c\u90a3\u80fd\u81ea\u52a8\u8ba2\u9605\u4e0a\u3002<\/p>\n<h3>offset\u7684\u4fdd\u5b58<\/h3>\n<p>\u4e00\u4e2a\u6d88\u8d39\u7ec4\u6d88\u8d39partition\uff0c\u9700\u8981\u4fdd\u5b58offset\u8bb0\u5f55\u6d88\u8d39\u5230\u54ea\uff0c\u4ee5\u524d\u4fdd\u5b58\u5728zk\u4e2d\uff0c\u7531\u4e8ezk\u7684\u5199\u6027\u80fd\u4e0d\u597d\uff0c\u4ee5\u524d\u7684\u89e3\u51b3\u65b9\u6cd5\u90fd\u662fconsumer\u6bcf\u9694\u4e00\u5206\u949f\u4e0a\u62a5\u4e00\u6b21\u3002\u8fd9\u91cczk\u7684\u6027\u80fd\u4e25\u91cd\u5f71\u54cd\u4e86\u6d88\u8d39\u7684\u901f\u5ea6\uff0c\u800c\u4e14\u5f88\u5bb9\u6613\u51fa\u73b0\u91cd\u590d\u6d88\u8d39\u3002<br \/>\n\u57280.10\u7248\u672c\u540e\uff0ckafka\u628a\u8fd9\u4e2aoffset\u7684\u4fdd\u5b58\uff0c\u4ecezk\u603b\u5265\u79bb\uff0c\u4fdd\u5b58\u5728\u4e00\u4e2a\u540d\u53eb__consumeroffsets topic\u7684topic\u4e2d\u3002\u5199\u8fdb\u6d88\u606f\u7684key\u7531groupid\u3001topic\u3001partition\u7ec4\u6210\uff0cvalue\u662f\u504f\u79fb\u91cfoffset\u3002topic\u914d\u7f6e\u7684\u6e05\u7406\u7b56\u7565\u662fcompact\u3002\u603b\u662f\u4fdd\u7559\u6700\u65b0\u7684key\uff0c\u5176\u4f59\u5220\u6389\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u6bcf\u4e2akey\u7684offset\u90fd\u662f\u7f13\u5b58\u5728\u5185\u5b58\u4e2d\uff0c\u67e5\u8be2\u7684\u65f6\u5019\u4e0d\u7528\u904d\u5386partition\uff0c\u5982\u679c\u6ca1\u6709\u7f13\u5b58\uff0c\u7b2c\u4e00\u6b21\u5c31\u4f1a\u904d\u5386partition\u5efa\u7acb\u7f13\u5b58\uff0c\u7136\u540e\u67e5\u8be2\u8fd4\u56de\u3002<\/p>\n<p>\u786e\u5b9aconsumer group\u4f4d\u79fb\u4fe1\u606f\u5199\u5165__consumers_offsets\u7684\u54ea\u4e2apartition\uff0c\u5177\u4f53\u8ba1\u7b97\u516c\u5f0f\uff1a<\/p>\n<pre class=\"hljs cpp\"><code class=\"cpp\">__consumers_offsets partition =\n           Math.<span class=\"hljs-built_in\">abs<\/span>(groupId.hashCode() % groupMetadataTopicPartitionCount)\n<span class=\"hljs-comment\">\/\/groupMetadataTopicPartitionCount\u7531offsets.topic.num.partitions\u6307\u5b9a\uff0c\u9ed8\u8ba4\u662f50\u4e2a\u5206\u533a\u3002<\/span>\n<\/code><\/pre>\n<p><strong><em>\u601d\u8003\uff1a<\/em><\/strong><br \/>\n\u5982\u679c\u6b63\u5728\u8dd1\u7684\u670d\u52a1\uff0c\u4fee\u6539\u4e86offsets.topic.num.partitions\uff0c\u90a3\u4e48offset\u7684\u4fdd\u5b58\u662f\u4e0d\u662f\u5c31\u4e71\u5957\u4e86\uff1f<\/p>\n<h3>\u5206\u914dpartition&#8211;reblance<\/h3>\n<p>\u751f\u4ea7\u8fc7\u7a0b\u4e2dbroker\u8981\u5206\u914dpartition\uff0c<strong>\u6d88\u8d39\u8fc7\u7a0b\u8fd9\u91cc\uff0c\u4e5f\u8981\u5206\u914dpartition\u7ed9\u6d88\u8d39\u8005\u3002\u7c7b\u4f3cbroker\u4e2d\u9009\u4e86\u4e00\u4e2acontroller\u51fa\u6765\uff0c\u6d88\u8d39\u4e5f\u8981\u4ecebroker\u4e2d\u9009\u4e00\u4e2acoordinator\uff0c\u7528\u4e8e\u5206\u914dpartition\u3002<\/strong><br \/>\n\u4e0b\u9762\u4ece\u9876\u5411\u4e0b\uff0c\u5206\u522b\u9610\u8ff0\u4e00\u4e0b<\/p>\n<ol>\n<li>\u600e\u4e48\u9009coordinator\u3002<\/li>\n<li>\u4ea4\u4e92\u6d41\u7a0b\u3002<\/li>\n<li>reblance\u7684\u6d41\u7a0b\u3002<\/li>\n<\/ol>\n<h4>\u9009coordinator<\/h4>\n<ol>\n<li>\u770boffset\u4fdd\u5b58\u5728\u90a3\u4e2apartition<\/li>\n<li>\u8be5partition leader\u6240\u5728\u7684broker\u5c31\u662f\u88ab\u9009\u5b9a\u7684coordinator<\/li>\n<\/ol>\n<p>\u8fd9\u91cc\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0cconsumer group\u7684coordinator\uff0c\u548c\u4fdd\u5b58consumer group offset\u7684partition leader\u662f\u540c\u4e00\u53f0\u673a\u5668\u3002<\/p>\n<h4>\u4ea4\u4e92\u6d41\u7a0b<\/h4>\n<p>\u628acoordinator\u9009\u51fa\u6765\u4e4b\u540e\uff0c\u5c31\u662f\u8981\u5206\u914d\u4e86<br \/>\n\u6574\u4e2a\u6d41\u7a0b\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<ol>\n<li>consumer\u542f\u52a8\u3001\u6216\u8005coordinator\u5b95\u673a\u4e86\uff0cconsumer\u4f1a\u4efb\u610f\u8bf7\u6c42\u4e00\u4e2abroker\uff0c\u53d1\u9001ConsumerMetadataRequest\u8bf7\u6c42\uff0cbroker\u4f1a\u6309\u7167\u4e0a\u9762\u8bf4\u7684\u65b9\u6cd5\uff0c\u9009\u51fa\u8fd9\u4e2aconsumer\u5bf9\u5e94coordinator\u7684\u5730\u5740\u3002<\/li>\n<li>consumer \u53d1\u9001heartbeat\u8bf7\u6c42\u7ed9coordinator\uff0c\u8fd4\u56deIllegalGeneration\u7684\u8bdd\uff0c\u5c31\u8bf4\u660econsumer\u7684\u4fe1\u606f\u662f\u65e7\u7684\u4e86\uff0c\u9700\u8981\u91cd\u65b0\u52a0\u5165\u8fdb\u6765\uff0c\u8fdb\u884creblance\u3002\u8fd4\u56de\u6210\u529f\uff0c\u90a3\u4e48consumer\u5c31\u4ece\u4e0a\u6b21\u5206\u914d\u7684partition\u4e2d\u7ee7\u7eed\u6267\u884c\u3002<\/li>\n<\/ol>\n<h4>reblance\u6d41\u7a0b<\/h4>\n<ol>\n<li>consumer\u7ed9coordinator\u53d1\u9001JoinGroupRequest\u8bf7\u6c42\u3002<\/li>\n<li>\u8fd9\u65f6\u5176\u4ed6consumer\u53d1heartbeat\u8bf7\u6c42\u8fc7\u6765\u65f6\uff0ccoordinator\u4f1a\u544a\u8bc9\u4ed6\u4eec\uff0c\u8981reblance\u4e86\u3002<\/li>\n<li>\u5176\u4ed6consumer\u53d1\u9001JoinGroupRequest\u8bf7\u6c42\u3002<\/li>\n<li>\u6240\u6709\u8bb0\u5f55\u5728\u518c\u7684consumer\u90fd\u53d1\u4e86JoinGroupRequest\u8bf7\u6c42\u4e4b\u540e\uff0ccoordinator\u5c31\u4f1a\u5728\u8fd9\u91ccconsumer\u4e2d\u968f\u4fbf\u9009\u4e00\u4e2aleader\u3002\u7136\u540e\u56deJoinGroupRespone\uff0c\u8fd9\u4f1a\u544a\u8bc9consumer\u4f60\u662ffollower\u8fd8\u662fleader\uff0c\u5bf9\u4e8eleader\uff0c\u8fd8\u4f1a\u628afollower\u7684\u4fe1\u606f\u5e26\u7ed9\u5b83\uff0c\u8ba9\u5b83\u6839\u636e\u8fd9\u4e9b\u4fe1\u606f\u53bb\u5206\u914dpartition<\/li>\n<\/ol>\n<p>5\u3001consumer\u5411coordinator\u53d1\u9001SyncGroupRequest\uff0c\u5176\u4e2dleader\u7684SyncGroupRequest\u4f1a\u5305\u542b\u5206\u914d\u7684\u60c5\u51b5\u3002<br \/>\n6\u3001coordinator\u56de\u5305\uff0c\u628a\u5206\u914d\u7684\u60c5\u51b5\u544a\u8bc9consumer\uff0c\u5305\u62ecleader\u3002<\/p>\n<p>\u5f53partition\u6216\u8005\u6d88\u8d39\u8005\u7684\u6570\u91cf\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u90fd\u5f97\u8fdb\u884creblance\u3002<br \/>\n\u5217\u4e3e\u4e00\u4e0b\u4f1areblance\u7684\u60c5\u51b5\uff1a<\/p>\n<ol>\n<li>\u589e\u52a0partition<\/li>\n<li>\u589e\u52a0\u6d88\u8d39\u8005<\/li>\n<li>\u6d88\u8d39\u8005\u4e3b\u52a8\u5173\u95ed<\/li>\n<li>\u6d88\u8d39\u8005\u5b95\u673a\u4e86<\/li>\n<li>coordinator\u81ea\u5df1\u4e5f\u5b95\u673a\u4e86<\/li>\n<\/ol>\n<hr \/>\n<h2>\u6d88\u606f\u6295\u9012\u8bed\u4e49<\/h2>\n<p>kafka\u652f\u63013\u79cd\u6d88\u606f\u6295\u9012\u8bed\u4e49<br \/>\nAt most once\uff1a\u6700\u591a\u4e00\u6b21\uff0c\u6d88\u606f\u53ef\u80fd\u4f1a\u4e22\u5931\uff0c\u4f46\u4e0d\u4f1a\u91cd\u590d<br \/>\nAt least once\uff1a\u6700\u5c11\u4e00\u6b21\uff0c\u6d88\u606f\u4e0d\u4f1a\u4e22\u5931\uff0c\u53ef\u80fd\u4f1a\u91cd\u590d<br \/>\nExactly once\uff1a\u53ea\u4e14\u4e00\u6b21\uff0c\u6d88\u606f\u4e0d\u4e22\u5931\u4e0d\u91cd\u590d\uff0c\u53ea\u4e14\u6d88\u8d39\u4e00\u6b21\uff080.11\u4e2d\u5b9e\u73b0\uff0c\u4ec5\u9650\u4e8e\u4e0b\u6e38\u4e5f\u662fkafka\uff09<\/p>\n<p>\u5728\u4e1a\u52a1\u4e2d\uff0c\u5e38\u5e38\u90fd\u662f\u4f7f\u7528At least once\u7684\u6a21\u578b\uff0c\u5982\u679c\u9700\u8981\u53ef\u91cd\u5165\u7684\u8bdd\uff0c\u5f80\u5f80\u662f\u4e1a\u52a1\u81ea\u5df1\u5b9e\u73b0\u3002<\/p>\n<h3>At least once<\/h3>\n<p>\u5148\u83b7\u53d6\u6570\u636e\uff0c\u518d\u8fdb\u884c\u4e1a\u52a1\u5904\u7406\uff0c\u4e1a\u52a1\u5904\u7406\u6210\u529f\u540ecommit offset\u3002<br \/>\n1\u3001\u751f\u4ea7\u8005\u751f\u4ea7\u6d88\u606f\u5f02\u5e38\uff0c\u6d88\u606f\u662f\u5426\u6210\u529f\u5199\u5165\u4e0d\u786e\u5b9a\uff0c\u91cd\u505a\uff0c\u53ef\u80fd\u5199\u5165\u91cd\u590d\u7684\u6d88\u606f<br \/>\n2\u3001\u6d88\u8d39\u8005\u5904\u7406\u6d88\u606f\uff0c\u4e1a\u52a1\u5904\u7406\u6210\u529f\u540e\uff0c\u66f4\u65b0offset\u5931\u8d25\uff0c\u6d88\u8d39\u8005\u91cd\u542f\u7684\u8bdd\uff0c\u4f1a\u91cd\u590d\u6d88\u8d39<\/p>\n<h3>At most once<\/h3>\n<p>\u5148\u83b7\u53d6\u6570\u636e\uff0c\u518dcommit offset\uff0c\u6700\u540e\u8fdb\u884c\u4e1a\u52a1\u5904\u7406\u3002<br \/>\n1\u3001\u751f\u4ea7\u8005\u751f\u4ea7\u6d88\u606f\u5f02\u5e38\uff0c\u4e0d\u7ba1\uff0c\u751f\u4ea7\u4e0b\u4e00\u4e2a\u6d88\u606f\uff0c\u6d88\u606f\u5c31\u4e22\u4e86<br \/>\n2\u3001\u6d88\u8d39\u8005\u5904\u7406\u6d88\u606f\uff0c\u5148\u66f4\u65b0offset\uff0c\u518d\u505a\u4e1a\u52a1\u5904\u7406\uff0c\u505a\u4e1a\u52a1\u5904\u7406\u5931\u8d25\uff0c\u6d88\u8d39\u8005\u91cd\u542f\uff0c\u6d88\u606f\u5c31\u4e22\u4e86<\/p>\n<h3>Exactly once<\/h3>\n<p>\u601d\u8def\u662f\u8fd9\u6837\u7684\uff0c\u9996\u5148\u8981\u4fdd\u8bc1\u6d88\u606f\u4e0d\u4e22\uff0c\u518d\u53bb\u4fdd\u8bc1\u4e0d\u91cd\u590d\u3002\u6240\u4ee5\u76ef\u7740At least once\u7684\u539f\u56e0\u6765\u641e\u3002 \u9996\u5148\u60f3\u51fa\u6765\u7684\uff1a<\/p>\n<ol>\n<li>\u751f\u4ea7\u8005\u91cd\u505a\u5bfc\u81f4\u91cd\u590d\u5199\u5165\u6d88\u606f&#8212;-\u751f\u4ea7\u4fdd\u8bc1\u5e42\u7b49\u6027<\/li>\n<li>\u6d88\u8d39\u8005\u91cd\u590d\u6d88\u8d39&#8212;\u6d88\u706d\u91cd\u590d\u6d88\u8d39\uff0c\u6216\u8005\u4e1a\u52a1\u63a5\u53e3\u4fdd\u8bc1\u5e42\u7b49\u6027\u91cd\u590d\u6d88\u8d39\u4e5f\u6ca1\u95ee\u9898<\/li>\n<\/ol>\n<p><strong>\u7531\u4e8e\u4e1a\u52a1\u63a5\u53e3\u662f\u5426\u5e42\u7b49\uff0c\u4e0d\u662fkafka\u80fd\u4fdd\u8bc1\u7684\uff0c\u6240\u4ee5kafka\u8fd9\u91cc\u63d0\u4f9b\u7684exactly once\u662f\u6709\u9650\u5236\u7684\uff0c\u6d88\u8d39\u8005\u7684\u4e0b\u6e38\u4e5f\u5fc5\u987b\u662fkafka\u3002<\/strong>\u6240\u4ee5\u4e00\u4e0b\u8ba8\u8bba\u7684\uff0c\u6ca1\u7279\u6b8a\u8bf4\u660e\uff0c\u6d88\u8d39\u8005\u7684\u4e0b\u6e38\u7cfb\u7edf\u90fd\u662fkafka\uff08\u6ce8:\u4f7f\u7528kafka conector\uff0c\u5b83\u5bf9\u90e8\u5206\u7cfb\u7edf\u505a\u4e86\u9002\u914d\uff0c\u5b9e\u73b0\u4e86exactly once\uff09\u3002<\/p>\n<p>\u751f\u4ea7\u8005\u5e42\u7b49\u6027\u597d\u505a\uff0c\u6ca1\u5565\u95ee\u9898\u3002<\/p>\n<p>\u89e3\u51b3\u91cd\u590d\u6d88\u8d39\u6709\u4e24\u4e2a\u65b9\u6cd5\uff1a<\/p>\n<ol>\n<li>\u4e0b\u6e38\u7cfb\u7edf\u4fdd\u8bc1\u5e42\u7b49\u6027\uff0c\u91cd\u590d\u6d88\u8d39\u4e5f\u4e0d\u4f1a\u5bfc\u81f4\u591a\u6761\u8bb0\u5f55\u3002<\/li>\n<li>\u628acommit offset\u548c\u4e1a\u52a1\u5904\u7406\u7ed1\u5b9a\u6210\u4e00\u4e2a\u4e8b\u52a1\u3002<\/li>\n<\/ol>\n<p>\u672c\u6765exactly once\u5b9e\u73b0\u7b2c1\u70b9\u5c31ok\u4e86\u3002<\/p>\n<p>\u4f46\u662f\u5728\u4e00\u4e9b\u4f7f\u7528\u573a\u666f\u4e0b\uff0c\u6211\u4eec\u7684\u6570\u636e\u6e90\u53ef\u80fd\u662f\u591a\u4e2atopic\uff0c\u5904\u7406\u540e\u8f93\u51fa\u5230\u591a\u4e2atopic\uff0c\u8fd9\u65f6\u6211\u4eec\u4f1a\u5e0c\u671b\u8f93\u51fa\u65f6\u8981\u4e48\u5168\u90e8\u6210\u529f\uff0c\u8981\u4e48\u5168\u90e8\u5931\u8d25\u3002<strong>\u8fd9\u5c31\u9700\u8981\u5b9e\u73b0\u4e8b\u52a1\u6027\u3002<\/strong>\u65e2\u7136\u8981\u505a\u4e8b\u52a1\uff0c\u90a3\u4e48\u5e72\u8106<strong>\u628a\u91cd\u590d\u6d88\u8d39\u7684\u95ee\u9898\u4ece\u6839\u6e90\u4e0a\u89e3\u51b3\uff0c\u628acommit offset\u548c\u8f93\u51fa\u5230\u5176\u4ed6topic\u7ed1\u5b9a\u6210\u4e00\u4e2a\u4e8b\u52a1\u3002<\/strong><\/p>\n<h4>\u751f\u4ea7\u5e42\u7b49\u6027<\/h4>\n<p>\u601d\u8def\u662f\u8fd9\u6837\u7684\uff0c\u4e3a\u6bcf\u4e2aproducer\u5206\u914d\u4e00\u4e2apid\uff0c\u4f5c\u4e3a\u8be5producer\u7684\u552f\u4e00\u6807\u8bc6\u3002producer\u4f1a\u4e3a\u6bcf\u4e00\u4e2a&lt;topic,partition&gt;\u7ef4\u62a4\u4e00\u4e2a\u5355\u8c03\u9012\u589e\u7684seq\u3002\u7c7b\u4f3c\u7684\uff0cbroker\u4e5f\u4f1a\u4e3a\u6bcf\u4e2a&lt;pid,topic,partition&gt;\u8bb0\u5f55\u4e0b\u6700\u65b0\u7684seq\u3002\u5f53req_seq == broker_seq+1\u65f6\uff0cbroker\u624d\u4f1a\u63a5\u53d7\u8be5\u6d88\u606f\u3002\u56e0\u4e3a\uff1a<\/p>\n<ol>\n<li>\u6d88\u606f\u7684seq\u6bd4broker\u7684seq\u5927\u8d85\u8fc7\u65f6\uff0c\u8bf4\u660e\u4e2d\u95f4\u6709\u6570\u636e\u8fd8\u6ca1\u5199\u5165\uff0c\u5373\u4e71\u5e8f\u4e86\u3002<\/li>\n<li>\u6d88\u606f\u7684seq\u4e0d\u6bd4broker\u7684seq\u5c0f\uff0c\u90a3\u4e48\u8bf4\u660e\u8be5\u6d88\u606f\u5df2\u88ab\u4fdd\u5b58\u3002\n<div class=\"image-package\">\n<div class=\"image-container\">\n<div class=\"image-container-fill\"><\/div>\n<div class=\"image-view\" data-width=\"496\" data-height=\"781\"><img decoding=\"async\" class=\"\" src=\"\/\/upload-images.jianshu.io\/upload_images\/2835676-6cdca2f01bdd7e4b.png?imageMogr2\/auto-orient\/strip%7CimageView2\/2\/w\/496\/format\/webp\" data-original-src=\"\/\/upload-images.jianshu.io\/upload_images\/2835676-6cdca2f01bdd7e4b.png\" data-original-width=\"496\" data-original-height=\"781\" data-original-format=\"image\/png\" data-original-filesize=\"30832\" \/><\/div>\n<\/div>\n<div class=\"image-caption\">\u89e3\u51b3\u91cd\u590d\u751f\u4ea7<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<h4>\u4e8b\u52a1\u6027\/\u539f\u5b50\u6027\u5e7f\u64ad<\/h4>\n<p>\u573a\u666f\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<ol>\n<li>\u5148\u4ece\u591a\u4e2a\u6e90topic\u4e2d\u83b7\u53d6\u6570\u636e\u3002<\/li>\n<li>\u505a\u4e1a\u52a1\u5904\u7406\uff0c\u5199\u5230\u4e0b\u6e38\u7684\u591a\u4e2a\u76ee\u7684topic\u3002<\/li>\n<li>\u66f4\u65b0\u591a\u4e2a\u6e90topic\u7684offset\u3002<\/li>\n<\/ol>\n<p>\u5176\u4e2d\u7b2c2\u30013\u70b9\u4f5c\u4e3a\u4e00\u4e2a\u4e8b\u52a1\uff0c\u8981\u4e48\u5168\u6210\u529f\uff0c\u8981\u4e48\u5168\u5931\u8d25\u3002\u8fd9\u91cc\u5f97\u76ca\u4e0eoffset\u5b9e\u9645\u4e0a\u662f\u7528\u7279\u6b8a\u7684topic\u53bb\u4fdd\u5b58\uff0c\u8fd9\u4e24\u70b9\u90fd\u5f52\u4e00\u4e3a\u5199\u591a\u4e2atopic\u7684\u4e8b\u52a1\u6027\u5904\u7406\u3002<\/p>\n<div class=\"image-package\">\n<div class=\"image-container\">\n<div class=\"image-container-fill\"><\/div>\n<div class=\"image-view\" data-width=\"864\" data-height=\"617\"><img decoding=\"async\" class=\"\" src=\"\/\/upload-images.jianshu.io\/upload_images\/2835676-cb4882e8e69cc9b8.png?imageMogr2\/auto-orient\/strip%7CimageView2\/2\/w\/864\/format\/webp\" data-original-src=\"\/\/upload-images.jianshu.io\/upload_images\/2835676-cb4882e8e69cc9b8.png\" data-original-width=\"864\" data-original-height=\"617\" data-original-format=\"image\/png\" data-original-filesize=\"34050\" \/><\/div>\n<\/div>\n<div class=\"image-caption\"><\/div>\n<\/div>\n<p>\u57fa\u672c\u601d\u8def\u662f\u8fd9\u6837\u7684\uff1a<br \/>\n\u5f15\u5165tid\uff08transaction id\uff09\uff0c\u548cpid\u4e0d\u540c\uff0c\u8fd9\u4e2aid\u662f\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u7684\uff0c\u7528\u4e8e\u6807\u8bc6\u4e8b\u52a1\uff0c\u548cproducer\u662f\u8c01\u5e76\u6ca1\u5173\u7cfb\u3002\u5c31\u662f\u4efb\u4f55producer\u90fd\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2atid\u53bb\u505a\u4e8b\u52a1\uff0c\u8fd9\u6837\u8fdb\u884c\u5230\u4e00\u534a\u5c31\u6b7b\u6389\u7684\u4e8b\u52a1\uff0c\u53ef\u4ee5\u7531\u53e6\u4e00\u4e2aproducer\u53bb\u6062\u590d\u3002<br \/>\n\u540c\u65f6\u4e3a\u4e86\u8bb0\u5f55\u4e8b\u52a1\u7684\u72b6\u6001\uff0c\u7c7b\u4f3c\u5bf9offset\u7684\u5904\u7406\uff0c\u5f15\u5165transaction coordinator\u7528\u4e8e\u8bb0\u5f55transaction log\u3002\u5728\u96c6\u7fa4\u4e2d\u4f1a\u6709\u591a\u4e2atransaction coordinator\uff0c\u6bcf\u4e2atid\u5bf9\u5e94\u552f\u4e00\u4e00\u4e2atransaction coordinator\u3002<br \/>\n\u6ce8\uff1atransaction log\u5220\u9664\u7b56\u7565\u662fcompact\uff0c\u5df2\u5b8c\u6210\u7684\u4e8b\u52a1\u4f1a\u6807\u8bb0\u6210null\uff0ccompact\u540e\u4e0d\u4fdd\u7559\u3002<\/p>\n<p>\u505a\u4e8b\u52a1\u65f6\uff0c\u5148\u6807\u8bb0\u5f00\u542f\u4e8b\u52a1\uff0c\u5199\u5165\u6570\u636e\uff0c\u5168\u90e8\u6210\u529f\u5c31\u5728transaction log\u4e2d\u8bb0\u5f55\u4e3aprepare commit\u72b6\u6001\uff0c\u5426\u5219\u5199\u5165prepare abort\u7684\u72b6\u6001\u3002\u4e4b\u540e\u518d\u53bb\u7ed9\u6bcf\u4e2a\u76f8\u5173\u7684partition\u5199\u5165\u4e00\u6761marker\uff08commit\u6216\u8005abort\uff09\u6d88\u606f\uff0c\u6807\u8bb0\u8fd9\u4e2a\u4e8b\u52a1\u7684message\u53ef\u4ee5\u88ab\u8bfb\u53d6\u6216\u5df2\u7ecf\u5e9f\u5f03\u3002\u6210\u529f\u540e\u5728transaction log\u8bb0\u5f55\u4e0bcommit\/abort\u72b6\u6001\uff0c\u81f3\u6b64\u4e8b\u52a1\u7ed3\u675f\u3002<\/p>\n<p>\u6570\u636e\u6d41\uff1a<\/p>\n<div class=\"image-package\">\n<div class=\"image-container\">\n<div class=\"image-container-fill\"><\/div>\n<div class=\"image-view\" data-width=\"720\" data-height=\"546\"><img decoding=\"async\" class=\"\" src=\"\/\/upload-images.jianshu.io\/upload_images\/2835676-3ddc2841526aeb71.png?imageMogr2\/auto-orient\/strip%7CimageView2\/2\/w\/720\/format\/webp\" data-original-src=\"\/\/upload-images.jianshu.io\/upload_images\/2835676-3ddc2841526aeb71.png\" data-original-width=\"720\" data-original-height=\"546\" data-original-format=\"image\/png\" data-original-filesize=\"29413\" \/><\/div>\n<\/div>\n<div class=\"image-caption\">Kafka Transactions Data Flow.png<\/div>\n<\/div>\n<ol>\n<li>\u9996\u5148\u4f7f\u7528tid\u8bf7\u6c42\u4efb\u610f\u4e00\u4e2abroker\uff08\u4ee3\u7801\u4e2d\u5199\u7684\u662f\u8d1f\u8f7d\u6700\u5c0f\u7684broker\uff09\uff0c\u627e\u5230\u5bf9\u5e94\u7684transaction coordinator\u3002<\/li>\n<li>\u8bf7\u6c42transaction coordinator\u83b7\u53d6\u5230\u5bf9\u5e94\u7684pid\uff0c\u548cpid\u5bf9\u5e94\u7684epoch\uff0c\u8fd9\u4e2aepoch\u7528\u4e8e\u9632\u6b62\u50f5\u6b7b\u8fdb\u7a0b\u590d\u6d3b\u5bfc\u81f4\u6d88\u606f\u9519\u4e71\uff0c\u5f53\u6d88\u606f\u7684epoch\u6bd4\u5f53\u524d\u7ef4\u62a4\u7684epoch\u5c0f\u65f6\uff0c\u62d2\u7edd\u6389\u3002tid\u548cpid\u6709\u4e00\u4e00\u5bf9\u5e94\u7684\u5173\u7cfb\uff0c\u8fd9\u6837\u5bf9\u4e8e\u540c\u4e00\u4e2atid\u4f1a\u8fd4\u56de\u76f8\u540c\u7684pid\u3002<\/li>\n<\/ol>\n<ol start=\"4\">\n<li>client\u5148\u8bf7\u6c42transaction coordinator\u8bb0\u5f55&lt;topic,partition&gt;\u7684\u4e8b\u52a1\u72b6\u6001\uff0c\u521d\u59cb\u72b6\u6001\u662fBEGIN\uff0c\u5982\u679c\u662f\u8be5\u4e8b\u52a1\u4e2d\u7b2c\u4e00\u4e2a\u5230\u8fbe\u7684&lt;topic,partition&gt;\uff0c\u540c\u65f6\u4f1a\u5bf9\u4e8b\u52a1\u8fdb\u884c\u8ba1\u65f6\uff1bclient\u8f93\u51fa\u6570\u636e\u5230\u76f8\u5173\u7684partition\u4e2d\uff1bclient\u518d\u8bf7\u6c42transaction coordinator\u8bb0\u5f55offset\u7684&lt;topic,partition&gt;\u4e8b\u52a1\u72b6\u6001\uff1bclient\u53d1\u9001offset commit\u5230\u5bf9\u5e94offset partition\u3002<\/li>\n<li>client\u53d1\u9001commit\u8bf7\u6c42\uff0ctransaction coordinator\u8bb0\u5f55prepare commit\/abort\uff0c\u7136\u540e\u53d1\u9001marker\u7ed9\u76f8\u5173\u7684partition\u3002\u5168\u90e8\u6210\u529f\u540e\uff0c\u8bb0\u5f55commit\/abort\u7684\u72b6\u6001\uff0c\u6700\u540e\u8fd9\u4e2a\u8bb0\u5f55\u4e0d\u9700\u8981\u7b49\u5f85\u5176\u4ed6replica\u7684ack\uff0c\u56e0\u4e3aprepare\u4e0d\u4e22\u5c31\u80fd\u4fdd\u8bc1\u6700\u7ec8\u7684\u6b63\u786e\u6027\u4e86\u3002<\/li>\n<\/ol>\n<p>\u8fd9\u91ccprepare\u7684\u72b6\u6001\u4e3b\u8981\u662f\u7528\u4e8e\u4e8b\u52a1\u6062\u590d\uff0c\u4f8b\u5982\u7ed9\u76f8\u5173\u7684partition\u53d1\u9001\u63a7\u5236\u6d88\u606f\uff0c\u6ca1\u53d1\u5b8c\u5c31\u5b95\u673a\u4e86\uff0c\u5907\u673a\u8d77\u6765\u540e\uff0cproducer\u53d1\u9001\u8bf7\u6c42\u83b7\u53d6pid\u65f6\uff0c\u4f1a\u628a\u672a\u5b8c\u6210\u7684\u4e8b\u52a1\u63a5\u7740\u5b8c\u6210\u3002<\/p>\n<p>\u5f53partition\u4e2d\u5199\u5165commit\u7684marker\u540e\uff0c\u76f8\u5173\u7684\u6d88\u606f\u5c31\u53ef\u88ab\u8bfb\u53d6\u3002\u6240\u4ee5kafka\u4e8b\u52a1\u5728prepare commit\u5230commit\u8fd9\u4e2a\u65f6\u95f4\u6bb5\u5185\uff0c\u6d88\u606f\u662f\u9010\u6e10\u53ef\u89c1\u7684\uff0c\u800c\u4e0d\u662f\u540c\u4e00\u65f6\u523b\u53ef\u89c1\u3002<\/p>\n<p>\u8be6\u7ec6\u7ec6\u8282\u53ef\u770b\uff1a<a href=\"https:\/\/link.jianshu.com?t=https%3A%2F%2Fcwiki.apache.org%2Fconfluence%2Fdisplay%2FKAFKA%2FKIP-98%2B-%2BExactly%2BOnce%2BDelivery%2Band%2BTransactional%2BMessaging%23KIP-98-ExactlyOnceDeliveryandTransactionalMessaging-TransactionalGuarantees\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/cwiki.apache.org\/confluence\/display\/KAFKA\/KIP-98+-+Exactly+Once+Delivery+and+Transactional+Messaging#KIP-98-ExactlyOnceDeliveryandTransactionalMessaging-TransactionalGuarantees<\/a><\/p>\n<h4>\u6d88\u8d39\u4e8b\u52a1<\/h4>\n<p>\u524d\u9762\u90fd\u662f\u4ece\u751f\u4ea7\u7684\u89d2\u5ea6\u770b\u5f85\u4e8b\u52a1\u3002\u8fd8\u9700\u8981\u4ece\u6d88\u8d39\u7684\u89d2\u5ea6\u53bb\u8003\u8651\u4e00\u4e9b\u95ee\u9898\u3002<br \/>\n\u6d88\u8d39\u65f6\uff0cpartition\u4e2d\u4f1a\u5b58\u5728\u4e00\u4e9b\u6d88\u606f\u5904\u4e8e\u672acommit\u72b6\u6001\uff0c\u5373\u4e1a\u52a1\u65b9\u5e94\u8be5\u770b\u4e0d\u5230\u7684\u6d88\u606f\uff0c\u9700\u8981\u8fc7\u6ee4\u8fd9\u4e9b\u6d88\u606f\u4e0d\u8ba9\u4e1a\u52a1\u770b\u5230\uff0ckafka\u9009\u62e9\u5728\u6d88\u8d39\u8005\u8fdb\u7a0b\u4e2d\u8fdb\u884c\u8fc7\u6765\uff0c\u800c\u4e0d\u662f\u5728broker\u4e2d\u8fc7\u6ee4\uff0c\u4e3b\u8981\u8003\u8651\u7684\u8fd8\u662f\u6027\u80fd\u3002kafka\u9ad8\u6027\u80fd\u7684\u4e00\u4e2a\u5173\u952e\u70b9\u662fzero copy\uff0c\u5982\u679c\u9700\u8981\u5728broker\u4e2d\u8fc7\u6ee4\uff0c\u90a3\u4e48\u52bf\u5fc5\u9700\u8981\u8bfb\u53d6\u6d88\u606f\u5185\u5bb9\u5230\u5185\u5b58\uff0c\u5c31\u4f1a\u5931\u53bbzero copy\u7684\u7279\u6027\u3002<\/p>\n<hr \/>\n<h2>\u6587\u4ef6\u7ec4\u7ec7<\/h2>\n<p>kafka\u7684\u6570\u636e\uff0c\u5b9e\u9645\u4e0a\u662f\u4ee5\u6587\u4ef6\u7684\u5f62\u5f0f\u5b58\u50a8\u5728\u6587\u4ef6\u7cfb\u7edf\u7684\u3002topic\u4e0b\u6709partition\uff0cpartition\u4e0b\u6709segment\uff0csegment\u662f\u5b9e\u9645\u7684\u4e00\u4e2a\u4e2a\u6587\u4ef6\uff0ctopic\u548cpartition\u90fd\u662f\u62bd\u8c61\u6982\u5ff5\u3002<\/p>\n<p>\u5728\u76ee\u5f55\/${topicName}-{$partitionid}\/\u4e0b\uff0c\u5b58\u50a8\u7740\u5b9e\u9645\u7684log\u6587\u4ef6\uff08\u5373segment\uff09\uff0c\u8fd8\u6709\u5bf9\u5e94\u7684\u7d22\u5f15\u6587\u4ef6\u3002<\/p>\n<p>\u6bcf\u4e2asegment\u6587\u4ef6\u5927\u5c0f\u76f8\u7b49\uff0c\u6587\u4ef6\u540d\u4ee5\u8fd9\u4e2asegment\u4e2d\u6700\u5c0f\u7684offset\u547d\u540d\uff0c\u6587\u4ef6\u6269\u5c55\u540d\u662f.log\uff1bsegment\u5bf9\u5e94\u7684\u7d22\u5f15\u7684\u6587\u4ef6\u540d\u5b57\u4e00\u6837\uff0c\u6269\u5c55\u540d\u662f.index\u3002\u6709\u4e24\u4e2aindex\u6587\u4ef6\uff0c\u4e00\u4e2a\u662foffset index\u7528\u4e8e\u6309offset\u53bb\u67e5message\uff0c\u4e00\u4e2a\u662ftime index\u7528\u4e8e\u6309\u7167\u65f6\u95f4\u53bb\u67e5\uff0c\u5176\u5b9e\u8fd9\u91cc\u53ef\u4ee5\u4f18\u5316\u5408\u5230\u4e00\u8d77\uff0c\u4e0b\u9762\u53ea\u8bf4offset index\u3002\u603b\u4f53\u7684\u7ec4\u7ec7\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<div class=\"image-package\">\n<div class=\"image-container\">\n<div class=\"image-container-fill\"><\/div>\n<div class=\"image-view\" data-width=\"1560\" data-height=\"1269\"><img decoding=\"async\" class=\"\" src=\"\/\/upload-images.jianshu.io\/upload_images\/2835676-3d067d57adff7834.png?imageMogr2\/auto-orient\/strip%7CimageView2\/2\/w\/1000\/format\/webp\" data-original-src=\"\/\/upload-images.jianshu.io\/upload_images\/2835676-3d067d57adff7834.png\" data-original-width=\"1560\" data-original-height=\"1269\" data-original-format=\"image\/png\" data-original-filesize=\"123465\" \/><\/div>\n<\/div>\n<div class=\"image-caption\">kafka \u6587\u4ef6\u7ec4\u7ec7.png<\/div>\n<\/div>\n<p>\u4e3a\u4e86\u51cf\u5c11\u7d22\u5f15\u6587\u4ef6\u7684\u5927\u5c0f\uff0c\u964d\u4f4e\u7a7a\u95f4\u4f7f\u7528\uff0c\u65b9\u4fbf\u76f4\u63a5\u52a0\u8f7d\u8fdb\u5185\u5b58\u4e2d\uff0c\u8fd9\u91cc\u7684\u7d22\u5f15\u4f7f\u7528\u7a00\u758f\u77e9\u9635\uff0c\u4e0d\u4f1a\u6bcf\u4e00\u4e2amessage\u90fd\u8bb0\u5f55\u4e0b\u5177\u4f53\u4f4d\u7f6e\uff0c\u800c\u662f\u6bcf\u9694\u4e00\u5b9a\u7684\u5b57\u8282\u6570\uff0c\u518d\u5efa\u7acb\u4e00\u6761\u7d22\u5f15\u3002 \u7d22\u5f15\u5305\u542b\u4e24\u90e8\u5206\uff0c\u5206\u522b\u662fbaseOffset\uff0c\u8fd8\u6709position\u3002<\/p>\n<p>baseOffset\uff1a\u610f\u601d\u662f\u8fd9\u6761\u7d22\u5f15\u5bf9\u5e94segment\u6587\u4ef6\u4e2d\u7684\u7b2c\u51e0\u6761message\u3002\u8fd9\u6837\u505a\u65b9\u4fbf\u4f7f\u7528\u6570\u503c\u538b\u7f29\u7b97\u6cd5\u6765\u8282\u7701\u7a7a\u95f4\u3002\u4f8b\u5982kafka\u4f7f\u7528\u7684\u662fvarint\u3002<\/p>\n<p>position\uff1a\u5728segment\u4e2d\u7684\u7edd\u5bf9\u4f4d\u7f6e\u3002<\/p>\n<p>\u67e5\u627eoffset\u5bf9\u5e94\u7684\u8bb0\u5f55\u65f6\uff0c\u4f1a\u5148\u7528\u4e8c\u5206\u6cd5\uff0c\u627e\u51fa\u5bf9\u5e94\u7684offset\u5728\u54ea\u4e2asegment\u4e2d\uff0c\u7136\u540e\u4f7f\u7528\u7d22\u5f15\uff0c\u5728\u5b9a\u4f4d\u51faoffset\u5728segment\u4e2d\u7684\u5927\u6982\u4f4d\u7f6e\uff0c\u518d\u904d\u5386\u67e5\u627emessage\u3002<\/p>\n<hr \/>\n<h2>\u5e38\u7528\u914d\u7f6e\u9879<\/h2>\n<h3>broker\u914d\u7f6e<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u914d\u7f6e\u9879<\/th>\n<th>\u4f5c\u7528<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>broker.id<\/td>\n<td>broker\u7684\u552f\u4e00\u6807\u8bc6<\/td>\n<\/tr>\n<tr>\n<td>auto.create.topics.auto<\/td>\n<td>\u8bbe\u7f6e\u6210true\uff0c\u5c31\u662f\u9047\u5230\u6ca1\u6709\u7684topic\u81ea\u52a8\u521b\u5efatopic\u3002<\/td>\n<\/tr>\n<tr>\n<td>log.dirs<\/td>\n<td>log\u7684\u76ee\u5f55\u6570\uff0c\u76ee\u5f55\u91cc\u9762\u653epartition\uff0c\u5f53\u751f\u6210\u65b0\u7684partition\u65f6\uff0c\u4f1a\u6311\u76ee\u5f55\u91ccpartition\u6570\u6700\u5c11\u7684\u76ee\u5f55\u653e\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>topic\u914d\u7f6e<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u914d\u7f6e\u9879<\/th>\n<th>\u4f5c\u7528<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>num.partitions<\/td>\n<td>\u65b0\u5efa\u4e00\u4e2atopic\uff0c\u4f1a\u6709\u51e0\u4e2apartition\u3002<\/td>\n<\/tr>\n<tr>\n<td>log.retention.ms<\/td>\n<td>\u5bf9\u5e94\u7684\u8fd8\u6709minutes\uff0chours\u7684\u5355\u4f4d\u3002\u65e5\u5fd7\u4fdd\u7559\u65f6\u95f4\uff0c\u56e0\u4e3a\u5220\u9664\u662f\u6587\u4ef6\u7ef4\u5ea6\u800c\u4e0d\u662f\u6d88\u606f\u7ef4\u5ea6\uff0c\u770b\u7684\u662f\u65e5\u5fd7\u6587\u4ef6\u7684mtime\u3002<\/td>\n<\/tr>\n<tr>\n<td>log.retention.bytes<\/td>\n<td>partion\u6700\u5927\u7684\u5bb9\u91cf\uff0c\u8d85\u8fc7\u5c31\u6e05\u7406\u8001\u7684\u3002\u6ce8\u610f\u8fd9\u4e2a\u662fpartion\u7ef4\u5ea6\uff0c\u5c31\u662f\u8bf4\u5982\u679c\u4f60\u7684topic\u67098\u4e2apartition\uff0c\u914d\u7f6e1G\uff0c\u90a3\u4e48\u5e73\u5747\u5206\u914d\u4e0b\uff0ctopic\u7406\u8bba\u6700\u5927\u503c8G\u3002<\/td>\n<\/tr>\n<tr>\n<td>log.segment.bytes<\/td>\n<td>\u4e00\u4e2asegment\u7684\u5927\u5c0f\u3002\u8d85\u8fc7\u4e86\u5c31\u6eda\u52a8\u3002<\/td>\n<\/tr>\n<tr>\n<td>log.segment.ms<\/td>\n<td>\u4e00\u4e2asegment\u7684\u6253\u5f00\u65f6\u95f4\uff0c\u8d85\u8fc7\u4e86\u5c31\u6eda\u52a8\u3002<\/td>\n<\/tr>\n<tr>\n<td>message.max.bytes<\/td>\n<td>message\u6700\u5927\u591a\u5927<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5173\u4e8e\u65e5\u5fd7\u6e05\u7406\uff0c\u9ed8\u8ba4\u5f53\u524d\u6b63\u5728\u5199\u7684\u65e5\u5fd7\uff0c\u662f\u600e\u4e48\u4e5f\u4e0d\u4f1a\u6e05\u7406\u6389\u7684\u3002<br \/>\n\u8fd8\u67090.10\u4e4b\u524d\u7684\u7248\u672c\uff0c\u65f6\u95f4\u770b\u7684\u662f\u65e5\u5fd7\u6587\u4ef6\u7684mtime\uff0c\u4f46\u8fd9\u4e2a\u6307\u662f\u4e0d\u51c6\u786e\u7684\uff0c\u6709\u53ef\u80fd\u6587\u4ef6\u88abtouch\u4e00\u4e0b\uff0cmtime\u5c31\u53d8\u4e86\u3002\u56e0\u6b64\u57280.10\u7248\u672c\u5f00\u59cb\uff0c\u6539\u4e3a\u4f7f\u7528\u8be5\u6587\u4ef6\u6700\u65b0\u4e00\u6761\u6d88\u606f\u7684\u65f6\u95f4\u6765\u5224\u65ad\u3002<br \/>\n\u6309\u5927\u5c0f\u6e05\u7406\u8fd9\u91cc\u4e5f\u8981\u6ce8\u610f\uff0cKafka\u5728\u5b9a\u65f6\u4efb\u52a1\u4e2d\u5c1d\u8bd5\u6bd4\u8f83\u5f53\u524d\u65e5\u5fd7\u91cf\u603b\u5927\u5c0f\u662f\u5426\u8d85\u8fc7\u9608\u503c\u81f3\u5c11\u4e00\u4e2a\u65e5\u5fd7\u6bb5\u7684\u5927\u5c0f\u3002\u5982\u679c\u8d85\u8fc7\u4f46\u662f\u6ca1\u8d85\u8fc7\u4e00\u4e2a\u65e5\u5fd7\u6bb5\uff0c\u90a3\u4e48\u5c31\u4e0d\u4f1a\u5220\u9664\u3002<\/p>\n<\/div>\n<p>\u4f5c\u8005\uff1a123archu<br \/>\n\u94fe\u63a5\uff1ahttps:\/\/www.jianshu.com\/p\/d3e963ff8b70<br \/>\n\u4f86\u6e90\uff1a\u7b80\u4e66<br \/>\n\u7b80\u4e66\u8457\u4f5c\u6743\u5f52\u4f5c\u8005\u6240\u6709\uff0c\u4efb\u4f55\u5f62\u5f0f\u7684\u8f6c\u8f7d\u90fd\u8bf7\u8054\u7cfb\u4f5c\u8005\u83b7\u5f97\u6388\u6743\u5e76\u6ce8\u660e\u51fa\u5904\u3002<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u4ecb kafka\u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u6d88\u606f\u961f\u5217\u3002\u5177\u6709\u9ad8\u6027\u80fd\u3001\u6301\u4e45\u5316\u3001\u591a\u526f\u672c\u5907\u4efd\u3001\u6a2a\u5411\u6269\u5c55\u80fd\u529b\u3002\u751f\u4ea7\u8005\u5f80\u961f\u5217\u91cc\u5199\u6d88\u606f\uff0c\u6d88\u8d39\u8005\u4ece\u961f\u5217\u91cc\u53d6\u6d88\u606f\u8fdb\u884c\u4e1a\u52a1\u903b\u8f91\u3002\u4e00\u822c\u5728\u67b6\u6784\u8bbe\u8ba1\u4e2d\u8d77\u5230\u89e3\u8026\u3001\u524a\u5cf0\u3001\u5f02\u6b65\u5904\u7406\u7684\u4f5c\u7528\u3002 kafka\u5bf9\u5916\u4f7f\u7528topic\u7684\u6982\u5ff5\uff0c\u751f\u4ea7\u8005\u5f80topic\u91cc\u5199\u6d88\u606f\uff0c\u6d88\u8d39\u8005\u4ece\u8bfb\u6d88\u606f\u3002\u4e3a\u4e86\u505a\u5230\u6c34\u5e73\u6269\u5c55\uff0c\u4e00\u4e2atopic\u5b9e\u9645\u662f\u7531\u591a\u4e2apartition\u7ec4\u6210\u7684\uff0c\u9047\u5230\u74f6\u9888\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u589e\u52a0partition\u7684\u6570\u91cf\u6765\u8fdb\u884c\u6a2a\u5411\u6269\u5bb9\u3002\u5355\u4e2aparition\u5185\u662f\u4fdd\u8bc1\u6d88\u606f\u6709\u5e8f\u3002 \u6bcf\u65b0\u5199\u4e00\u6761\u6d88\u606f\uff0ckafka\u5c31\u662f\u5728\u5bf9\u5e94\u7684\u6587\u4ef6append\u5199\uff0c\u6240\u4ee5\u6027\u80fd\u975e\u5e38\u9ad8\u3002 kafka\u7684\u603b\u4f53\u6570\u636e\u6d41\u662f\u8fd9\u6837\u7684\uff1a kafka data flow \u5927\u6982\u7528\u6cd5\u5c31\u662f\uff0cProducers\u5f80Brokers\u91cc\u9762\u7684\u6307\u5b9aTopic\u4e2d\u5199\u6d88\u606f\uff0cConsumers\u4eceBrokers\u91cc\u9762\u62c9\u53bb\u6307\u5b9aTopic\u7684\u6d88\u606f\uff0c\u7136\u540e\u8fdb\u884c\u4e1a\u52a1\u5904\u7406\u3002 \u56fe\u4e2d\u6709\u4e24\u4e2atopic\uff0ctopic 0\u6709\u4e24\u4e2apartition\uff0ctopic 1\u6709\u4e00\u4e2apartition\uff0c\u4e09\u526f\u672c\u5907\u4efd\u3002\u53ef\u4ee5\u770b\u5230consumer gourp 1\u4e2d\u7684consumer 2\u6ca1\u6709\u5206\u5230partition\u5904\u7406\uff0c\u8fd9\u662f\u6709\u53ef\u80fd\u51fa\u73b0\u7684\uff0c\u4e0b\u9762\u4f1a\u8bb2\u5230\u3002 \u5173\u4e8ebroker\u3001topics\u3001partitions\u7684\u4e00\u4e9b\u5143\u4fe1\u606f\u7528zk\u6765\u5b58\uff0c\u76d1\u63a7\u548c\u8def\u7531\u5565\u7684\u4e5f\u90fd\u4f1a\u7528\u5230zk\u3002 \u751f\u4ea7 \u57fa\u672c\u6d41\u7a0b\u662f\u8fd9\u6837\u7684\uff1a kafka sdk [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1116","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/1116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1116"}],"version-history":[{"count":0,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/1116\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}