{"id":97514,"date":"2026-08-29T18:17:00","date_gmt":"2026-08-29T10:17:00","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/97514.html"},"modified":"2026-08-29T18:17:00","modified_gmt":"2026-08-29T10:17:00","slug":"%e3%80%90kafka%e8%bf%9b%e9%98%b66%e3%80%91%e9%a1%ba%e5%ba%8f%e6%b6%88%e8%b4%b9%e6%b7%b1%e5%ba%a6%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/97514.html","title":{"rendered":"\u3010Kafka\u8fdb\u96366\u3011\u987a\u5e8f\u6d88\u8d39\u6df1\u5ea6\u89e3\u6790"},"content":{"rendered":"<h3>\u4e00\u3001Kafka \u987a\u5e8f\u6d88\u8d39\u7684\u6838\u5fc3\u539f\u7406<\/h3>\n<h4>1.1  Kafka \u987a\u5e8f<\/h4>\n<p>Kafka \u7684\u987a\u5e8f\u4fdd\u8bc1\u5efa\u7acb\u5728 \u5206\u533a&#xff08;Partition&#xff09; \u8fd9\u4e00\u6838\u5fc3\u6982\u5ff5\u4e4b\u4e0a\u3002<\/p>\n<p>#mermaid-svg-QyLvdSLBaEhapjAN{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-QyLvdSLBaEhapjAN .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-QyLvdSLBaEhapjAN .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-QyLvdSLBaEhapjAN .error-icon{fill:#552222;}#mermaid-svg-QyLvdSLBaEhapjAN .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-QyLvdSLBaEhapjAN .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-QyLvdSLBaEhapjAN .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-QyLvdSLBaEhapjAN .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-QyLvdSLBaEhapjAN .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-QyLvdSLBaEhapjAN .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-QyLvdSLBaEhapjAN .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-QyLvdSLBaEhapjAN .marker{fill:#333333;stroke:#333333;}#mermaid-svg-QyLvdSLBaEhapjAN .marker.cross{stroke:#333333;}#mermaid-svg-QyLvdSLBaEhapjAN svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-QyLvdSLBaEhapjAN p{margin:0;}#mermaid-svg-QyLvdSLBaEhapjAN .label{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;color:#333;}#mermaid-svg-QyLvdSLBaEhapjAN .cluster-label text{fill:#333;}#mermaid-svg-QyLvdSLBaEhapjAN .cluster-label span{color:#333;}#mermaid-svg-QyLvdSLBaEhapjAN .cluster-label span p{background-color:transparent;}#mermaid-svg-QyLvdSLBaEhapjAN .label text,#mermaid-svg-QyLvdSLBaEhapjAN span{fill:#333;color:#333;}#mermaid-svg-QyLvdSLBaEhapjAN .node rect,#mermaid-svg-QyLvdSLBaEhapjAN .node circle,#mermaid-svg-QyLvdSLBaEhapjAN .node ellipse,#mermaid-svg-QyLvdSLBaEhapjAN .node polygon,#mermaid-svg-QyLvdSLBaEhapjAN .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-QyLvdSLBaEhapjAN .rough-node .label text,#mermaid-svg-QyLvdSLBaEhapjAN .node .label text,#mermaid-svg-QyLvdSLBaEhapjAN .image-shape .label,#mermaid-svg-QyLvdSLBaEhapjAN .icon-shape .label{text-anchor:middle;}#mermaid-svg-QyLvdSLBaEhapjAN .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-QyLvdSLBaEhapjAN .rough-node .label,#mermaid-svg-QyLvdSLBaEhapjAN .node .label,#mermaid-svg-QyLvdSLBaEhapjAN .image-shape .label,#mermaid-svg-QyLvdSLBaEhapjAN .icon-shape .label{text-align:center;}#mermaid-svg-QyLvdSLBaEhapjAN .node.clickable{cursor:pointer;}#mermaid-svg-QyLvdSLBaEhapjAN .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-QyLvdSLBaEhapjAN .arrowheadPath{fill:#333333;}#mermaid-svg-QyLvdSLBaEhapjAN .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-QyLvdSLBaEhapjAN .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-QyLvdSLBaEhapjAN .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-QyLvdSLBaEhapjAN .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-QyLvdSLBaEhapjAN .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-QyLvdSLBaEhapjAN .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-QyLvdSLBaEhapjAN .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-QyLvdSLBaEhapjAN .cluster text{fill:#333;}#mermaid-svg-QyLvdSLBaEhapjAN .cluster span{color:#333;}#mermaid-svg-QyLvdSLBaEhapjAN div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-QyLvdSLBaEhapjAN .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-QyLvdSLBaEhapjAN rect.text{fill:none;stroke-width:0;}#mermaid-svg-QyLvdSLBaEhapjAN .icon-shape,#mermaid-svg-QyLvdSLBaEhapjAN .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-QyLvdSLBaEhapjAN .icon-shape p,#mermaid-svg-QyLvdSLBaEhapjAN .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-QyLvdSLBaEhapjAN .icon-shape .label rect,#mermaid-svg-QyLvdSLBaEhapjAN .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-QyLvdSLBaEhapjAN .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-QyLvdSLBaEhapjAN .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-QyLvdSLBaEhapjAN :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<span class=\"nodeLabel\"><\/p>\n<p>\u6d88\u8d39\u8005\u7ec4<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u751f\u4ea7\u8005<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>Topic: ORDER_TOPIC<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/span><span class=\"edgeLabel\"><\/p>\n<p>\u76f8\u540cKey \u2192 \u540c\u4e00\u5206\u533a<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/p>\n<p>\u76f8\u540cKey \u2192 \u540c\u4e00\u5206\u533a<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/p>\n<p>\u72ec\u5360\u6d88\u8d39<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/p>\n<p>\u72ec\u5360\u6d88\u8d39<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/p>\n<p>\u72ec\u5360\u6d88\u8d39<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/p>\n<p>\u72ec\u5360\u6d88\u8d39<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>Partition 0<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>Partition 1<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>Partition 2<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>Partition 3<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u8ba2\u5355ID\u4f5c\u4e3aKey<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u54c8\u5e0c\u53d6\u6a21<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>Consumer 1\u6d88\u8d39 Partition 0,1<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>Consumer 2\u6d88\u8d39 Partition 2,3<\/p>\n<p><\/span><\/p>\n<p>Kafka \u63d0\u4f9b\u7684\u987a\u5e8f\u4fdd\u8bc1&#xff1a;<\/p>\n<table>\n<tr>\u4fdd\u8bc1\u9879\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u2705 \u751f\u4ea7\u8005\u987a\u5e8f<\/td>\n<td>\u540c\u4e00\u751f\u4ea7\u8005\u53d1\u9001\u5230\u540c\u4e00\u5206\u533a\u7684\u6d88\u606f&#xff0c;\u6309\u53d1\u9001\u987a\u5e8f\u8ffd\u52a0<\/td>\n<\/tr>\n<tr>\n<td>\u2705 \u6d88\u8d39\u8005\u987a\u5e8f<\/td>\n<td>\u6d88\u8d39\u8005\u5b9e\u4f8b\u6309\u6d88\u606f\u5728\u65e5\u5fd7\u4e2d\u7684\u987a\u5e8f\u8bfb\u53d6<\/td>\n<\/tr>\n<tr>\n<td>\u2705 \u5206\u533a\u72ec\u5360<\/td>\n<td>\u6bcf\u4e2a\u5206\u533a\u5728\u540c\u4e00\u6d88\u8d39\u8005\u7ec4\u5185\u53ea\u80fd\u88ab\u4e00\u4e2a\u6d88\u8d39\u8005\u6d88\u8d39<\/td>\n<\/tr>\n<tr>\n<td>\u274c \u4e0d\u4fdd\u8bc1\u5168\u5c40<\/td>\n<td>\u4e0d\u540c\u5206\u533a\u4e4b\u95f4\u4e0d\u4fdd\u8bc1\u5168\u5c40\u987a\u5e8f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&#x1f4a1; \u6838\u5fc3\u7ed3\u8bba&#xff1a;Kafka \u53ea\u4fdd\u8bc1\u5206\u533a\u5185\u6709\u5e8f&#xff0c;\u4e0d\u4fdd\u8bc1\u5168\u5c40\u6709\u5e8f\u3002<\/p>\n<h4>1.2 \u5b9e\u73b0\u987a\u5e8f\u6d88\u8d39\u7684\u5173\u952e\u6b65\u9aa4<\/h4>\n<p>#mermaid-svg-W5zGM2Wu1EXevELf{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-W5zGM2Wu1EXevELf .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-W5zGM2Wu1EXevELf .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-W5zGM2Wu1EXevELf .error-icon{fill:#552222;}#mermaid-svg-W5zGM2Wu1EXevELf .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-W5zGM2Wu1EXevELf .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-W5zGM2Wu1EXevELf .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-W5zGM2Wu1EXevELf .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-W5zGM2Wu1EXevELf .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-W5zGM2Wu1EXevELf .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-W5zGM2Wu1EXevELf .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-W5zGM2Wu1EXevELf .marker{fill:#333333;stroke:#333333;}#mermaid-svg-W5zGM2Wu1EXevELf .marker.cross{stroke:#333333;}#mermaid-svg-W5zGM2Wu1EXevELf svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-W5zGM2Wu1EXevELf p{margin:0;}#mermaid-svg-W5zGM2Wu1EXevELf .label{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;color:#333;}#mermaid-svg-W5zGM2Wu1EXevELf .cluster-label text{fill:#333;}#mermaid-svg-W5zGM2Wu1EXevELf .cluster-label span{color:#333;}#mermaid-svg-W5zGM2Wu1EXevELf .cluster-label span p{background-color:transparent;}#mermaid-svg-W5zGM2Wu1EXevELf .label text,#mermaid-svg-W5zGM2Wu1EXevELf span{fill:#333;color:#333;}#mermaid-svg-W5zGM2Wu1EXevELf .node rect,#mermaid-svg-W5zGM2Wu1EXevELf .node circle,#mermaid-svg-W5zGM2Wu1EXevELf .node ellipse,#mermaid-svg-W5zGM2Wu1EXevELf .node polygon,#mermaid-svg-W5zGM2Wu1EXevELf .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-W5zGM2Wu1EXevELf .rough-node .label text,#mermaid-svg-W5zGM2Wu1EXevELf .node .label text,#mermaid-svg-W5zGM2Wu1EXevELf .image-shape .label,#mermaid-svg-W5zGM2Wu1EXevELf .icon-shape .label{text-anchor:middle;}#mermaid-svg-W5zGM2Wu1EXevELf .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-W5zGM2Wu1EXevELf .rough-node .label,#mermaid-svg-W5zGM2Wu1EXevELf .node .label,#mermaid-svg-W5zGM2Wu1EXevELf .image-shape .label,#mermaid-svg-W5zGM2Wu1EXevELf .icon-shape .label{text-align:center;}#mermaid-svg-W5zGM2Wu1EXevELf .node.clickable{cursor:pointer;}#mermaid-svg-W5zGM2Wu1EXevELf .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-W5zGM2Wu1EXevELf .arrowheadPath{fill:#333333;}#mermaid-svg-W5zGM2Wu1EXevELf .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-W5zGM2Wu1EXevELf .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-W5zGM2Wu1EXevELf .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-W5zGM2Wu1EXevELf .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-W5zGM2Wu1EXevELf .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-W5zGM2Wu1EXevELf .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-W5zGM2Wu1EXevELf .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-W5zGM2Wu1EXevELf .cluster text{fill:#333;}#mermaid-svg-W5zGM2Wu1EXevELf .cluster span{color:#333;}#mermaid-svg-W5zGM2Wu1EXevELf div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-W5zGM2Wu1EXevELf .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-W5zGM2Wu1EXevELf rect.text{fill:none;stroke-width:0;}#mermaid-svg-W5zGM2Wu1EXevELf .icon-shape,#mermaid-svg-W5zGM2Wu1EXevELf .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-W5zGM2Wu1EXevELf .icon-shape p,#mermaid-svg-W5zGM2Wu1EXevELf .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-W5zGM2Wu1EXevELf .icon-shape .label rect,#mermaid-svg-W5zGM2Wu1EXevELf .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-W5zGM2Wu1EXevELf .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-W5zGM2Wu1EXevELf .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-W5zGM2Wu1EXevELf :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<span class=\"edgeLabel\"><\/span><span class=\"edgeLabel\"><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u2462 \u63d0\u4ea4\u65b9\u5f0f<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u624b\u52a8\u63d0\u4ea4 Offset<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u4e1a\u52a1\u5904\u7406\u5b8c\u6210\u540e\u518d\u63d0\u4ea4<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u2461 \u6d88\u8d39\u7aef<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u6d88\u8d39\u8005\u7ebf\u7a0b\u6570&#061; \u5206\u533a\u6570<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u6bcf\u4e2a\u5206\u533a\u72ec\u5360\u4e00\u4e2a\u7ebf\u7a0b<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u2460 \u751f\u4ea7\u7aef<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u6307\u5b9a Key<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u76f8\u540c Key\u54c8\u5e0c\u5230\u540c\u4e00\u5206\u533a<\/p>\n<p><\/span><\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u6838\u5fc3\u4ee3\u7801\u5b9e\u73b0 &#x1f4bb;<\/h3>\n<h4>2.1 \u751f\u4ea7\u8005\u7aef\u2014\u2014\u6307\u5b9a Key \u8def\u7531\u5230\u540c\u4e00\u5206\u533a<\/h4>\n<p><span class=\"token annotation punctuation\">&#064;Service<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">KafkaOrderProducer<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Autowired<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token class-name\">KafkaTemplate<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">String<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> kafkaTemplate<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/**<br \/>\n     * \u53d1\u9001\u987a\u5e8f\u6d88\u606f<br \/>\n     * &#064;param orderId \u8ba2\u5355ID&#xff08;\u4f5c\u4e3aKey&#xff0c;\u4fdd\u8bc1\u540c\u4e00\u8ba2\u5355\u8fdb\u5165\u540c\u4e00\u5206\u533a&#xff09;<br \/>\n     * &#064;param messageBody \u6d88\u606f\u4f53<br \/>\n     *\/<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">sendOrderlyMessage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Long<\/span> orderId<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">String<\/span> messageBody<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u2705 \u6280\u672f\u4eae\u70b9&#xff1a;\u6307\u5b9a Key&#xff0c;Kafka \u9ed8\u8ba4\u6309 Key \u54c8\u5e0c\u5206\u914d\u5230\u540c\u4e00\u4e2a Partition<\/span><br \/>\n        <span class=\"token comment\">\/\/ Kafka \u4f7f\u7528 MurmurHash2 \u7b97\u6cd5\u5bf9 Key \u8fdb\u884c\u54c8\u5e0c&#xff0c;\u4e0e\u5206\u533a\u6570\u53d6\u6a21\u51b3\u5b9a\u76ee\u6807\u5206\u533a<\/span><br \/>\n        kafkaTemplate<span class=\"token punctuation\">.<\/span><span class=\"token function\">send<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;ORDER_TOPIC&#034;<\/span><span class=\"token punctuation\">,<\/span> orderId<span class=\"token punctuation\">.<\/span><span class=\"token function\">toString<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> messageBody<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>&#x1f4cc; \u539f\u7406\u8865\u5145&#xff1a;\u5f53\u6d88\u606f\u6307\u5b9a\u4e86 Key \u65f6&#xff0c;Kafka \u4f7f\u7528\u786e\u5b9a\u6027\u54c8\u5e0c\u51fd\u6570&#xff08;MurmurHash2&#xff09;\u5c06 Key \u6620\u5c04\u5230\u56fa\u5b9a\u5206\u533a\u3002\u76f8\u540c Key \u7684\u6d88\u606f\u59cb\u7ec8\u8fdb\u5165\u540c\u4e00\u5206\u533a&#xff0c;\u4ece\u800c\u4fdd\u8bc1\u987a\u5e8f\u3002<\/p>\n<h4>2.2 \u6d88\u8d39\u8005\u7aef\u2014\u2014\u7ebf\u7a0b\u6570 &#061; \u5206\u533a\u6570<\/h4>\n<p><span class=\"token annotation punctuation\">&#064;Component<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">KafkaOrderConsumer<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">final<\/span> <span class=\"token class-name\">Logger<\/span> log <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">LoggerFactory<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">getLogger<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">KafkaOrderConsumer<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Autowired<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token class-name\">OrderService<\/span> orderService<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/**<br \/>\n     * \u987a\u5e8f\u6d88\u8d39\u6d88\u606f<br \/>\n     * \u26a0\ufe0f \u5173\u952e&#xff1a;concurrency \u5fc5\u987b\u7b49\u4e8e Topic \u7684 Partition \u6570<br \/>\n     * \u6bcf\u4e2a\u5206\u533a\u53ea\u80fd\u88ab\u4e00\u4e2a\u6d88\u8d39\u8005\u7ebf\u7a0b\u6d88\u8d39<br \/>\n     *\/<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;KafkaListener<\/span><span class=\"token punctuation\">(<\/span><br \/>\n        topics <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;ORDER_TOPIC&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        groupId <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;ORDER_CONSUMER_GROUP&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        concurrency <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;8&#034;<\/span>  <span class=\"token comment\">\/\/ \u7ebf\u7a0b\u6570 &#061; \u5206\u533a\u6570<\/span><br \/>\n    <span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">consumeMessage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">ConsumerRecord<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">String<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> record<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">Long<\/span> orderId <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">Long<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">parseLong<\/span><span class=\"token punctuation\">(<\/span>record<span class=\"token punctuation\">.<\/span><span class=\"token function\">key<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">String<\/span> messageBody <span class=\"token operator\">&#061;<\/span> record<span class=\"token punctuation\">.<\/span><span class=\"token function\">value<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        log<span class=\"token punctuation\">.<\/span><span class=\"token function\">info<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;&#x1f4e8; Kafka\u987a\u5e8f\u6d88\u8d39\u6d88\u606f&#xff0c;\u8ba2\u5355ID&#xff1a;{}&#xff0c;\u5206\u533a&#xff1a;{}&#xff0c;\u504f\u79fb\u91cf&#xff1a;{}&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                 orderId<span class=\"token punctuation\">,<\/span> record<span class=\"token punctuation\">.<\/span><span class=\"token function\">partition<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> record<span class=\"token punctuation\">.<\/span><span class=\"token function\">offset<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>        <span class=\"token comment\">\/\/ \u4e1a\u52a1\u903b\u8f91\u5904\u7406<\/span><br \/>\n        orderService<span class=\"token punctuation\">.<\/span><span class=\"token function\">processOrderMessage<\/span><span class=\"token punctuation\">(<\/span>orderId<span class=\"token punctuation\">,<\/span> messageBody<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u26a0\ufe0f \u91cd\u8981\u9650\u5236&#xff1a;\u6d88\u8d39\u8005\u7ec4\u5185\u7684\u6d88\u8d39\u8005\u5b9e\u4f8b\u6570\u4e0d\u80fd\u8d85\u8fc7\u5206\u533a\u6570&#xff0c;\u5426\u5219\u591a\u4f59\u7684\u6d88\u8d39\u8005\u5c06\u5904\u4e8e\u7a7a\u95f2\u72b6\u6001\u3002<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u6280\u672f\u96be\u70b9\u4e0e\u89e3\u51b3\u65b9\u6848 &#x1f6e1;\ufe0f<\/h3>\n<h4>3.1 \u6280\u672f\u96be\u70b9\u5168\u666f\u56fe<\/h4>\n<table>\n<tr>\u6280\u672f\u96be\u70b9\u63cf\u8ff0\u89e3\u51b3\u65b9\u6848\u5bf9\u5e94\u914d\u7f6e\/\u4ee3\u7801<\/tr>\n<tbody>\n<tr>\n<td>\u5206\u533a\u9009\u62e9\u4e0e\u8d1f\u8f7d\u5747\u8861<\/td>\n<td>\u5982\u4f55\u4fdd\u8bc1\u540c\u4e00\u8ba2\u5355\u8fdb\u540c\u4e00\u961f\u5217&#xff0c;\u540c\u65f6\u4e0d\u540c\u8ba2\u5355\u5747\u5300\u5206\u5e03&#xff1f;<\/td>\n<td>\u8ba2\u5355ID\u54c8\u5e0c\u53d6\u6a21\u9009\u5206\u533a&#xff1b;\u6d88\u8d39\u8005\u7aef\u91c7\u7528\u96c6\u7fa4\u6a21\u5f0f&#xff0c;\u5206\u533a\u5747\u5300\u5206\u914d<\/td>\n<td>\u751f\u4ea7\u8005\u6307\u5b9a orderId.toString() \u4f5c\u4e3a Key<\/td>\n<\/tr>\n<tr>\n<td>\u6d88\u8d39\u5931\u8d25\u961f\u5934\u963b\u585e &#x1f534;<\/td>\n<td>\u67d0\u6761\u6d88\u606f\u5931\u8d25&#xff0c;\u540e\u7eed\u6d88\u606f\u5168\u90e8\u7b49\u5f85&#xff0c;\u961f\u5217\u5835\u585e<\/td>\n<td>\u72b6\u6001\u673a\u4e50\u89c2\u9501\u6821\u9a8c &#043; \u6700\u5927\u91cd\u8bd5\u6b21\u6570 &#043; \u6b7b\u4fe1\u515c\u5e95<\/td>\n<td>\u6d88\u8d39\u8005\u8fdb\u9636\u7248\u4ee3\u7801&#xff08;\u89c1\u4e0b\u6587&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>Rebalance \u5bfc\u81f4\u77ed\u6682\u4e71\u5e8f<\/td>\n<td>Kafka \u6d88\u8d39\u8005\u7ec4\u91cd\u5e73\u8861\u65f6\u5206\u533a\u6f02\u79fb&#xff0c;\u77ed\u65f6\u95f4\u53ef\u80fd\u4e71\u5e8f<\/td>\n<td>\u589e\u5927 session.timeout.ms&#xff1b;\u4f7f\u7528\u9759\u6001\u7ec4ID&#xff1b;\u914d\u5408\u4e1a\u52a1\u5e42\u7b49\u5bb9\u5fcd\u77ed\u6682\u91cd\u590d<\/td>\n<td>session.timeout.ms&#061;30000group.instance.id \u56fa\u5b9a<\/td>\n<\/tr>\n<tr>\n<td>\u91cd\u590d\u6d88\u606f\u7834\u574f\u5e42\u7b49\u6027<\/td>\n<td>\u987a\u5e8f\u6d88\u8d39\u4e0d\u80fd\u9632\u6b62\u751f\u4ea7\u8005\u91cd\u8bd5\u9020\u6210\u7684\u91cd\u590d\u6d88\u606f<\/td>\n<td>\u6d88\u606f\u4f53\u5e26\u4e1a\u52a1\u6d41\u6c34\u53f7&#xff0c;\u6d88\u8d39\u524d\u901a\u8fc7 DB \u552f\u4e00\u952e \/ Redis \u9501\u53bb\u91cd<\/td>\n<td>\u552f\u4e00\u7d22\u5f15&#xff1a;uk_order_event_id<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>3.2 Rebalance \u4e71\u5e8f\u95ee\u9898\u6df1\u5ea6\u89e3\u6790<\/h4>\n<p>BrokerConsumer 2(\u65b0\u52a0\u5165)Group CoordinatorConsumer 1(\u6d88\u8d39 P0)BrokerConsumer 2(\u65b0\u52a0\u5165)Group CoordinatorConsumer 1(\u6d88\u8d39 P0)#mermaid-svg-NSxYG8cWSFJLqChg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-NSxYG8cWSFJLqChg .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-NSxYG8cWSFJLqChg .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-NSxYG8cWSFJLqChg .error-icon{fill:#552222;}#mermaid-svg-NSxYG8cWSFJLqChg .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-NSxYG8cWSFJLqChg .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-NSxYG8cWSFJLqChg .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-NSxYG8cWSFJLqChg .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-NSxYG8cWSFJLqChg .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-NSxYG8cWSFJLqChg .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-NSxYG8cWSFJLqChg .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-NSxYG8cWSFJLqChg .marker{fill:#333333;stroke:#333333;}#mermaid-svg-NSxYG8cWSFJLqChg .marker.cross{stroke:#333333;}#mermaid-svg-NSxYG8cWSFJLqChg svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-NSxYG8cWSFJLqChg p{margin:0;}#mermaid-svg-NSxYG8cWSFJLqChg .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-NSxYG8cWSFJLqChg text.actor&gt;tspan{fill:black;stroke:none;}#mermaid-svg-NSxYG8cWSFJLqChg .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-NSxYG8cWSFJLqChg .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-NSxYG8cWSFJLqChg .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-NSxYG8cWSFJLqChg .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-NSxYG8cWSFJLqChg #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-NSxYG8cWSFJLqChg .sequenceNumber{fill:white;}#mermaid-svg-NSxYG8cWSFJLqChg #sequencenumber{fill:#333;}#mermaid-svg-NSxYG8cWSFJLqChg #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-NSxYG8cWSFJLqChg .messageText{fill:#333;stroke:none;}#mermaid-svg-NSxYG8cWSFJLqChg .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-NSxYG8cWSFJLqChg .labelText,#mermaid-svg-NSxYG8cWSFJLqChg .labelText&gt;tspan{fill:black;stroke:none;}#mermaid-svg-NSxYG8cWSFJLqChg .loopText,#mermaid-svg-NSxYG8cWSFJLqChg .loopText&gt;tspan{fill:black;stroke:none;}#mermaid-svg-NSxYG8cWSFJLqChg .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-NSxYG8cWSFJLqChg .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-NSxYG8cWSFJLqChg .noteText,#mermaid-svg-NSxYG8cWSFJLqChg .noteText&gt;tspan{fill:black;stroke:none;}#mermaid-svg-NSxYG8cWSFJLqChg .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-NSxYG8cWSFJLqChg .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-NSxYG8cWSFJLqChg .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-NSxYG8cWSFJLqChg .actorPopupMenu{position:absolute;}#mermaid-svg-NSxYG8cWSFJLqChg .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 \/ 0.4));}#mermaid-svg-NSxYG8cWSFJLqChg .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-NSxYG8cWSFJLqChg .actor-man circle,#mermaid-svg-NSxYG8cWSFJLqChg line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-NSxYG8cWSFJLqChg :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}\u6b63\u5728\u6d88\u8d39 P0&#xff0c;\u504f\u79fb\u91cf 100\u26a0\ufe0f \u53ef\u80fd\u4ece\u504f\u79fb\u91cf 90 \u5f00\u59cb\u5bfc\u81f4\u77ed\u6682\u91cd\u590d\u6d88\u8d39\u2705 \u89e3\u51b3\u65b9\u6848&#xff1a;1. \u589e\u5927 session.timeout.ms2. \u4f7f\u7528\u9759\u6001\u7ec4ID&#xff08;group.instance.id&#xff09;3. \u4e1a\u52a1\u5c42\u5e42\u7b49\u515c\u5e95\u274c \u5fc3\u8df3\u8d85\u65f6\u89e6\u53d1 Rebalance\u5206\u914d P0\u4ece\u4e0a\u6b21\u63d0\u4ea4\u504f\u79fb\u91cf\u5f00\u59cb\u6d88\u8d39<\/p>\n<p>&#x1f4a1; Rebalance \u5e76\u4e0d\u4f1a\u7834\u574f\u5206\u533a\u5185\u7684\u987a\u5e8f&#xff0c;\u4f46\u53ef\u80fd\u5bfc\u81f4&#xff1a;<\/p>\n<ul>\n<li>\u91cd\u590d\u6d88\u8d39&#xff1a;\u65b0\u6d88\u8d39\u8005\u4ece\u4e0a\u6b21\u63d0\u4ea4\u7684\u504f\u79fb\u91cf\u5f00\u59cb&#xff0c;\u53ef\u80fd\u91cd\u590d\u6d88\u8d39\u5df2\u5904\u7406\u4f46\u672a\u63d0\u4ea4\u7684\u6d88\u606f<\/li>\n<li>\u77ed\u6682\u5904\u7406\u4e2d\u65ad&#xff1a;\u91cd\u5e73\u8861\u671f\u95f4\u6d88\u8d39\u6682\u505c<\/li>\n<\/ul>\n<hr \/>\n<h3>\u56db\u3001\u961f\u5934\u963b\u585e\u95ee\u9898\u4e0e\u5e94\u5bf9\u7b56\u7565 &#x1f9e9;<\/h3>\n<p>\u201c\u8fd9\u6b63\u662f\u961f\u5934\u963b\u585e\u95ee\u9898&#xff0c;\u9762\u8bd5\u5b98\u60a8\u95ee\u5230\u70b9\u4e0a\u4e86 &#x1f913;\u3002\u6211\u4eec\u6709\u51e0\u5957\u7b56\u7565&#xff0c;\u6839\u636e\u4e1a\u52a1\u4e25\u91cd\u6027\u9009\u62e9&#xff1a;\u201d<\/p>\n<h4>4.1 \u4e09\u79cd\u5e94\u5bf9\u7b56\u7565\u5bf9\u6bd4<\/h4>\n<table>\n<tr>\u7b56\u7565\u505a\u6cd5\u5229\u5f0a\u9002\u7528\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td>\u963b\u585e &#043; \u9884\u8b66 &#x1f6a8;<\/td>\n<td>\u5f53\u524d\u6d88\u606f\u53cd\u590d\u91cd\u8bd5\u76f4\u5230\u6210\u529f&#xff0c;\u540e\u7eed\u6d88\u606f\u7b49\u5f85<\/td>\n<td>\u2705 \u5f3a\u4e00\u81f4\u274c \u5f71\u54cd\u5ef6\u8fdf&#xff0c;\u5fc5\u987b\u914d\u4e0a\u76d1\u63a7\u544a\u8b66<\/td>\n<td>\u91d1\u878d\u652f\u4ed8\u3001\u5e93\u5b58\u6263\u51cf\u7b49\u5f3a\u4e00\u81f4\u6027\u573a\u666f<\/td>\n<\/tr>\n<tr>\n<td>\u8df3\u6b7b\u4fe1 &#043; \u4eba\u5de5\u4ecb\u5165<\/td>\n<td>\u5931\u8d25N\u6b21\u540e\u8f6c\u5165\u6b7b\u4fe1\u961f\u5217&#xff0c;\u4eba\u5de5\u4fee\u590d\u6570\u636e\u540e\u56de\u8c03<\/td>\n<td>\u2705 \u5141\u8bb8\u6682\u65f6\u8df3\u8fc7\u2705 \u4fdd\u8bc1\u6700\u7ec8\u4e00\u81f4\u274c \u9700\u8981\u4eba\u5de5\u4ecb\u5165<\/td>\n<td>\u591a\u6570\u975e\u81f4\u547d\u4e1a\u52a1<\/td>\n<\/tr>\n<tr>\n<td>\u4e1a\u52a1\u72b6\u6001\u673a\u6821\u9a8c<\/td>\n<td>\u6d88\u606f\u4f53\u5e26\u524d\u7f6e\u72b6\u6001&#xff0c;\u6d88\u8d39\u65f6\u505a\u4e50\u89c2\u9501\u6821\u9a8c&#xff0c;\u72b6\u6001\u4e0d\u5bf9\u76f4\u63a5\u5ffd\u7565\u6216\u4e22\u5f03<\/td>\n<td>\u2705 \u66f4\u7075\u6d3b\u274c \u4e1a\u52a1\u4ee3\u7801\u6709\u4fb5\u5165\u6027<\/td>\n<td>\u8ba2\u5355\u6d41\u8f6c\u7b49\u6709\u660e\u786e\u72b6\u6001\u673a\u7684\u573a\u666f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>4.2 \u8ba2\u5355\u573a\u666f\u63a8\u8350\u65b9\u6848&#xff1a;\u72b6\u6001\u673a\u6821\u9a8c &#043; \u6b7b\u4fe1\u515c\u5e95<\/h4>\n<p>#mermaid-svg-b8lDUgjAXNjLf0d9{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-b8lDUgjAXNjLf0d9 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-b8lDUgjAXNjLf0d9 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-b8lDUgjAXNjLf0d9 .error-icon{fill:#552222;}#mermaid-svg-b8lDUgjAXNjLf0d9 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-b8lDUgjAXNjLf0d9 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-b8lDUgjAXNjLf0d9 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-b8lDUgjAXNjLf0d9 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-b8lDUgjAXNjLf0d9 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-b8lDUgjAXNjLf0d9 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-b8lDUgjAXNjLf0d9 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-b8lDUgjAXNjLf0d9 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-b8lDUgjAXNjLf0d9 .marker.cross{stroke:#333333;}#mermaid-svg-b8lDUgjAXNjLf0d9 svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-b8lDUgjAXNjLf0d9 p{margin:0;}#mermaid-svg-b8lDUgjAXNjLf0d9 .label{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;color:#333;}#mermaid-svg-b8lDUgjAXNjLf0d9 .cluster-label text{fill:#333;}#mermaid-svg-b8lDUgjAXNjLf0d9 .cluster-label span{color:#333;}#mermaid-svg-b8lDUgjAXNjLf0d9 .cluster-label span p{background-color:transparent;}#mermaid-svg-b8lDUgjAXNjLf0d9 .label text,#mermaid-svg-b8lDUgjAXNjLf0d9 span{fill:#333;color:#333;}#mermaid-svg-b8lDUgjAXNjLf0d9 .node rect,#mermaid-svg-b8lDUgjAXNjLf0d9 .node circle,#mermaid-svg-b8lDUgjAXNjLf0d9 .node ellipse,#mermaid-svg-b8lDUgjAXNjLf0d9 .node polygon,#mermaid-svg-b8lDUgjAXNjLf0d9 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-b8lDUgjAXNjLf0d9 .rough-node .label text,#mermaid-svg-b8lDUgjAXNjLf0d9 .node .label text,#mermaid-svg-b8lDUgjAXNjLf0d9 .image-shape .label,#mermaid-svg-b8lDUgjAXNjLf0d9 .icon-shape .label{text-anchor:middle;}#mermaid-svg-b8lDUgjAXNjLf0d9 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-b8lDUgjAXNjLf0d9 .rough-node .label,#mermaid-svg-b8lDUgjAXNjLf0d9 .node .label,#mermaid-svg-b8lDUgjAXNjLf0d9 .image-shape .label,#mermaid-svg-b8lDUgjAXNjLf0d9 .icon-shape .label{text-align:center;}#mermaid-svg-b8lDUgjAXNjLf0d9 .node.clickable{cursor:pointer;}#mermaid-svg-b8lDUgjAXNjLf0d9 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-b8lDUgjAXNjLf0d9 .arrowheadPath{fill:#333333;}#mermaid-svg-b8lDUgjAXNjLf0d9 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-b8lDUgjAXNjLf0d9 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-b8lDUgjAXNjLf0d9 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-b8lDUgjAXNjLf0d9 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-b8lDUgjAXNjLf0d9 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-b8lDUgjAXNjLf0d9 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-b8lDUgjAXNjLf0d9 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-b8lDUgjAXNjLf0d9 .cluster text{fill:#333;}#mermaid-svg-b8lDUgjAXNjLf0d9 .cluster span{color:#333;}#mermaid-svg-b8lDUgjAXNjLf0d9 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-b8lDUgjAXNjLf0d9 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-b8lDUgjAXNjLf0d9 rect.text{fill:none;stroke-width:0;}#mermaid-svg-b8lDUgjAXNjLf0d9 .icon-shape,#mermaid-svg-b8lDUgjAXNjLf0d9 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-b8lDUgjAXNjLf0d9 .icon-shape p,#mermaid-svg-b8lDUgjAXNjLf0d9 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-b8lDUgjAXNjLf0d9 .icon-shape .label rect,#mermaid-svg-b8lDUgjAXNjLf0d9 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-b8lDUgjAXNjLf0d9 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-b8lDUgjAXNjLf0d9 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-b8lDUgjAXNjLf0d9 :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<span class=\"edgeLabel\"><\/span><span class=\"edgeLabel\"><\/p>\n<p>\u72b6\u6001\u5339\u914d<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/p>\n<p>\u72b6\u6001\u4e0d\u5339\u914d<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/span><span class=\"edgeLabel\"><\/p>\n<p>\u5426<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/p>\n<p>\u662f<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/span><span class=\"edgeLabel\"><\/span><span class=\"edgeLabel\"><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u6d88\u606f\u5230\u8fbe<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u72b6\u6001\u6821\u9a8c<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u6267\u884c\u4e1a\u52a1\u903b\u8f91<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u91cd\u8bd5\u6b21\u6570\u662f\u5426\u8d85\u9650&#xff1f;<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u2705 \u6d88\u8d39\u6210\u529f\u63d0\u4ea4 Offset<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u23f3 \u91cd\u8bd5&#xff08;\u5ef6\u8fdf\u540e\u91cd\u65b0\u5165\u961f&#xff09;<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>&#x1f4e5; \u8f6c\u5165\u6b7b\u4fe1\u961f\u5217<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>&#x1f468;\u200d&#x1f4bb; \u4eba\u5de5\u4ecb\u5165\u4fee\u590d\u6570\u636e\u540e\u56de\u8c03<\/p>\n<p><\/span><\/p>\n<p>\u6838\u5fc3\u601d\u8def&#xff1a;\u6d88\u606f\u4f53\u91cc\u5e26\u524d\u7f6e\u72b6\u6001&#xff0c;\u6d88\u8d39\u65f6\u505a\u4e50\u89c2\u9501\u6821\u9a8c\u3002<\/p>\n<p><span class=\"token comment\">&#8212; \u2705 \u652f\u4ed8\u6d88\u606f\u793a\u4f8b&#xff1a;\u671f\u671b\u524d\u7f6e\u72b6\u6001\u4e3a&#034;\u5f85\u652f\u4ed8&#034;<\/span><br \/>\n<span class=\"token keyword\">UPDATE<\/span> <span class=\"token keyword\">order<\/span><br \/>\n<span class=\"token keyword\">SET<\/span> <span class=\"token keyword\">status<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;\u5df2\u652f\u4ed8&#039;<\/span><br \/>\n<span class=\"token keyword\">WHERE<\/span> id <span class=\"token operator\">&#061;<\/span> <span class=\"token comment\">#{orderId} <\/span><br \/>\n  <span class=\"token operator\">AND<\/span> <span class=\"token keyword\">status<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;\u5f85\u652f\u4ed8&#039;<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">&#8212; \u4e50\u89c2\u9501\u6761\u4ef6<\/span><\/p>\n<p>&#x1f4cc; \u4e3a\u4ec0\u4e48\u8fd9\u6837\u6709\u6548&#xff1f;<\/p>\n<ul>\n<li>\u5982\u679c\u72b6\u6001\u5df2\u662f \u5df2\u53d6\u6d88&#xff0c;UPDATE \u5f71\u54cd\u884c\u6570\u4e3a 0&#xff0c;\u76f4\u63a5 ACK \u6216\u79fb\u5165\u6b7b\u4fe1<\/li>\n<li>\u5373\u4f7f\u5386\u53f2\u6d88\u606f\u91cd\u653e&#xff0c;\u4e5f\u4e0d\u4f1a\u6253\u4e71\u6700\u7ec8\u7ed3\u679c<\/li>\n<li>\u5929\u7136\u5e42\u7b49&#xff0c;\u65e0\u9700\u989d\u5916\u53bb\u91cd\u903b\u8f91<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e94\u3001\u5e42\u7b49\u6027\u4fdd\u969c\u2014\u2014\u9632\u6b62\u91cd\u590d\u6d88\u606f &#x1f4aa;<\/h3>\n<h4>5.1 \u91cd\u590d\u6d88\u606f\u7684\u6765\u6e90<\/h4>\n<table>\n<tr>\u6765\u6e90\u539f\u56e0\u5f71\u54cd<\/tr>\n<tbody>\n<tr>\n<td>\u751f\u4ea7\u8005\u91cd\u8bd5<\/td>\n<td>\u7f51\u7edc\u8d85\u65f6\u5bfc\u81f4 Producer \u91cd\u53d1<\/td>\n<td>\u540c\u4e00\u6761\u6d88\u606f\u591a\u6b21\u5199\u5165<\/td>\n<\/tr>\n<tr>\n<td>Rebalance<\/td>\n<td>\u6d88\u8d39\u8005\u91cd\u5e73\u8861\u5bfc\u81f4\u672a\u63d0\u4ea4 offset \u7684\u6d88\u606f\u88ab\u91cd\u65b0\u6d88\u8d39<\/td>\n<td>\u540c\u4e00\u6761\u6d88\u606f\u591a\u6b21\u5904\u7406<\/td>\n<\/tr>\n<tr>\n<td>\u6d88\u8d39\u8005\u91cd\u542f<\/td>\n<td>\u6d88\u8d39\u540e\u672a\u63d0\u4ea4 offset \u5373\u5b95\u673a<\/td>\n<td>\u91cd\u542f\u540e\u91cd\u590d\u6d88\u8d39<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>5.2 \u5e42\u7b49\u6027\u4fdd\u969c\u65b9\u6848<\/h4>\n<p>#mermaid-svg-tjxW9YmXzMM5Tyx8{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-tjxW9YmXzMM5Tyx8 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .error-icon{fill:#552222;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .marker.cross{stroke:#333333;}#mermaid-svg-tjxW9YmXzMM5Tyx8 svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-tjxW9YmXzMM5Tyx8 p{margin:0;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .label{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;color:#333;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .cluster-label text{fill:#333;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .cluster-label span{color:#333;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .cluster-label span p{background-color:transparent;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .label text,#mermaid-svg-tjxW9YmXzMM5Tyx8 span{fill:#333;color:#333;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .node rect,#mermaid-svg-tjxW9YmXzMM5Tyx8 .node circle,#mermaid-svg-tjxW9YmXzMM5Tyx8 .node ellipse,#mermaid-svg-tjxW9YmXzMM5Tyx8 .node polygon,#mermaid-svg-tjxW9YmXzMM5Tyx8 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .rough-node .label text,#mermaid-svg-tjxW9YmXzMM5Tyx8 .node .label text,#mermaid-svg-tjxW9YmXzMM5Tyx8 .image-shape .label,#mermaid-svg-tjxW9YmXzMM5Tyx8 .icon-shape .label{text-anchor:middle;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .rough-node .label,#mermaid-svg-tjxW9YmXzMM5Tyx8 .node .label,#mermaid-svg-tjxW9YmXzMM5Tyx8 .image-shape .label,#mermaid-svg-tjxW9YmXzMM5Tyx8 .icon-shape .label{text-align:center;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .node.clickable{cursor:pointer;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .arrowheadPath{fill:#333333;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-tjxW9YmXzMM5Tyx8 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-tjxW9YmXzMM5Tyx8 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-tjxW9YmXzMM5Tyx8 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .cluster text{fill:#333;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .cluster span{color:#333;}#mermaid-svg-tjxW9YmXzMM5Tyx8 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-tjxW9YmXzMM5Tyx8 rect.text{fill:none;stroke-width:0;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .icon-shape,#mermaid-svg-tjxW9YmXzMM5Tyx8 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .icon-shape p,#mermaid-svg-tjxW9YmXzMM5Tyx8 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .icon-shape .label rect,#mermaid-svg-tjxW9YmXzMM5Tyx8 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-tjxW9YmXzMM5Tyx8 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-tjxW9YmXzMM5Tyx8 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-tjxW9YmXzMM5Tyx8 :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<span class=\"edgeLabel\"><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u6d88\u8d39\u7aef\u5e42\u7b49<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u6d88\u606f\u4f53\u5e26\u4e1a\u52a1\u6d41\u6c34\u53f7<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>DB\u552f\u4e00\u952e \/ Redis\u9501\u53bb\u91cd<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u751f\u4ea7\u7aef\u5e42\u7b49<\/p>\n<p><\/span><span class=\"edgeLabel\"><\/span><span class=\"nodeLabel\"><\/p>\n<p>enable.idempotence&#061;true<\/p>\n<p><\/span><span class=\"nodeLabel\"><\/p>\n<p>\u9632\u6b62\u751f\u4ea7\u8005\u91cd\u8bd5\u5bfc\u81f4\u7684\u91cd\u590d\u6d88\u606f<\/p>\n<p><\/span><\/p>\n<p>\u6d88\u8d39\u7aef\u53bb\u91cd\u793a\u4f8b&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; \u2705 \u552f\u4e00\u7d22\u5f15\u4fdd\u8bc1\u5e42\u7b49<\/span><br \/>\n<span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">TABLE<\/span> order_event <span class=\"token punctuation\">(<\/span><br \/>\n    id <span class=\"token keyword\">BIGINT<\/span> <span class=\"token keyword\">PRIMARY<\/span> <span class=\"token keyword\">KEY<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    order_id <span class=\"token keyword\">BIGINT<\/span> <span class=\"token operator\">NOT<\/span> <span class=\"token boolean\">NULL<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    event_id <span class=\"token keyword\">VARCHAR<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">64<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">UNIQUE<\/span><span class=\"token punctuation\">,<\/span>  <span class=\"token comment\">&#8212; \u4e1a\u52a1\u6d41\u6c34\u53f7\u552f\u4e00\u7d22\u5f15<\/span><br \/>\n    event_type <span class=\"token keyword\">VARCHAR<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">32<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    create_time <span class=\"token keyword\">DATETIME<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u2705 \u6d88\u8d39\u65f6\u5148\u68c0\u67e5\u662f\u5426\u5df2\u5904\u7406<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">consumeMessage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">ConsumerRecord<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">String<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> record<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token class-name\">String<\/span> eventId <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">extractEventId<\/span><span class=\"token punctuation\">(<\/span>record<span class=\"token punctuation\">.<\/span><span class=\"token function\">value<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ Redis \u5206\u5e03\u5f0f\u9501 \/ DB \u552f\u4e00\u952e\u68c0\u67e5<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>eventService<span class=\"token punctuation\">.<\/span><span class=\"token function\">isProcessed<\/span><span class=\"token punctuation\">(<\/span>eventId<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        log<span class=\"token punctuation\">.<\/span><span class=\"token function\">info<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u23ed\ufe0f \u6d88\u606f\u5df2\u5904\u7406&#xff0c;\u8df3\u8fc7\u3002eventId: {}&#034;<\/span><span class=\"token punctuation\">,<\/span> eventId<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">return<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u4e1a\u52a1\u5904\u7406 &#043; \u8bb0\u5f55\u5904\u7406\u72b6\u6001&#xff08;\u539f\u5b50\u64cd\u4f5c&#xff09;<\/span><br \/>\n    orderService<span class=\"token punctuation\">.<\/span><span class=\"token function\">processOrderMessage<\/span><span class=\"token punctuation\">(<\/span>record<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    eventService<span class=\"token punctuation\">.<\/span><span class=\"token function\">markProcessed<\/span><span class=\"token punctuation\">(<\/span>eventId<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<hr \/>\n<h3>\u516d\u3001\u603b\u7ed3 &#x1f4dd;<\/h3>\n<table>\n<tr>\u7ef4\u5ea6\u5173\u952e\u70b9<\/tr>\n<tbody>\n<tr>\n<td>\u987a\u5e8f\u4fdd\u8bc1<\/td>\n<td>Kafka \u53ea\u4fdd\u8bc1\u5206\u533a\u5185\u6709\u5e8f&#xff0c;\u4e0d\u4fdd\u8bc1\u5168\u5c40\u6709\u5e8f<\/td>\n<\/tr>\n<tr>\n<td>\u5b9e\u73b0\u6838\u5fc3<\/td>\n<td>\u751f\u4ea7\u7aef\u6307\u5b9a Key \u8def\u7531\u5230\u540c\u4e00\u5206\u533a&#xff1b;\u6d88\u8d39\u7aef\u786e\u4fdd\u6bcf\u5206\u533a\u4ec5\u4e00\u4e2a\u6d88\u8d39\u8005\u7ebf\u7a0b<\/td>\n<\/tr>\n<tr>\n<td>\u6700\u5927\u9677\u9631<\/td>\n<td>Rebalance \u53ef\u80fd\u5bfc\u81f4\u77ed\u6682\u91cd\u590d\u6d88\u8d39&#xff0c;\u9700\u4e1a\u52a1\u5c42\u5e42\u7b49\u515c\u5e95<\/td>\n<\/tr>\n<tr>\n<td>\u961f\u5934\u963b\u585e<\/td>\n<td>\u63a8\u8350\u72b6\u6001\u673a\u6821\u9a8c &#043; \u6b7b\u4fe1\u515c\u5e95&#xff0c;\u517c\u987e\u4e00\u81f4\u6027\u548c\u53ef\u7528\u6027<\/td>\n<\/tr>\n<tr>\n<td>\u5e42\u7b49\u4fdd\u969c<\/td>\n<td>\u751f\u4ea7\u7aef enable.idempotence&#061;true &#043; \u6d88\u8d39\u7aef\u4e1a\u52a1\u6d41\u6c34\u53f7\u53bb\u91cd<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&#x1f3af; Kafka \u901a\u8fc7\u5206\u533a\u673a\u5236\u63d0\u4f9b\u987a\u5e8f\u4fdd\u8bc1&#xff0c;\u901a\u8fc7 Key \u54c8\u5e0c\u5b9e\u73b0\u4e1a\u52a1\u7ea7\u987a\u5e8f\u8def\u7531&#xff0c;\u901a\u8fc7\u72b6\u6001\u673a\u6821\u9a8c&#043;\u5e42\u7b49\u89e3\u51b3\u4e71\u5e8f\u548c\u91cd\u590d\u4e24\u5927\u96be\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001Kafka \u987a\u5e8f\u6d88\u8d39\u7684\u6838\u5fc3\u539f\u7406<br \/>\n1.1  Kafka \u987a\u5e8f<br \/>\nKafka \u7684\u987a\u5e8f\u4fdd\u8bc1\u5efa\u7acb\u5728 \u5206\u533a&#xff08;Partition&#xff09; \u8fd9\u4e00\u6838\u5fc3\u6982\u5ff5\u4e4b\u4e0a\u3002<br \/>\n#mermaid-svg-QyLvdSLBaEhapjAN{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-das<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10187,1114,3231,664],"topic":[],"class_list":["post-97514","post","type-post","status-publish","format-standard","hentry","category-server","tag-codingplan","tag-kafka","tag-linq","tag-664"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010Kafka\u8fdb\u96366\u3011\u987a\u5e8f\u6d88\u8d39\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/97514.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Kafka\u8fdb\u96366\u3011\u987a\u5e8f\u6d88\u8d39\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001Kafka \u987a\u5e8f\u6d88\u8d39\u7684\u6838\u5fc3\u539f\u7406 1.1 Kafka \u987a\u5e8f Kafka \u7684\u987a\u5e8f\u4fdd\u8bc1\u5efa\u7acb\u5728 \u5206\u533a&#xff08;Partition&#xff09; \u8fd9\u4e00\u6838\u5fc3\u6982\u5ff5\u4e4b\u4e0a\u3002 #mermaid-svg-QyLvdSLBaEhapjAN{font-family:&quot;trebuchet ms&quot;,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-das\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/97514.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-29T10:17:00+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/97514.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/97514.html\",\"name\":\"\u3010Kafka\u8fdb\u96366\u3011\u987a\u5e8f\u6d88\u8d39\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-29T10:17:00+00:00\",\"dateModified\":\"2026-08-29T10:17:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/97514.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/97514.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/97514.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Kafka\u8fdb\u96366\u3011\u987a\u5e8f\u6d88\u8d39\u6df1\u5ea6\u89e3\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010Kafka\u8fdb\u96366\u3011\u987a\u5e8f\u6d88\u8d39\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/97514.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Kafka\u8fdb\u96366\u3011\u987a\u5e8f\u6d88\u8d39\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u3001Kafka \u987a\u5e8f\u6d88\u8d39\u7684\u6838\u5fc3\u539f\u7406 1.1 Kafka \u987a\u5e8f Kafka \u7684\u987a\u5e8f\u4fdd\u8bc1\u5efa\u7acb\u5728 \u5206\u533a&#xff08;Partition&#xff09; \u8fd9\u4e00\u6838\u5fc3\u6982\u5ff5\u4e4b\u4e0a\u3002 #mermaid-svg-QyLvdSLBaEhapjAN{font-family:\"trebuchet ms\",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-das","og_url":"https:\/\/www.wsisp.com\/helps\/97514.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-29T10:17:00+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"13 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/97514.html","url":"https:\/\/www.wsisp.com\/helps\/97514.html","name":"\u3010Kafka\u8fdb\u96366\u3011\u987a\u5e8f\u6d88\u8d39\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-29T10:17:00+00:00","dateModified":"2026-08-29T10:17:00+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/97514.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/97514.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/97514.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010Kafka\u8fdb\u96366\u3011\u987a\u5e8f\u6d88\u8d39\u6df1\u5ea6\u89e3\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/97514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=97514"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/97514\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=97514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=97514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=97514"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=97514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}