﻿{"id":596,"date":"2018-08-25T13:55:32","date_gmt":"2018-08-25T05:55:32","guid":{"rendered":"https:\/\/www.chenweikang.top\/?p=596"},"modified":"2018-08-25T13:55:32","modified_gmt":"2018-08-25T05:55:32","slug":"kafka%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0%ef%bc%9a%e7%9f%a5%e8%af%86%e7%82%b9%e6%95%b4%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.chenweikang.top\/?p=596","title":{"rendered":"kafka\u5b66\u4e60\u7b14\u8bb0\uff1a\u77e5\u8bc6\u70b9\u6574\u7406"},"content":{"rendered":"<div id=\"cnblogs_post_body\" class=\"blogpost-body\">\n<h2><strong>\u4e00\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u6d88\u606f\u7cfb\u7edf<\/strong><\/h2>\n<div class=\"cnblogs_code\">\n<pre><strong>1.\u89e3\u8026\uff1a\r\n<\/strong>\u3000\u3000\u5141\u8bb8\u4f60\u72ec\u7acb\u7684\u6269\u5c55\u6216\u4fee\u6539\u4e24\u8fb9\u7684\u5904\u7406\u8fc7\u7a0b\uff0c\u53ea\u8981\u786e\u4fdd\u5b83\u4eec\u9075\u5b88\u540c\u6837\u7684\u63a5\u53e3\u7ea6\u675f\u3002\r\n<strong>2.\u5197\u4f59\uff1a<\/strong>\r\n\u3000\u3000\u6d88\u606f\u961f\u5217\u628a\u6570\u636e\u8fdb\u884c\u6301\u4e45\u5316\u76f4\u5230\u5b83\u4eec\u5df2\u7ecf\u88ab\u5b8c\u5168\u5904\u7406\uff0c\u901a\u8fc7\u8fd9\u4e00\u65b9\u5f0f\u89c4\u907f\u4e86\u6570\u636e\u4e22\u5931\u98ce\u9669\u3002\u8bb8\u591a\u6d88\u606f\u961f\u5217\u6240\u91c7\u7528\u7684\"\u63d2\u5165-\u83b7\u53d6-\u5220\u9664\"\u8303\u5f0f\u4e2d\uff0c\u5728\u628a\u4e00\u4e2a\u6d88\u606f\u4ece\u961f\u5217\u4e2d\u5220\u9664\u4e4b\u524d\uff0c\u9700\u8981\u4f60\u7684\u5904\u7406\u7cfb\u7edf\u660e\u786e\u7684\u6307\u51fa\u8be5\u6d88\u606f\u5df2\u7ecf\u88ab\u5904\u7406\u5b8c\u6bd5\uff0c\u4ece\u800c\u786e\u4fdd\u4f60\u7684\u6570\u636e\u88ab\u5b89\u5168\u7684\u4fdd\u5b58\u76f4\u5230\u4f60\u4f7f\u7528\u5b8c\u6bd5\u3002\r\n<strong>3.\u6269\u5c55\u6027\uff1a<\/strong>\r\n\u3000\u3000\u56e0\u4e3a\u6d88\u606f\u961f\u5217\u89e3\u8026\u4e86\u4f60\u7684\u5904\u7406\u8fc7\u7a0b\uff0c\u6240\u4ee5\u589e\u5927\u6d88\u606f\u5165\u961f\u548c\u5904\u7406\u7684\u9891\u7387\u662f\u5f88\u5bb9\u6613\u7684\uff0c\u53ea\u8981\u53e6\u5916\u589e\u52a0\u5904\u7406\u8fc7\u7a0b\u5373\u53ef\u3002\r\n<strong>4.\u7075\u6d3b\u6027 &amp; \u5cf0\u503c\u5904\u7406\u80fd\u529b\uff1a<\/strong>\r\n\u3000\u3000\u5728\u8bbf\u95ee\u91cf\u5267\u589e\u7684\u60c5\u51b5\u4e0b\uff0c\u5e94\u7528\u4ecd\u7136\u9700\u8981\u7ee7\u7eed\u53d1\u6325\u4f5c\u7528\uff0c\u4f46\u662f\u8fd9\u6837\u7684\u7a81\u53d1\u6d41\u91cf\u5e76\u4e0d\u5e38\u89c1\u3002\u5982\u679c\u4e3a\u4ee5\u80fd\u5904\u7406\u8fd9\u7c7b\u5cf0\u503c\u8bbf\u95ee\u4e3a\u6807\u51c6\u6765\u6295\u5165\u8d44\u6e90\u968f\u65f6\u5f85\u547d\u65e0\u7591\u662f\u5de8\u5927\u7684\u6d6a\u8d39\u3002\u4f7f\u7528\u6d88\u606f\u961f\u5217\u80fd\u591f\u4f7f\u5173\u952e\u7ec4\u4ef6\u9876\u4f4f\u7a81\u53d1\u7684\u8bbf\u95ee\u538b\u529b\uff0c\u800c\u4e0d\u4f1a\u56e0\u4e3a\u7a81\u53d1\u7684\u8d85\u8d1f\u8377\u7684\u8bf7\u6c42\u800c\u5b8c\u5168\u5d29\u6e83\u3002\r\n<strong>5.\u53ef\u6062\u590d\u6027\uff1a<\/strong>\r\n\u3000\u3000\u7cfb\u7edf\u7684\u4e00\u90e8\u5206\u7ec4\u4ef6\u5931\u6548\u65f6\uff0c\u4e0d\u4f1a\u5f71\u54cd\u5230\u6574\u4e2a\u7cfb\u7edf\u3002\u6d88\u606f\u961f\u5217\u964d\u4f4e\u4e86\u8fdb\u7a0b\u95f4\u7684\u8026\u5408\u5ea6\uff0c\u6240\u4ee5\u5373\u4f7f\u4e00\u4e2a\u5904\u7406\u6d88\u606f\u7684\u8fdb\u7a0b\u6302\u6389\uff0c\u52a0\u5165\u961f\u5217\u4e2d\u7684\u6d88\u606f\u4ecd\u7136\u53ef\u4ee5\u5728\u7cfb\u7edf\u6062\u590d\u540e\u88ab\u5904\u7406\u3002\r\n<strong>6.\u987a\u5e8f\u4fdd\u8bc1\uff1a<\/strong>\r\n\u3000\u3000\u5728\u5927\u591a\u4f7f\u7528\u573a\u666f\u4e0b\uff0c\u6570\u636e\u5904\u7406\u7684\u987a\u5e8f\u90fd\u5f88\u91cd\u8981\u3002\u5927\u90e8\u5206\u6d88\u606f\u961f\u5217\u672c\u6765\u5c31\u662f\u6392\u5e8f\u7684\uff0c\u5e76\u4e14\u80fd\u4fdd\u8bc1\u6570\u636e\u4f1a\u6309\u7167\u7279\u5b9a\u7684\u987a\u5e8f\u6765\u5904\u7406\u3002\uff08Kafka \u4fdd\u8bc1\u4e00\u4e2a Partition \u5185\u7684\u6d88\u606f\u7684\u6709\u5e8f\u6027\uff09\r\n<strong>7.\u7f13\u51b2\uff1a<\/strong>\r\n\u3000\u3000\u6709\u52a9\u4e8e\u63a7\u5236\u548c\u4f18\u5316\u6570\u636e\u6d41\u7ecf\u8fc7\u7cfb\u7edf\u7684\u901f\u5ea6\uff0c\u89e3\u51b3\u751f\u4ea7\u6d88\u606f\u548c\u6d88\u8d39\u6d88\u606f\u7684\u5904\u7406\u901f\u5ea6\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\u3002\r\n<strong>8.\u5f02\u6b65\u901a\u4fe1\uff1a<\/strong>\r\n\u3000\u3000\u5f88\u591a\u65f6\u5019\uff0c\u7528\u6237\u4e0d\u60f3\u4e5f\u4e0d\u9700\u8981\u7acb\u5373\u5904\u7406\u6d88\u606f\u3002\u6d88\u606f\u961f\u5217\u63d0\u4f9b\u4e86\u5f02\u6b65\u5904\u7406\u673a\u5236\uff0c\u5141\u8bb8\u7528\u6237\u628a\u4e00\u4e2a\u6d88\u606f\u653e\u5165\u961f\u5217\uff0c\u4f46\u5e76\u4e0d\u7acb\u5373\u5904\u7406\u5b83\u3002\u60f3\u5411\u961f\u5217\u4e2d\u653e\u5165\u591a\u5c11\u6d88\u606f\u5c31\u653e\u591a\u5c11\uff0c\u7136\u540e\u5728\u9700\u8981\u7684\u65f6\u5019\u518d\u53bb\u5904\u7406\u5b83\u4eec\u3002<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<h2><strong>\u4e8c\u3001kafka \u67b6\u6784<\/strong><\/h2>\n<h3><strong>2.1 \u62d3\u6251\u7ed3\u6784<\/strong><\/h3>\n<p>\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/897247\/201610\/897247-20161012133845281-1066342716.png\" alt=\"\" \/><\/p>\n<p>\u56fe.1<\/p>\n<h3><strong>2.2 \u76f8\u5173\u6982\u5ff5<\/strong><\/h3>\n<p>\u5982\u56fe.1\u4e2d\uff0ckafka \u76f8\u5173\u540d\u8bcd\u89e3\u91ca\u5982\u4e0b\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre><strong>1.producer\uff1a<\/strong>\r\n\u3000\u3000\u6d88\u606f\u751f\u4ea7\u8005\uff0c\u53d1\u5e03\u6d88\u606f\u5230 kafka \u96c6\u7fa4\u7684\u7ec8\u7aef\u6216\u670d\u52a1\u3002\r\n<strong>2.broker\uff1a<\/strong>\r\n\u3000\u3000kafka \u96c6\u7fa4\u4e2d\u5305\u542b\u7684\u670d\u52a1\u5668\u3002\r\n<strong>3.topic\uff1a<\/strong>\r\n\u3000\u3000\u6bcf\u6761\u53d1\u5e03\u5230 kafka \u96c6\u7fa4\u7684\u6d88\u606f\u5c5e\u4e8e\u7684\u7c7b\u522b\uff0c\u5373 kafka \u662f\u9762\u5411 topic \u7684\u3002\r\n<strong>4.partition\uff1a<\/strong>\r\n\u3000\u3000partition \u662f\u7269\u7406\u4e0a\u7684\u6982\u5ff5\uff0c\u6bcf\u4e2a topic \u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a partition\u3002kafka \u5206\u914d\u7684\u5355\u4f4d\u662f partition\u3002\r\n<strong>5.consumer\uff1a<\/strong>\r\n\u3000\u3000\u4ece kafka \u96c6\u7fa4\u4e2d\u6d88\u8d39\u6d88\u606f\u7684\u7ec8\u7aef\u6216\u670d\u52a1\u3002\r\n<strong>6.Consumer group\uff1a<\/strong>\r\n\u3000\u3000high-level consumer API \u4e2d\uff0c\u6bcf\u4e2a consumer \u90fd\u5c5e\u4e8e\u4e00\u4e2a consumer group\uff0c\u6bcf\u6761\u6d88\u606f\u53ea\u80fd\u88ab consumer group \u4e2d\u7684\u4e00\u4e2a Consumer \u6d88\u8d39\uff0c\u4f46\u53ef\u4ee5\u88ab\u591a\u4e2a consumer group \u6d88\u8d39\u3002\r\n<strong>7.replica\uff1a<\/strong>\r\n\u3000\u3000partition \u7684\u526f\u672c\uff0c\u4fdd\u969c partition \u7684\u9ad8\u53ef\u7528\u3002\r\n<strong>8.leader\uff1a<\/strong>\r\n\u3000\u3000replica \u4e2d\u7684\u4e00\u4e2a\u89d2\u8272\uff0c producer \u548c consumer \u53ea\u8ddf leader \u4ea4\u4e92\u3002\r\n<strong>9.follower\uff1a<\/strong>\r\n\u3000\u3000replica \u4e2d\u7684\u4e00\u4e2a\u89d2\u8272\uff0c\u4ece leader \u4e2d\u590d\u5236\u6570\u636e\u3002\r\n<strong>10.controller\uff1a<\/strong>\r\n\u3000\u3000kafka \u96c6\u7fa4\u4e2d\u7684\u5176\u4e2d\u4e00\u4e2a\u670d\u52a1\u5668\uff0c\u7528\u6765\u8fdb\u884c leader election \u4ee5\u53ca \u5404\u79cd failover\u3002\r\n<strong>12.zookeeper\uff1a<\/strong>\r\n\u3000\u3000kafka \u901a\u8fc7 zookeeper \u6765\u5b58\u50a8\u96c6\u7fa4\u7684 meta \u4fe1\u606f\u3002<\/pre>\n<\/div>\n<h3><strong>2.3 zookeeper \u8282\u70b9<\/strong><\/h3>\n<p>kafka \u5728 zookeeper \u4e2d\u7684\u5b58\u50a8\u7ed3\u6784\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/897247\/201610\/897247-20161012133618468-2107696384.png\" alt=\"\" \/><\/p>\n<p>\u56fe.2<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>\u4e09\u3001producer \u53d1\u5e03\u6d88\u606f<\/strong><\/h2>\n<h3><strong>3.1 \u5199\u5165\u65b9\u5f0f<\/strong><\/h3>\n<p>producer \u91c7\u7528 push \u6a21\u5f0f\u5c06\u6d88\u606f\u53d1\u5e03\u5230 broker\uff0c\u6bcf\u6761\u6d88\u606f\u90fd\u88ab append \u5230 patition \u4e2d\uff0c\u5c5e\u4e8e\u987a\u5e8f\u5199\u78c1\u76d8\uff08\u987a\u5e8f\u5199\u78c1\u76d8\u6548\u7387\u6bd4\u968f\u673a\u5199\u5185\u5b58\u8981\u9ad8\uff0c\u4fdd\u969c kafka \u541e\u5410\u7387\uff09\u3002<\/p>\n<h3><strong>3.2 \u6d88\u606f\u8def\u7531<\/strong><\/h3>\n<p>producer \u53d1\u9001\u6d88\u606f\u5230 broker \u65f6\uff0c\u4f1a\u6839\u636e\u5206\u533a\u7b97\u6cd5\u9009\u62e9\u5c06\u5176\u5b58\u50a8\u5230\u54ea\u4e00\u4e2a partition\u3002\u5176\u8def\u7531\u673a\u5236\u4e3a\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. \u6307\u5b9a\u4e86 patition\uff0c\u5219\u76f4\u63a5\u4f7f\u7528\uff1b\r\n\r\n2. \u672a\u6307\u5b9a patition \u4f46\u6307\u5b9a key\uff0c\u901a\u8fc7\u5bf9 key \u7684 value \u8fdb\u884chash \u9009\u51fa\u4e00\u4e2a patition\r\n\r\n3. patition \u548c key \u90fd\u672a\u6307\u5b9a\uff0c\u4f7f\u7528\u8f6e\u8be2\u9009\u51fa\u4e00\u4e2a patition\u3002<\/pre>\n<\/div>\n<p>\u9644\u4e0a java \u5ba2\u6237\u7aef\u5206\u533a\u6e90\u7801\uff0c\u4e00\u76ee\u4e86\u7136\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>\/\/\u521b\u5efa\u6d88\u606f\u5b9e\u4f8b\r\npublic ProducerRecord(String topic, Integer partition, Long timestamp, K key, V value) {\r\n     if (topic == null)\r\n          throw new IllegalArgumentException(\"Topic cannot be null\");\r\n     if (timestamp != null &amp;&amp; timestamp &lt; 0)\r\n          throw new IllegalArgumentException(\"Invalid timestamp \" + timestamp);\r\n     this.topic = topic;\r\n     this.partition = partition;\r\n     this.key = key;\r\n     this.value = value;\r\n     this.timestamp = timestamp;\r\n}\r\n\r\n\/\/\u8ba1\u7b97 patition\uff0c\u5982\u679c\u6307\u5b9a\u4e86 patition \u5219\u76f4\u63a5\u4f7f\u7528\uff0c\u5426\u5219\u4f7f\u7528 key \u8ba1\u7b97\r\nprivate int partition(ProducerRecord&lt;K, V&gt; record, byte[] serializedKey , byte[] serializedValue, Cluster cluster) {\r\n     Integer partition = record.partition();\r\n     if (partition != null) {\r\n          List&lt;PartitionInfo&gt; partitions = cluster.partitionsForTopic(record.topic());\r\n          int lastPartition = partitions.size() - 1;\r\n          if (partition &lt; 0 || partition &gt; lastPartition) {\r\n               throw new IllegalArgumentException(String.format(\"Invalid partition given with record: %d is not in the range [0...%d].\", partition, lastPartition));\r\n          }\r\n          return partition;\r\n     }\r\n     return this.partitioner.partition(record.topic(), record.key(), serializedKey, record.value(), serializedValue, cluster);\r\n}\r\n\r\n\/\/ \u4f7f\u7528 key \u9009\u53d6 patition\r\npublic int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {\r\n     List&lt;PartitionInfo&gt; partitions = cluster.partitionsForTopic(topic);\r\n     int numPartitions = partitions.size();\r\n     if (keyBytes == null) {\r\n          int nextValue = counter.getAndIncrement();\r\n          List&lt;PartitionInfo&gt; availablePartitions = cluster.availablePartitionsForTopic(topic);\r\n          if (availablePartitions.size() &gt; 0) {\r\n               int part = DefaultPartitioner.toPositive(nextValue) % availablePartitions.size();\r\n               return availablePartitions.get(part).partition();\r\n          } else {\r\n               return DefaultPartitioner.toPositive(nextValue) % numPartitions;\r\n          }\r\n     } else {\r\n          \/\/\u5bf9 keyBytes \u8fdb\u884c hash \u9009\u51fa\u4e00\u4e2a patition\r\n          return DefaultPartitioner.toPositive(Utils.murmur2(keyBytes)) % numPartitions;\r\n     }\r\n}<\/pre>\n<div class=\"cnblogs_code_toolbar\"><\/div>\n<\/div>\n<h3><strong>3.3 \u5199\u5165\u6d41\u7a0b<\/strong><\/h3>\n<p>producer \u5199\u5165\u6d88\u606f\u5e8f\u5217\u56fe\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/897247\/201610\/897247-20161012131406546-202763949.png\" alt=\"\" \/><\/p>\n<p>\u56fe.3<\/p>\n<p>\u6d41\u7a0b\u8bf4\u660e\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. producer \u5148\u4ece zookeeper \u7684 \"\/brokers\/...\/state\" \u8282\u70b9\u627e\u5230\u8be5 partition \u7684 leader\r\n2. producer \u5c06\u6d88\u606f\u53d1\u9001\u7ed9\u8be5 leader\r\n3. leader \u5c06\u6d88\u606f\u5199\u5165\u672c\u5730 log\r\n4. followers \u4ece leader pull \u6d88\u606f\uff0c\u5199\u5165\u672c\u5730 log \u540e leader \u53d1\u9001 ACK\r\n5. leader \u6536\u5230\u6240\u6709 ISR \u4e2d\u7684 replica \u7684 ACK \u540e\uff0c\u589e\u52a0 HW\uff08high watermark\uff0c\u6700\u540e commit \u7684 offset\uff09 \u5e76\u5411 producer \u53d1\u9001 ACK<\/pre>\n<div class=\"cnblogs_code_toolbar\"><\/div>\n<\/div>\n<h3><strong>3.4 producer delivery guarantee<\/strong><\/h3>\n<p>\u4e00\u822c\u60c5\u51b5\u4e0b\u5b58\u5728\u4e09\u79cd\u60c5\u51b5\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. At most once \u6d88\u606f\u53ef\u80fd\u4f1a\u4e22\uff0c\u4f46\u7edd\u4e0d\u4f1a\u91cd\u590d\u4f20\u8f93\r\n\r\n2. At least one \u6d88\u606f\u7edd\u4e0d\u4f1a\u4e22\uff0c\u4f46\u53ef\u80fd\u4f1a\u91cd\u590d\u4f20\u8f93\r\n\r\n3. Exactly once \u6bcf\u6761\u6d88\u606f\u80af\u5b9a\u4f1a\u88ab\u4f20\u8f93\u4e00\u6b21\u4e14\u4ec5\u4f20\u8f93\u4e00\u6b21<\/pre>\n<\/div>\n<p>\u5f53 producer \u5411 broker \u53d1\u9001\u6d88\u606f\u65f6\uff0c\u4e00\u65e6\u8fd9\u6761\u6d88\u606f\u88ab commit\uff0c\u7531\u4e8e replication \u7684\u5b58\u5728\uff0c\u5b83\u5c31\u4e0d\u4f1a\u4e22\u3002\u4f46\u662f\u5982\u679c producer \u53d1\u9001\u6570\u636e\u7ed9 broker \u540e\uff0c\u9047\u5230\u7f51\u7edc\u95ee\u9898\u800c\u9020\u6210\u901a\u4fe1\u4e2d\u65ad\uff0c\u90a3 Producer \u5c31\u65e0\u6cd5\u5224\u65ad\u8be5\u6761\u6d88\u606f\u662f\u5426\u5df2\u7ecf commit\u3002\u867d\u7136 Kafka \u65e0\u6cd5\u786e\u5b9a\u7f51\u7edc\u6545\u969c\u671f\u95f4\u53d1\u751f\u4e86\u4ec0\u4e48\uff0c\u4f46\u662f producer \u53ef\u4ee5\u751f\u6210\u4e00\u79cd\u7c7b\u4f3c\u4e8e\u4e3b\u952e\u7684\u4e1c\u897f\uff0c\u53d1\u751f\u6545\u969c\u65f6\u5e42\u7b49\u6027\u7684\u91cd\u8bd5\u591a\u6b21\uff0c\u8fd9\u6837\u5c31\u505a\u5230\u4e86 Exactly once\uff0c\u4f46\u76ee\u524d\u8fd8\u5e76\u672a\u5b9e\u73b0\u3002\u6240\u4ee5\u76ee\u524d\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4e00\u6761\u6d88\u606f\u4ece producer \u5230 broker \u662f\u786e\u4fdd\u4e86 At least once\uff0c\u53ef\u901a\u8fc7\u8bbe\u7f6e producer \u5f02\u6b65\u53d1\u9001\u5b9e\u73b0At most once\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>\u56db\u3001broker \u4fdd\u5b58\u6d88\u606f<\/strong><\/h2>\n<h3><strong>4.1 \u5b58\u50a8\u65b9\u5f0f<\/strong><\/h3>\n<p>\u7269\u7406\u4e0a\u628a topic \u5206\u6210\u4e00\u4e2a\u6216\u591a\u4e2a patition\uff08\u5bf9\u5e94 server.properties \u4e2d\u7684 num.partitions=3 \u914d\u7f6e\uff09\uff0c\u6bcf\u4e2a patition \u7269\u7406\u4e0a\u5bf9\u5e94\u4e00\u4e2a\u6587\u4ef6\u5939\uff08\u8be5\u6587\u4ef6\u5939\u5b58\u50a8\u8be5 patition \u7684\u6240\u6709\u6d88\u606f\u548c\u7d22\u5f15\u6587\u4ef6\uff09\uff0c\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/897247\/201610\/897247-20161012105133296-413851676.png\" alt=\"\" \/><\/p>\n<p>\u56fe.4<\/p>\n<h3><strong>4.2 \u5b58\u50a8\u7b56\u7565<\/strong><\/h3>\n<p>\u65e0\u8bba\u6d88\u606f\u662f\u5426\u88ab\u6d88\u8d39\uff0ckafka \u90fd\u4f1a\u4fdd\u7559\u6240\u6709\u6d88\u606f\u3002\u6709\u4e24\u79cd\u7b56\u7565\u53ef\u4ee5\u5220\u9664\u65e7\u6570\u636e\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. \u57fa\u4e8e\u65f6\u95f4\uff1alog.retention.hours=168\r\n\r\n2. \u57fa\u4e8e\u5927\u5c0f\uff1alog.retention.bytes=1073741824<\/pre>\n<\/div>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u56e0\u4e3aKafka\u8bfb\u53d6\u7279\u5b9a\u6d88\u606f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(1)\uff0c\u5373\u4e0e\u6587\u4ef6\u5927\u5c0f\u65e0\u5173\uff0c\u6240\u4ee5\u8fd9\u91cc\u5220\u9664\u8fc7\u671f\u6587\u4ef6\u4e0e\u63d0\u9ad8 Kafka \u6027\u80fd\u65e0\u5173\u3002<\/p>\n<h3><strong>4.3 topic \u521b\u5efa\u4e0e\u5220\u9664<\/strong><\/h3>\n<h4><strong>4.3.1 \u521b\u5efa topic<\/strong><\/h4>\n<p>\u521b\u5efa topic \u7684\u5e8f\u5217\u56fe\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/897247\/201610\/897247-20161012161552718-1963426687.png\" alt=\"\" \/><\/p>\n<p>\u56fe.5<\/p>\n<p>\u6d41\u7a0b\u8bf4\u660e\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. controller \u5728 ZooKeeper \u7684 \/brokers\/topics \u8282\u70b9\u4e0a\u6ce8\u518c watcher\uff0c\u5f53 topic \u88ab\u521b\u5efa\uff0c\u5219 controller \u4f1a\u901a\u8fc7 watch \u5f97\u5230\u8be5 topic \u7684 partition\/replica \u5206\u914d\u3002\r\n\r\n2. controller\u4ece \/brokers\/ids \u8bfb\u53d6\u5f53\u524d\u6240\u6709\u53ef\u7528\u7684 broker \u5217\u8868\uff0c\u5bf9\u4e8e set_p \u4e2d\u7684\u6bcf\u4e00\u4e2a partition\uff1a\r\n\t2.1 \u4ece\u5206\u914d\u7ed9\u8be5 partition \u7684\u6240\u6709 replica\uff08\u79f0\u4e3aAR\uff09\u4e2d\u4efb\u9009\u4e00\u4e2a\u53ef\u7528\u7684 broker \u4f5c\u4e3a\u65b0\u7684 leader\uff0c\u5e76\u5c06AR\u8bbe\u7f6e\u4e3a\u65b0\u7684 ISR\r\n\t2.2 \u5c06\u65b0\u7684 leader \u548c ISR \u5199\u5165 \/brokers\/topics\/[topic]\/partitions\/[partition]\/state\r\n\r\n3. controller \u901a\u8fc7 RPC \u5411\u76f8\u5173\u7684 broker \u53d1\u9001 LeaderAndISRRequest\u3002<\/pre>\n<div class=\"cnblogs_code_toolbar\"><\/div>\n<\/div>\n<h4><strong>4.3.2 \u5220\u9664 topic<\/strong><\/h4>\n<p>\u5220\u9664 topic \u7684\u5e8f\u5217\u56fe\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/897247\/201610\/897247-20161012162436140-850153613.png\" alt=\"\" \/><\/p>\n<p>\u56fe.6<\/p>\n<p>\u6d41\u7a0b\u8bf4\u660e\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. controller \u5728 zooKeeper \u7684 \/brokers\/topics \u8282\u70b9\u4e0a\u6ce8\u518c watcher\uff0c\u5f53 topic \u88ab\u5220\u9664\uff0c\u5219 controller \u4f1a\u901a\u8fc7 watch \u5f97\u5230\u8be5 topic \u7684 partition\/replica \u5206\u914d\u3002\r\n\r\n2. \u82e5 delete.topic.enable=false\uff0c\u7ed3\u675f\uff1b\u5426\u5219 controller \u6ce8\u518c\u5728 \/admin\/delete_topics \u4e0a\u7684 watch \u88ab fire\uff0ccontroller \u901a\u8fc7\u56de\u8c03\u5411\u5bf9\u5e94\u7684 broker \u53d1\u9001 StopReplicaRequest\u3002<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<h2><strong>\u4e94\u3001kafka HA<\/strong><\/h2>\n<h3><strong>5.1 replication<\/strong><\/h3>\n<p>\u5982\u56fe.1\u6240\u793a\uff0c\u540c\u4e00\u4e2a partition \u53ef\u80fd\u4f1a\u6709\u591a\u4e2a replica\uff08\u5bf9\u5e94 server.properties \u914d\u7f6e\u4e2d\u7684 default.replication.factor=N\uff09\u3002\u6ca1\u6709 replica \u7684\u60c5\u51b5\u4e0b\uff0c\u4e00\u65e6 broker \u5b95\u673a\uff0c\u5176\u4e0a\u6240\u6709 patition \u7684\u6570\u636e\u90fd\u4e0d\u53ef\u88ab\u6d88\u8d39\uff0c\u540c\u65f6 producer \u4e5f\u4e0d\u80fd\u518d\u5c06\u6570\u636e\u5b58\u4e8e\u5176\u4e0a\u7684 patition\u3002\u5f15\u5165replication \u4e4b\u540e\uff0c\u540c\u4e00\u4e2a partition \u53ef\u80fd\u4f1a\u6709\u591a\u4e2a replica\uff0c\u800c\u8fd9\u65f6\u9700\u8981\u5728\u8fd9\u4e9b replica \u4e4b\u95f4\u9009\u51fa\u4e00\u4e2a leader\uff0cproducer \u548c consumer \u53ea\u4e0e\u8fd9\u4e2a leader \u4ea4\u4e92\uff0c\u5176\u5b83 replica \u4f5c\u4e3a follower \u4ece leader \u4e2d\u590d\u5236\u6570\u636e\u3002<\/p>\n<p>Kafka \u5206\u914d Replica \u7684\u7b97\u6cd5\u5982\u4e0b\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. \u5c06\u6240\u6709 broker\uff08\u5047\u8bbe\u5171 n \u4e2a broker\uff09\u548c\u5f85\u5206\u914d\u7684 partition \u6392\u5e8f\r\n\r\n2. \u5c06\u7b2c i \u4e2a partition \u5206\u914d\u5230\u7b2c\uff08i mod n\uff09\u4e2a broker \u4e0a\r\n\r\n3. \u5c06\u7b2c i \u4e2a partition \u7684\u7b2c j \u4e2a replica \u5206\u914d\u5230\u7b2c\uff08(i + j) mode n\uff09\u4e2a broker\u4e0a<\/pre>\n<\/div>\n<h3><strong>5.2 leader failover<\/strong><\/h3>\n<p>\u5f53 partition \u5bf9\u5e94\u7684 leader \u5b95\u673a\u65f6\uff0c\u9700\u8981\u4ece follower \u4e2d\u9009\u4e3e\u51fa\u65b0 leader\u3002\u5728\u9009\u4e3e\u65b0leader\u65f6\uff0c\u4e00\u4e2a\u57fa\u672c\u7684\u539f\u5219\u662f\uff0c\u65b0\u7684 leader \u5fc5\u987b\u62e5\u6709\u65e7 leader commit \u8fc7\u7684\u6240\u6709\u6d88\u606f\u3002<\/p>\n<p>kafka \u5728 zookeeper \u4e2d\uff08\/brokers\/...\/state\uff09\u52a8\u6001\u7ef4\u62a4\u4e86\u4e00\u4e2a ISR\uff08in-sync replicas\uff09\uff0c\u75313.3\u8282\u7684\u5199\u5165\u6d41\u7a0b\u53ef\u77e5 ISR \u91cc\u9762\u7684\u6240\u6709 replica \u90fd\u8ddf\u4e0a\u4e86 leader\uff0c\u53ea\u6709 ISR \u91cc\u9762\u7684\u6210\u5458\u624d\u80fd\u9009\u4e3a leader\u3002\u5bf9\u4e8e f+1 \u4e2a replica\uff0c\u4e00\u4e2a partition \u53ef\u4ee5\u5728\u5bb9\u5fcd f \u4e2a replica \u5931\u6548\u7684\u60c5\u51b5\u4e0b\u4fdd\u8bc1\u6d88\u606f\u4e0d\u4e22\u5931\u3002<\/p>\n<p>\u5f53\u6240\u6709 replica \u90fd\u4e0d\u5de5\u4f5c\u65f6\uff0c\u6709\u4e24\u79cd\u53ef\u884c\u7684\u65b9\u6848\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. \u7b49\u5f85 ISR \u4e2d\u7684\u4efb\u4e00\u4e2a replica \u6d3b\u8fc7\u6765\uff0c\u5e76\u9009\u5b83\u4f5c\u4e3a leader\u3002\u53ef\u4fdd\u969c\u6570\u636e\u4e0d\u4e22\u5931\uff0c\u4f46\u65f6\u95f4\u53ef\u80fd\u76f8\u5bf9\u8f83\u957f\u3002\r\n\r\n2. \u9009\u62e9\u7b2c\u4e00\u4e2a\u6d3b\u8fc7\u6765\u7684 replica\uff08\u4e0d\u4e00\u5b9a\u662f ISR \u6210\u5458\uff09\u4f5c\u4e3a leader\u3002\u65e0\u6cd5\u4fdd\u969c\u6570\u636e\u4e0d\u4e22\u5931\uff0c\u4f46\u76f8\u5bf9\u4e0d\u53ef\u7528\u65f6\u95f4\u8f83\u77ed\u3002<\/pre>\n<\/div>\n<p>kafka 0.8.* \u4f7f\u7528\u7b2c\u4e8c\u79cd\u65b9\u5f0f\u3002<\/p>\n<p>kafka \u901a\u8fc7 Controller \u6765\u9009\u4e3e leader\uff0c\u6d41\u7a0b\u8bf7\u53c2\u80035.3\u8282\u3002<\/p>\n<h3><strong>5.3 broker failover<\/strong><\/h3>\n<p>kafka broker failover \u5e8f\u5217\u56fe\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/897247\/201610\/897247-20161012143318812-1534130173.png\" alt=\"\" \/><\/p>\n<p>\u56fe.7<\/p>\n<p>\u6d41\u7a0b\u8bf4\u660e\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. controller \u5728 zookeeper \u7684 \/brokers\/ids\/[brokerId] \u8282\u70b9\u6ce8\u518c Watcher\uff0c\u5f53 broker \u5b95\u673a\u65f6 zookeeper \u4f1a fire watch\r\n2. controller \u4ece \/brokers\/ids \u8282\u70b9\u8bfb\u53d6\u53ef\u7528broker\r\n3. controller\u51b3\u5b9aset_p\uff0c\u8be5\u96c6\u5408\u5305\u542b\u5b95\u673a broker \u4e0a\u7684\u6240\u6709 partition\r\n4. \u5bf9 set_p \u4e2d\u7684\u6bcf\u4e00\u4e2a partition\r\n    4.1 \u4ece\/brokers\/topics\/[topic]\/partitions\/[partition]\/state \u8282\u70b9\u8bfb\u53d6 ISR\r\n    4.2 \u51b3\u5b9a\u65b0 leader\uff08\u59824.3\u8282\u6240\u63cf\u8ff0\uff09\r\n    4.3 \u5c06\u65b0 leader\u3001ISR\u3001controller_epoch \u548c leader_epoch \u7b49\u4fe1\u606f\u5199\u5165 state \u8282\u70b9\r\n5. \u901a\u8fc7 RPC \u5411\u76f8\u5173 broker \u53d1\u9001 leaderAndISRRequest \u547d\u4ee4<\/pre>\n<div class=\"cnblogs_code_toolbar\"><\/div>\n<\/div>\n<h3><strong>5.4 controller failover<\/strong><\/h3>\n<p>\u5f53 controller \u5b95\u673a\u65f6\u4f1a\u89e6\u53d1 controller failover\u3002\u6bcf\u4e2a broker \u90fd\u4f1a\u5728 zookeeper \u7684 \"\/controller\" \u8282\u70b9\u6ce8\u518c watcher\uff0c\u5f53 controller \u5b95\u673a\u65f6 zookeeper \u4e2d\u7684\u4e34\u65f6\u8282\u70b9\u6d88\u5931\uff0c\u6240\u6709\u5b58\u6d3b\u7684 broker \u6536\u5230 fire \u7684\u901a\u77e5\uff0c\u6bcf\u4e2a broker \u90fd\u5c1d\u8bd5\u521b\u5efa\u65b0\u7684 controller path\uff0c\u53ea\u6709\u4e00\u4e2a\u7ade\u9009\u6210\u529f\u5e76\u5f53\u9009\u4e3a controller\u3002<\/p>\n<p>\u5f53\u65b0\u7684 controller \u5f53\u9009\u65f6\uff0c\u4f1a\u89e6\u53d1 KafkaController.onControllerFailover \u65b9\u6cd5\uff0c\u5728\u8be5\u65b9\u6cd5\u4e2d\u5b8c\u6210\u5982\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. \u8bfb\u53d6\u5e76\u589e\u52a0 Controller Epoch\u3002\r\n2. \u5728 reassignedPartitions Patch(\/admin\/reassign_partitions) \u4e0a\u6ce8\u518c watcher\u3002\r\n3. \u5728 preferredReplicaElection Path(\/admin\/preferred_replica_election) \u4e0a\u6ce8\u518c watcher\u3002\r\n4. \u901a\u8fc7 partitionStateMachine \u5728 broker Topics Patch(\/brokers\/topics) \u4e0a\u6ce8\u518c watcher\u3002\r\n5. \u82e5 delete.topic.enable=true\uff08\u9ed8\u8ba4\u503c\u662f false\uff09\uff0c\u5219 partitionStateMachine \u5728 Delete Topic Patch(\/admin\/delete_topics) \u4e0a\u6ce8\u518c watcher\u3002\r\n6. \u901a\u8fc7 replicaStateMachine\u5728 Broker Ids Patch(\/brokers\/ids)\u4e0a\u6ce8\u518cWatch\u3002\r\n7. \u521d\u59cb\u5316 ControllerContext \u5bf9\u8c61\uff0c\u8bbe\u7f6e\u5f53\u524d\u6240\u6709 topic\uff0c\u201c\u6d3b\u201d\u7740\u7684 broker \u5217\u8868\uff0c\u6240\u6709 partition \u7684 leader \u53ca ISR\u7b49\u3002\r\n8. \u542f\u52a8 replicaStateMachine \u548c partitionStateMachine\u3002\r\n9. \u5c06 brokerState \u72b6\u6001\u8bbe\u7f6e\u4e3a RunningAsController\u3002\r\n10. \u5c06\u6bcf\u4e2a partition \u7684 Leadership \u4fe1\u606f\u53d1\u9001\u7ed9\u6240\u6709\u201c\u6d3b\u201d\u7740\u7684 broker\u3002\r\n11. \u82e5 auto.leader.rebalance.enable=true\uff08\u9ed8\u8ba4\u503c\u662ftrue\uff09\uff0c\u5219\u542f\u52a8 partition-rebalance \u7ebf\u7a0b\u3002\r\n12. \u82e5 delete.topic.enable=true \u4e14Delete Topic Patch(\/admin\/delete_topics)\u4e2d\u6709\u503c\uff0c\u5219\u5220\u9664\u76f8\u5e94\u7684Topic\u3002<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<h2><strong>6. consumer \u6d88\u8d39\u6d88\u606f<\/strong><\/h2>\n<h3><strong>6.1 consumer API<\/strong><\/h3>\n<p>kafka \u63d0\u4f9b\u4e86\u4e24\u5957 consumer API\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. The high-level Consumer API\r\n\r\n2. The SimpleConsumer API<\/pre>\n<\/div>\n<p>\u5176\u4e2d high-level consumer API \u63d0\u4f9b\u4e86\u4e00\u4e2a\u4ece kafka \u6d88\u8d39\u6570\u636e\u7684\u9ad8\u5c42\u62bd\u8c61\uff0c\u800c SimpleConsumer API \u5219\u9700\u8981\u5f00\u53d1\u4eba\u5458\u66f4\u591a\u5730\u5173\u6ce8\u7ec6\u8282\u3002<\/p>\n<h4><strong>6.1.1\u00a0The high-level consumer API<\/strong><\/h4>\n<p>high-level consumer API \u63d0\u4f9b\u4e86 consumer group \u7684\u8bed\u4e49\uff0c\u4e00\u4e2a\u6d88\u606f\u53ea\u80fd\u88ab group \u5185\u7684\u4e00\u4e2a consumer \u6240\u6d88\u8d39\uff0c\u4e14\u00a0consumer \u6d88\u8d39\u6d88\u606f\u65f6\u4e0d\u5173\u6ce8 offset\uff0c\u6700\u540e\u4e00\u4e2a offset \u7531 zookeeper \u4fdd\u5b58\u3002<\/p>\n<p>\u4f7f\u7528 high-level consumer API \u53ef\u4ee5\u662f\u591a\u7ebf\u7a0b\u7684\u5e94\u7528\uff0c\u5e94\u5f53\u6ce8\u610f\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. \u5982\u679c\u6d88\u8d39\u7ebf\u7a0b\u5927\u4e8e patition \u6570\u91cf\uff0c\u5219\u6709\u4e9b\u7ebf\u7a0b\u5c06\u6536\u4e0d\u5230\u6d88\u606f\r\n2. \u5982\u679c patition \u6570\u91cf\u5927\u4e8e\u7ebf\u7a0b\u6570\uff0c\u5219\u6709\u4e9b\u7ebf\u7a0b\u591a\u6536\u5230\u591a\u4e2a patition \u7684\u6d88\u606f\r\n3. \u5982\u679c\u4e00\u4e2a\u7ebf\u7a0b\u6d88\u8d39\u591a\u4e2a patition\uff0c\u5219\u65e0\u6cd5\u4fdd\u8bc1\u4f60\u6536\u5230\u7684\u6d88\u606f\u7684\u987a\u5e8f\uff0c\u800c\u4e00\u4e2a patition \u5185\u7684\u6d88\u606f\u662f\u6709\u5e8f\u7684<\/pre>\n<\/div>\n<h4><strong>6.1.2 The SimpleConsumer API<\/strong><\/h4>\n<p>\u5982\u679c\u4f60\u60f3\u8981\u5bf9 patition \u6709\u66f4\u591a\u7684\u63a7\u5236\u6743\uff0c\u90a3\u5c31\u5e94\u8be5\u4f7f\u7528 SimpleConsumer API\uff0c\u6bd4\u5982\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. \u591a\u6b21\u8bfb\u53d6\u4e00\u4e2a\u6d88\u606f\r\n\r\n2. \u53ea\u6d88\u8d39\u4e00\u4e2a patition \u4e2d\u7684\u90e8\u5206\u6d88\u606f\r\n\r\n3. \u4f7f\u7528\u4e8b\u52a1\u6765\u4fdd\u8bc1\u4e00\u4e2a\u6d88\u606f\u4ec5\u88ab\u6d88\u8d39\u4e00\u6b21<\/pre>\n<\/div>\n<p>\u4f46\u662f\u4f7f\u7528\u6b64 API \u65f6\uff0cpartition\u3001offset\u3001broker\u3001leader \u7b49\u5bf9\u4f60\u4e0d\u518d\u900f\u660e\uff0c\u9700\u8981\u81ea\u5df1\u53bb\u7ba1\u7406\u3002\u4f60\u9700\u8981\u505a\u5927\u91cf\u7684\u989d\u5916\u5de5\u4f5c\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. \u5fc5\u987b\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8ddf\u8e2a offset\uff0c\u4ece\u800c\u786e\u5b9a\u4e0b\u4e00\u6761\u5e94\u8be5\u6d88\u8d39\u54ea\u6761\u6d88\u606f\r\n\r\n2. \u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u901a\u8fc7\u7a0b\u5e8f\u83b7\u77e5\u6bcf\u4e2a Partition \u7684 leader \u662f\u8c01\r\n\r\n3. \u9700\u8981\u5904\u7406 leader \u7684\u53d8\u66f4<\/pre>\n<\/div>\n<p>\u4f7f\u7528 SimpleConsumer API \u7684\u4e00\u822c\u6d41\u7a0b\u5982\u4e0b\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. \u67e5\u627e\u5230\u4e00\u4e2a\u201c\u6d3b\u7740\u201d\u7684 broker\uff0c\u5e76\u4e14\u627e\u51fa\u6bcf\u4e2a partition \u7684 leader\r\n\r\n2. \u627e\u51fa\u6bcf\u4e2a partition \u7684 follower\r\n\r\n3. \u5b9a\u4e49\u597d\u8bf7\u6c42\uff0c\u8be5\u8bf7\u6c42\u5e94\u8be5\u80fd\u63cf\u8ff0\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u54ea\u4e9b\u6570\u636e\r\n\r\n4. fetch \u6570\u636e\r\n\r\n5. \u8bc6\u522b leader \u7684\u53d8\u5316\uff0c\u5e76\u5bf9\u4e4b\u4f5c\u51fa\u5fc5\u8981\u7684\u54cd\u5e94<\/pre>\n<\/div>\n<blockquote><p>\u4ee5\u4e0b\u9488\u5bf9 high-level Consumer API \u8fdb\u884c\u8bf4\u660e\u3002<\/p><\/blockquote>\n<h3><strong>6.2 consumer group<\/strong><\/h3>\n<p>\u5982 2.2 \u8282\u6240\u8bf4\uff0c kafka \u7684\u5206\u914d\u5355\u4f4d\u662f patition\u3002\u6bcf\u4e2a consumer \u90fd\u5c5e\u4e8e\u4e00\u4e2a group\uff0c\u4e00\u4e2a partition \u53ea\u80fd\u88ab\u540c\u4e00\u4e2a group \u5185\u7684\u4e00\u4e2a consumer \u6240\u6d88\u8d39\uff08\u4e5f\u5c31\u4fdd\u969c\u4e86\u4e00\u4e2a\u6d88\u606f\u53ea\u80fd\u88ab group \u5185\u7684\u4e00\u4e2a consuemr \u6240\u6d88\u8d39\uff09\uff0c\u4f46\u662f\u591a\u4e2a group \u53ef\u4ee5\u540c\u65f6\u6d88\u8d39\u8fd9\u4e2a partition\u3002<\/p>\n<p>kafka \u7684\u8bbe\u8ba1\u76ee\u6807\u4e4b\u4e00\u5c31\u662f\u540c\u65f6\u5b9e\u73b0\u79bb\u7ebf\u5904\u7406\u548c\u5b9e\u65f6\u5904\u7406\uff0c\u6839\u636e\u8fd9\u4e00\u7279\u6027\uff0c\u53ef\u4ee5\u4f7f\u7528 spark\/Storm \u8fd9\u4e9b\u5b9e\u65f6\u5904\u7406\u7cfb\u7edf\u5bf9\u6d88\u606f\u5728\u7ebf\u5904\u7406\uff0c\u540c\u65f6\u4f7f\u7528 Hadoop \u6279\u5904\u7406\u7cfb\u7edf\u8fdb\u884c\u79bb\u7ebf\u5904\u7406\uff0c\u8fd8\u53ef\u4ee5\u5c06\u6570\u636e\u5907\u4efd\u5230\u53e6\u4e00\u4e2a\u6570\u636e\u4e2d\u5fc3\uff0c\u53ea\u9700\u8981\u4fdd\u8bc1\u8fd9\u4e09\u8005\u5c5e\u4e8e\u4e0d\u540c\u7684 consumer group\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/images2015.cnblogs.com\/blog\/897247\/201610\/897247-20161012104850453-563375248.png\" alt=\"\" width=\"486\" height=\"447\" \/><\/p>\n<p>\u56fe.8<\/p>\n<h2><strong>6.3 \u6d88\u8d39\u65b9\u5f0f<\/strong><\/h2>\n<p>consumer \u91c7\u7528 pull \u6a21\u5f0f\u4ece broker \u4e2d\u8bfb\u53d6\u6570\u636e\u3002<\/p>\n<p>push \u6a21\u5f0f\u5f88\u96be\u9002\u5e94\u6d88\u8d39\u901f\u7387\u4e0d\u540c\u7684\u6d88\u8d39\u8005\uff0c\u56e0\u4e3a\u6d88\u606f\u53d1\u9001\u901f\u7387\u662f\u7531 broker \u51b3\u5b9a\u7684\u3002\u5b83\u7684\u76ee\u6807\u662f\u5c3d\u53ef\u80fd\u4ee5\u6700\u5feb\u901f\u5ea6\u4f20\u9012\u6d88\u606f\uff0c\u4f46\u662f\u8fd9\u6837\u5f88\u5bb9\u6613\u9020\u6210 consumer \u6765\u4e0d\u53ca\u5904\u7406\u6d88\u606f\uff0c\u5178\u578b\u7684\u8868\u73b0\u5c31\u662f\u62d2\u7edd\u670d\u52a1\u4ee5\u53ca\u7f51\u7edc\u62e5\u585e\u3002\u800c pull \u6a21\u5f0f\u5219\u53ef\u4ee5\u6839\u636e consumer \u7684\u6d88\u8d39\u80fd\u529b\u4ee5\u9002\u5f53\u7684\u901f\u7387\u6d88\u8d39\u6d88\u606f\u3002<\/p>\n<p>\u5bf9\u4e8e Kafka \u800c\u8a00\uff0cpull \u6a21\u5f0f\u66f4\u5408\u9002\uff0c\u5b83\u53ef\u7b80\u5316 broker \u7684\u8bbe\u8ba1\uff0cconsumer \u53ef\u81ea\u4e3b\u63a7\u5236\u6d88\u8d39\u6d88\u606f\u7684\u901f\u7387\uff0c\u540c\u65f6 consumer \u53ef\u4ee5\u81ea\u5df1\u63a7\u5236\u6d88\u8d39\u65b9\u5f0f\u2014\u2014\u5373\u53ef\u6279\u91cf\u6d88\u8d39\u4e5f\u53ef\u9010\u6761\u6d88\u8d39\uff0c\u540c\u65f6\u8fd8\u80fd\u9009\u62e9\u4e0d\u540c\u7684\u63d0\u4ea4\u65b9\u5f0f\u4ece\u800c\u5b9e\u73b0\u4e0d\u540c\u7684\u4f20\u8f93\u8bed\u4e49\u3002<\/p>\n<h3><strong>6.4 consumer\u00a0delivery guarantee<\/strong><\/h3>\n<p>\u5982\u679c\u5c06 consumer \u8bbe\u7f6e\u4e3a autocommit\uff0cconsumer \u4e00\u65e6\u8bfb\u5230\u6570\u636e\u7acb\u5373\u81ea\u52a8 commit\u3002\u5982\u679c\u53ea\u8ba8\u8bba\u8fd9\u4e00\u8bfb\u53d6\u6d88\u606f\u7684\u8fc7\u7a0b\uff0c\u90a3 Kafka \u786e\u4fdd\u4e86 Exactly once\u3002<\/p>\n<p>\u4f46\u5b9e\u9645\u4f7f\u7528\u4e2d\u5e94\u7528\u7a0b\u5e8f\u5e76\u975e\u5728 consumer \u8bfb\u53d6\u5b8c\u6570\u636e\u5c31\u7ed3\u675f\u4e86\uff0c\u800c\u662f\u8981\u8fdb\u884c\u8fdb\u4e00\u6b65\u5904\u7406\uff0c\u800c\u6570\u636e\u5904\u7406\u4e0e commit \u7684\u987a\u5e8f\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u51b3\u5b9a\u4e86consumer delivery guarantee\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre><strong>1.\u8bfb\u5b8c\u6d88\u606f\u5148 commit \u518d\u5904\u7406\u6d88\u606f\u3002<\/strong>\r\n    \u8fd9\u79cd\u6a21\u5f0f\u4e0b\uff0c\u5982\u679c consumer \u5728 commit \u540e\u8fd8\u6ca1\u6765\u5f97\u53ca\u5904\u7406\u6d88\u606f\u5c31 crash \u4e86\uff0c\u4e0b\u6b21\u91cd\u65b0\u5f00\u59cb\u5de5\u4f5c\u540e\u5c31\u65e0\u6cd5\u8bfb\u5230\u521a\u521a\u5df2\u63d0\u4ea4\u800c\u672a\u5904\u7406\u7684\u6d88\u606f\uff0c\u8fd9\u5c31\u5bf9\u5e94\u4e8e At most once\r\n<strong>2.\u8bfb\u5b8c\u6d88\u606f\u5148\u5904\u7406\u518d commit\u3002<\/strong>\r\n    \u8fd9\u79cd\u6a21\u5f0f\u4e0b\uff0c\u5982\u679c\u5728\u5904\u7406\u5b8c\u6d88\u606f\u4e4b\u540e commit \u4e4b\u524d consumer crash \u4e86\uff0c\u4e0b\u6b21\u91cd\u65b0\u5f00\u59cb\u5de5\u4f5c\u65f6\u8fd8\u4f1a\u5904\u7406\u521a\u521a\u672a commit \u7684\u6d88\u606f\uff0c\u5b9e\u9645\u4e0a\u8be5\u6d88\u606f\u5df2\u7ecf\u88ab\u5904\u7406\u8fc7\u4e86\u3002\u8fd9\u5c31\u5bf9\u5e94\u4e8e At least once\u3002\r\n<strong>3.\u5982\u679c\u4e00\u5b9a\u8981\u505a\u5230 Exactly once\uff0c\u5c31\u9700\u8981\u534f\u8c03 offset \u548c\u5b9e\u9645\u64cd\u4f5c\u7684\u8f93\u51fa\u3002<\/strong>\r\n    \u7cbe\u5178\u7684\u505a\u6cd5\u662f\u5f15\u5165\u4e24\u9636\u6bb5\u63d0\u4ea4\u3002\u5982\u679c\u80fd\u8ba9 offset \u548c\u64cd\u4f5c\u8f93\u5165\u5b58\u5728\u540c\u4e00\u4e2a\u5730\u65b9\uff0c\u4f1a\u66f4\u7b80\u6d01\u548c\u901a\u7528\u3002\u8fd9\u79cd\u65b9\u5f0f\u53ef\u80fd\u66f4\u597d\uff0c\u56e0\u4e3a\u8bb8\u591a\u8f93\u51fa\u7cfb\u7edf\u53ef\u80fd\u4e0d\u652f\u6301\u4e24\u9636\u6bb5\u63d0\u4ea4\u3002\u6bd4\u5982\uff0cconsumer \u62ff\u5230\u6570\u636e\u540e\u53ef\u80fd\u628a\u6570\u636e\u653e\u5230 HDFS\uff0c\u5982\u679c\u628a\u6700\u65b0\u7684 offset \u548c\u6570\u636e\u672c\u8eab\u4e00\u8d77\u5199\u5230 HDFS\uff0c\u90a3\u5c31\u53ef\u4ee5\u4fdd\u8bc1\u6570\u636e\u7684\u8f93\u51fa\u548c offset \u7684\u66f4\u65b0\u8981\u4e48\u90fd\u5b8c\u6210\uff0c\u8981\u4e48\u90fd\u4e0d\u5b8c\u6210\uff0c\u95f4\u63a5\u5b9e\u73b0 Exactly once\u3002\uff08\u76ee\u524d\u5c31 high-level API\u800c\u8a00\uff0coffset \u662f\u5b58\u4e8eZookeeper \u4e2d\u7684\uff0c\u65e0\u6cd5\u5b58\u4e8eHDFS\uff0c\u800cSimpleConsuemr API\u7684 offset \u662f\u7531\u81ea\u5df1\u53bb\u7ef4\u62a4\u7684\uff0c\u53ef\u4ee5\u5c06\u4e4b\u5b58\u4e8e HDFS \u4e2d\uff09<\/pre>\n<\/div>\n<p>\u603b\u4e4b\uff0cKafka \u9ed8\u8ba4\u4fdd\u8bc1 At least once\uff0c\u5e76\u4e14\u5141\u8bb8\u901a\u8fc7\u8bbe\u7f6e producer \u5f02\u6b65\u63d0\u4ea4\u6765\u5b9e\u73b0 At most once\uff08\u89c1\u6587\u7ae0\u300a<a href=\"http:\/\/kane-xie.iteye.com\/blog\/2225085\" target=\"_blank\" rel=\"noopener\">kafka consumer\u9632\u6b62\u6570\u636e\u4e22\u5931<\/a>\u300b\uff09\u3002\u800c Exactly once \u8981\u6c42\u4e0e\u5916\u90e8\u5b58\u50a8\u7cfb\u7edf\u534f\u4f5c\uff0c\u5e78\u8fd0\u7684\u662f kafka \u63d0\u4f9b\u7684 offset \u53ef\u4ee5\u975e\u5e38\u76f4\u63a5\u975e\u5e38\u5bb9\u6613\u5f97\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u3002<\/p>\n<p>\u66f4\u591a\u5173\u4e8e kafka \u4f20\u8f93\u8bed\u4e49\u7684\u4fe1\u606f\u8bf7\u53c2\u8003\u300a<a href=\"http:\/\/kafka.apache.org\/documentation.html#semantics\" target=\"_blank\" rel=\"noopener\">Message Delivery Semantics<\/a>\u300b\u3002<\/p>\n<h3><strong>6.5 consumer rebalance<\/strong><\/h3>\n<p>\u5f53\u6709 consumer \u52a0\u5165\u6216\u9000\u51fa\u3001\u4ee5\u53ca partition \u7684\u6539\u53d8\uff08\u5982 broker \u52a0\u5165\u6216\u9000\u51fa\uff09\u65f6\u4f1a\u89e6\u53d1 rebalance\u3002consumer rebalance\u7b97\u6cd5\u5982\u4e0b\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. \u5c06\u76ee\u6807 topic \u4e0b\u7684\u6240\u6709 partirtion \u6392\u5e8f\uff0c\u5b58\u4e8ePT\r\n2. \u5bf9\u67d0 consumer group \u4e0b\u6240\u6709 consumer \u6392\u5e8f\uff0c\u5b58\u4e8e CG\uff0c\u7b2c i \u4e2aconsumer \u8bb0\u4e3a Ci\r\n3. N=size(PT)\/size(CG)\uff0c\u5411\u4e0a\u53d6\u6574\r\n4. \u89e3\u9664 Ci \u5bf9\u539f\u6765\u5206\u914d\u7684 partition \u7684\u6d88\u8d39\u6743\uff08i\u4ece0\u5f00\u59cb\uff09\r\n5. \u5c06\u7b2ci*N\u5230\uff08i+1\uff09*N-1\u4e2a partition \u5206\u914d\u7ed9 Ci<\/pre>\n<\/div>\n<p>\u5728 0.8.*\u7248\u672c\uff0c\u6bcf\u4e2a consumer \u90fd\u53ea\u8d1f\u8d23\u8c03\u6574\u81ea\u5df1\u6240\u6d88\u8d39\u7684 partition\uff0c\u4e3a\u4e86\u4fdd\u8bc1\u6574\u4e2aconsumer group \u7684\u4e00\u81f4\u6027\uff0c\u5f53\u4e00\u4e2a consumer \u89e6\u53d1\u4e86 rebalance \u65f6\uff0c\u8be5 consumer group \u5185\u7684\u5176\u5b83\u6240\u6709\u5176\u5b83 consumer \u4e5f\u5e94\u8be5\u540c\u65f6\u89e6\u53d1 rebalance\u3002\u8fd9\u4f1a\u5bfc\u81f4\u4ee5\u4e0b\u51e0\u4e2a\u95ee\u9898\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre><strong>\r\n1.Herd effect<\/strong>\r\n\u3000\u3000\u4efb\u4f55 broker \u6216\u8005 consumer \u7684\u589e\u51cf\u90fd\u4f1a\u89e6\u53d1\u6240\u6709\u7684 consumer \u7684 rebalance\r\n<strong>\r\n2.Split Brain<\/strong>\r\n\u3000\u3000\u6bcf\u4e2a consumer \u5206\u522b\u5355\u72ec\u901a\u8fc7 zookeeper \u5224\u65ad\u54ea\u4e9b broker \u548c consumer \u5b95\u673a\u4e86\uff0c\u90a3\u4e48\u4e0d\u540c consumer \u5728\u540c\u4e00\u65f6\u523b\u4ece zookeeper \u770b\u5230\u7684 view \u5c31\u53ef\u80fd\u4e0d\u4e00\u6837\uff0c\u8fd9\u662f\u7531 zookeeper \u7684\u7279\u6027\u51b3\u5b9a\u7684\uff0c\u8fd9\u5c31\u4f1a\u9020\u6210\u4e0d\u6b63\u786e\u7684 reblance \u5c1d\u8bd5\u3002\r\n<strong>\r\n3. \u8c03\u6574\u7ed3\u679c\u4e0d\u53ef\u63a7<\/strong>\r\n\u3000\u3000\u6240\u6709\u7684 consumer \u90fd\u5e76\u4e0d\u77e5\u9053\u5176\u5b83 consumer \u7684 rebalance \u662f\u5426\u6210\u529f\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4 kafka \u5de5\u4f5c\u5728\u4e00\u4e2a\u4e0d\u6b63\u786e\u7684\u72b6\u6001\u3002<\/pre>\n<div class=\"cnblogs_code_toolbar\"><\/div>\n<\/div>\n<p>\u57fa\u4e8e\u4ee5\u4e0a\u95ee\u9898\uff0ckafka \u8bbe\u8ba1\u8005\u8003\u8651\u57280.9.*\u7248\u672c\u5f00\u59cb\u4f7f\u7528\u4e2d\u5fc3 coordinator \u6765\u63a7\u5236 consumer rebalance\uff0c\u7136\u540e\u53c8\u4ece\u7b80\u4fbf\u6027\u548c\u9a8c\u8bc1\u8981\u6c42\u4e24\u65b9\u9762\u8003\u8651\uff0c\u8ba1\u5212\u5728 consumer \u5ba2\u6237\u7aef\u5b9e\u73b0\u5206\u914d\u65b9\u6848\u3002\uff08\u89c1\u6587\u7ae0\u300a<a href=\"https:\/\/cwiki.apache.org\/confluence\/display\/KAFKA\/Kafka+Detailed+Consumer+Coordinator+Design#KafkaDetailedConsumerCoordinatorDesign-WARN:Thisisanobsoletedesign.Thedesignthat'simplementedinKafka0.9.0isdescribedinthiswiki.\" target=\"_blank\" rel=\"noopener\">Kafka Detailed Consumer Coordinator Design<\/a>\u300b\u548c\u300a<a href=\"https:\/\/cwiki.apache.org\/confluence\/display\/KAFKA\/Kafka+Client-side+Assignment+Proposal\" target=\"_blank\" rel=\"noopener\">Kafka Client-side Assignment Proposal<\/a>\u300b\uff09\uff0c\u6b64\u5904\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2><strong>\u4e03\u3001\u6ce8\u610f\u4e8b\u9879<\/strong><\/h2>\n<h3><strong>7.1 producer \u65e0\u6cd5\u53d1\u9001\u6d88\u606f\u7684\u95ee\u9898<\/strong><\/h3>\n<p>\u6700\u5f00\u59cb\u5728\u672c\u673a\u642d\u5efa\u4e86kafka\u4f2a\u96c6\u7fa4\uff0c\u672c\u5730 producer \u5ba2\u6237\u7aef\u6210\u529f\u53d1\u5e03\u6d88\u606f\u81f3 broker\u3002\u968f\u540e\u5728\u670d\u52a1\u5668\u4e0a\u642d\u5efa\u4e86 kafka \u96c6\u7fa4\uff0c\u5728\u672c\u673a\u8fde\u63a5\u8be5\u96c6\u7fa4\uff0cproducer \u5374\u65e0\u6cd5\u53d1\u5e03\u6d88\u606f\u5230 broker\uff08\u5947\u602a\u4e5f\u6ca1\u6709\u629b\u9519\uff09\u3002\u6700\u5f00\u59cb\u6000\u7591\u662f iptables \u6ca1\u5f00\u653e\uff0c\u4e8e\u662f\u5f00\u653e\u7aef\u53e3\uff0c\u7ed3\u679c\u8fd8\u4e0d\u884c\uff08\u53c8\u5f00\u59cb\u662f\u4ee3\u7801\u95ee\u9898\u3001\u7248\u672c\u95ee\u9898\u7b49\u7b49\uff0c\u5012\u817e\u4e86\u5f88\u4e45\uff09\u3002\u6700\u540e\u6ca1\u529e\u6cd5\uff0c\u4e00\u9879\u4e00\u9879\u67e5\u770b server.properties \u914d\u7f6e\uff0c\u53d1\u73b0\u4ee5\u4e0b\u4e24\u4e2a\u914d\u7f6e\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre># The address the socket server listens on. It will get the value returned from \r\n# java.net.InetAddress.getCanonicalHostName() if not configured.\r\n#   FORMAT:\r\n#     listeners = security_protocol:\/\/host_name:port\r\n#   EXAMPLE:\r\n#     listeners = PLAINTEXT:\/\/your.host.name:9092\r\nlisteners=PLAINTEXT:\/\/:9092<\/pre>\n<p># Hostname and port the broker will advertise to producers and consumers. If not set,<br \/>\n# it uses the value for \"listeners\" if configured. Otherwise, it will use the value<br \/>\n# returned from java.net.InetAddress.getCanonicalHostName().<br \/>\n#advertised.listeners=PLAINTEXT:\/\/your.host.name:9092<\/p>\n<div class=\"cnblogs_code_toolbar\"><\/div>\n<\/div>\n<p>\u4ee5\u4e0a\u8bf4\u7684\u5c31\u662f\u00a0advertised.listeners \u662f broker \u7ed9 producer \u548c consumer \u8fde\u63a5\u4f7f\u7528\u7684\uff0c\u5982\u679c\u6ca1\u6709\u8bbe\u7f6e\uff0c\u5c31\u4f7f\u7528\u00a0listeners\uff0c\u800c\u5982\u679c host_name \u6ca1\u6709\u8bbe\u7f6e\u7684\u8bdd\uff0c\u5c31\u4f7f\u7528\u00a0java.net.InetAddress.getCanonicalHostName() \u65b9\u6cd5\u8fd4\u56de\u7684\u4e3b\u673a\u540d\u3002<\/p>\n<p>\u4fee\u6539\u65b9\u6cd5\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<pre>1. listeners=PLAINTEXT:\/\/121.10.26.XXX:9092\r\n2. advertised.listeners=PLAINTEXT:\/\/121.10.26.XXX:9092<\/pre>\n<\/div>\n<p>\u4fee\u6539\u540e\u91cd\u542f\u670d\u52a1\uff0c\u6b63\u5e38\u5de5\u4f5c\u3002<\/p>\n<\/div>\n<div id=\"MySignature\">\n<div>\u4f5c\u8005\uff1a<a href=\"http:\/\/www.cnblogs.com\/cyfonly\/\" target=\"_blank\" rel=\"noopener\">cyfonly<\/a><\/div>\n<div>\u51fa\u5904\uff1a<a href=\"http:\/\/www.cnblogs.com\/cyfonly\/\" target=\"_blank\" rel=\"noopener\">http:\/\/www.cnblogs.com\/cyfonly\/<\/a><\/div>\n<div><\/div>\n<\/div>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"https:\/\/www.chenweikang.top\">\u5de6\u624b\u4ee3\u7801\u53f3\u624b\u8bd7<\/a> &raquo; <a href=\"https:\/\/www.chenweikang.top\/?p=596\">kafka\u5b66\u4e60\u7b14\u8bb0\uff1a\u77e5\u8bc6\u70b9\u6574\u7406<\/a><\/p><div class=\"__youshang\">\r\n            <div id=\"__youshang_popup\" class=\"wechat popup\" style=\"display: none;\">\r\n                <div class=\"head\">~\u8c22\u8c22\u6253\u8d4f~<\/div>\r\n                <div class=\"qrcode\"><div class=\"qrcode-li wechat\" ><img src=\"https:\/\/www.chenweikang.top\/wp-content\/uploads\/2019\/07\/wexin.png\" \/><\/div><div class=\"qrcode-li alipay\" style=\"display:none;\"><img src=\"https:\/\/www.chenweikang.top\/wp-content\/uploads\/2019\/07\/ali-pay.png\" \/><\/div><div class=\"qrcode-li hongbao\" style=\"display:none;\"><img src=\"https:\/\/www.chenweikang.top\/wp-content\/uploads\/2019\/07\/ali-hongbao.png\" \/><\/div><\/div>\r\n                <ul class=\"platform\"><li class=\"icon-wechat active\" data-bg-color=\"#05af4e\" data-thanks=\"~\u8c22\u8c22\u6253\u8d4f~\"><\/li><li class=\"icon-alipay \" data-bg-color=\"#00a2ea\" data-thanks=\"~\u8c22\u8c22\u6253\u8d4f~\"><\/li><li class=\"icon-hongbao \" data-bg-color=\"#dd5746\" data-thanks=\"<p>\u626b\u7801\u9886\u7ea2\u5305<\/p><p style='margin-top: 24px;'>\uff08\u4f59\u989d\u5b9d\u652f\u4ed8\u65f6\u53ef\u62b5\u73b0\uff09<\/p>\"><\/li><\/ul>\r\n            <\/div>\r\n            <a href=\"javascript:void(0);\" id=\"__youshang_btn\">\u8d4f<\/a>\r\n        <\/div>","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u6d88\u606f\u7cfb\u7edf 1.\u89e3\u8026\uff1a \u3000\u3000\u5141\u8bb8\u4f60\u72ec\u7acb\u7684\u6269\u5c55\u6216\u4fee\u6539\u4e24\u8fb9\u7684\u5904\u7406\u8fc7\u7a0b\uff0c\u53ea\u8981\u786e\u4fdd\u5b83\u4eec\u9075\u5b88\u540c\u6837\u7684\u63a5\u53e3\u7ea6\u675f\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":597,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9,3],"tags":[65],"class_list":["post-596","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-houduan","category-note","tag-kafka"],"_links":{"self":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/posts\/596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=596"}],"version-history":[{"count":0,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/posts\/596\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/media\/597"}],"wp:attachment":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}