{"id":108632,"date":"2026-09-22T09:32:57","date_gmt":"2026-09-22T01:32:57","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/108632.html"},"modified":"2026-09-22T09:32:57","modified_gmt":"2026-09-22T01:32:57","slug":"netty-pipeline-%e4%b8%8e-handler-%e4%bd%93%e7%b3%bb%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/108632.html","title":{"rendered":"Netty Pipeline \u4e0e Handler \u4f53\u7cfb\u8be6\u89e3"},"content":{"rendered":"<h2>Netty Pipeline \u4e0e Handler \u4f53\u7cfb\u8be6\u89e3<\/h2>\n<p>\u5b9a\u4f4d&#xff1a;Netty \u76ee\u5f55\u7b2c 03 \u7bc7&#xff0c;Pipeline \u7ed3\u6784\u3001Handler \u4e0e Context\u3001\u4e8b\u4ef6\u4f20\u64ad\u673a\u5236\u4e0e\u7f16\u89e3\u7801\u63a5\u5165\u5168\u89e3 \u9002\u7528\u7248\u672c&#xff1a;Netty 4.1.x&#xff08;JDK 8&#043;&#xff09;<\/p>\n<hr \/>\n<h3>\u76ee\u5f55<\/h3>\n<li>ChannelPipeline<\/li>\n<li>ChannelHandler \u4e0e Context<\/li>\n<li>\u4e8b\u4ef6\u4f20\u64ad\u673a\u5236<\/li>\n<li>SimpleChannelInboundHandler<\/li>\n<li>\u7f16\u89e3\u7801\u5668\u63a5\u5165\u4f4d\u7f6e<\/li>\n<li>\u603b\u7ed3<\/li>\n<li>\u5e38\u89c1\u9ad8\u9891\u9762\u8bd5\u9898<\/li>\n<hr \/>\n<h3>\u4e00\u3001ChannelPipeline<\/h3>\n<h4>1.1 \u7ed3\u6784&#xff1a;\u4e00\u6761\u8fde\u63a5\u7684\u52a0\u5de5\u6d41\u6c34\u7ebf<\/h4>\n<p>Channel \u521b\u5efa\u65f6\u540c\u6b65\u521b\u5efa\u4e00\u6761 Pipeline&#xff1a;<\/p>\n<p>  Head \u21c4 [ContextA(\u89e3\u7801\u5668)] \u21c4 [ContextB(\u4e1a\u52a1)] \u21c4 [ContextC(\u7f16\u7801\u5668)] \u21c4 Tail<br \/>\n  \u2502                                                                 \u2502<br \/>\n  \u5165\u7ad9\u4e8b\u4ef6&#xff1a;Head \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25ba Tail<br \/>\n  \u51fa\u7ad9\u4e8b\u4ef6&#xff1a;Head \u25c4\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Tail<\/p>\n<p>\u8981\u70b9&#xff1a;<\/p>\n<ul>\n<li>Pipeline \u4e0e Channel 1:1&#xff0c;\u672c\u8d28\u662f ChannelHandlerContext \u7ec4\u6210\u7684\u53cc\u5411\u94fe\u8868&#xff1b;<\/li>\n<li>\u94fe\u8868\u8282\u70b9\u4e0d\u662f Handler \u672c\u8eab&#xff0c;\u800c\u662f Context&#xff08;Handler \u7684\u5305\u88c5&#xff0c;\u6301\u524d\u540e\u6307\u9488&#xff09;&#xff1b;<\/li>\n<li>Head \u4e0e Tail \u662f\u5185\u7f6e\u7aef\u70b9&#xff1a;Head \u662f\u51fa\u7ad9\u64cd\u4f5c\u7684\u6700\u7ec8\u6267\u884c\u70b9&#xff08;\u771f\u6b63\u8c03\u5e95\u5c42\u5199&#xff09;&#xff0c;\u4e5f\u662f\u5165\u7ad9\u7684\u8d77\u70b9&#xff1b;Tail \u662f\u5165\u7ad9\u7684\u7ec8\u70b9&#xff08;\u515c\u5e95\u65e5\u5fd7&#xff09;\u4e0e\u51fa\u7ad9\u7684\u8d77\u70b9\u3002<\/li>\n<\/ul>\n<h4>1.2 \u65b9\u5411\u6027&#xff1a;\u4e00\u6761\u94fe\u8dd1\u4e24\u4e2a\u65b9\u5411<\/h4>\n<p>Handler \u6309\u5904\u7406\u7684\u65b9\u5411\u5206\u7c7b&#xff0c;\u4e8b\u4ef6\u6309\u65b9\u5411\u6d41\u52a8&#xff1a;<\/p>\n<p>\u5165\u7ad9&#xff08;Inbound&#xff09;&#xff1a;Head \u2192 Tail     \u8bfb\u6570\u636e\u3001\u8fde\u63a5\u6fc0\u6d3b\u3001\u5f02\u5e38\u4e0a\u62a5<br \/>\n\u51fa\u7ad9&#xff08;Outbound&#xff09;&#xff1a;Tail \u2192 Head    \u5199\u6570\u636e\u3001\u8fde\u63a5\u3001\u5173\u95ed<\/p>\n<p>\u4e00\u4e2a\u5165\u7ad9\u4e8b\u4ef6\u7ecf\u8fc7\u51fa\u7ad9 Handler \u65f6\u76f4\u63a5\u8df3\u8fc7&#xff08;\u53cd\u4e4b\u4ea6\u7136&#xff09;\u2014\u2014\u6240\u4ee5 addLast \u7684\u987a\u5e8f\u53ea\u51b3\u5b9a\u540c\u65b9\u5411\u5185\u7684\u5148\u540e&#xff0c;\u5165\u7ad9\u4e0e\u51fa\u7ad9\u4e92\u4e0d\u5e72\u6270\u3002\u8fd9\u89e3\u91ca\u4e86\u4e3a\u4ec0\u4e48\u89e3\u7801\u5668&#xff08;\u5165\u7ad9&#xff09;\u548c\u7f16\u7801\u5668&#xff08;\u51fa\u7ad9&#xff09;\u53ef\u4ee5\u653e\u5728\u76f8\u90bb\u4f4d\u7f6e\u800c\u4e92\u4e0d\u5f71\u54cd\u3002<\/p>\n<h4>1.3 \u589e\u5220\u64cd\u4f5c\u4e0e\u52a8\u6001\u6027<\/h4>\n<p><span class=\"token class-name\">ChannelPipeline<\/span> p <span class=\"token operator\">&#061;<\/span> ctx<span class=\"token punctuation\">.<\/span><span class=\"token function\">pipeline<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\np<span class=\"token punctuation\">.<\/span><span class=\"token function\">addLast<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;decoder&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">MsgDecoder<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\np<span class=\"token punctuation\">.<\/span><span class=\"token function\">addLast<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;handler&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">BizHandler<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\np<span class=\"token punctuation\">.<\/span><span class=\"token function\">addBefore<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;handler&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;auth&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">AuthHandler<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\np<span class=\"token punctuation\">.<\/span><span class=\"token function\">remove<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;auth&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>                          <span class=\"token comment\">\/\/ \u63e1\u624b\u5b8c\u6210\u540e\u79fb\u9664<\/span><br \/>\np<span class=\"token punctuation\">.<\/span><span class=\"token function\">replace<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;decoder&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;decoderV2&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">MsgDecoderV2<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u534f\u8bae\u5347\u7ea7\u70ed\u66ff\u6362<\/span><\/p>\n<p>\u751f\u4ea7\u6a21\u5f0f\u2014\u2014\u63e1\u624b\u534f\u5546&#xff1a;<\/p>\n<p>\u8fde\u63a5\u5efa\u7acb \u2192 [SSL\/\u9274\u6743\/\u534f\u8bae\u534f\u5546 Handler] \u2192 \u534f\u5546\u6210\u529f \u2192 \u79fb\u9664\u534f\u5546\u6bb5&#xff0c;\u6302\u4e0a\u7a33\u6001\u7f16\u89e3\u7801&#043;\u4e1a\u52a1<br \/>\n                                       \u2192 \u534f\u5546\u5931\u8d25 \u2192 close<\/p>\n<p>\u52a8\u6001\u589e\u5220\u5728 EventLoop \u4e0a\u6267\u884c\u662f\u5b89\u5168\u7684&#xff08;Pipeline \u5185\u90e8\u6709\u540c\u6b65&#xff09;&#xff0c;\u4f46\u4ece\u5916\u90e8\u7ebf\u7a0b\u8c03\u7528\u65f6\u6846\u67b6\u4f1a\u81ea\u52a8\u8c03\u5ea6\u5230 EventLoop\u2014\u2014\u884c\u4e3a\u6b63\u786e&#xff0c;\u4f46\u987a\u5e8f\u8bed\u4e49\u4ee5\u5b9e\u9645\u6267\u884c\u65f6\u523b\u4e3a\u51c6\u3002<\/p>\n<h4>1.4 fireXxx \u7684\u672c\u8d28<\/h4>\n<p>ctx.fireChannelRead(msg) \u7684\u672c\u8d28\u662f&#xff1a;\u4ece\u5f53\u524d Context \u51fa\u53d1&#xff0c;\u6cbf\u4e8b\u4ef6\u65b9\u5411\u627e\u4e0b\u4e00\u4e2a\u5339\u914d\u7c7b\u578b\u7684 Context&#xff0c;\u8c03\u7528\u5b83\u3002\u627e\u4e0d\u5230\u5339\u914d\u7684&#xff08;\u6bd4\u5982\u540e\u9762\u6ca1\u6709\u5165\u7ad9 Handler \u4e86&#xff09;&#xff0c;\u4e8b\u4ef6\u5230\u8fbe Tail \u88ab\u4e22\u5f03&#xff08;\u5165\u7ad9&#xff09;\u6216\u5230\u8fbe Head \u6267\u884c\u5e95\u5c42\u64cd\u4f5c&#xff08;\u51fa\u7ad9&#xff09;\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001ChannelHandler \u4e0e Context<\/h3>\n<h4>2.1 Handler \u4e09\u5206\u7c7b\u4e0e\u9002\u914d\u5668<\/h4>\n<table>\n<tr>\u63a5\u53e3\u5904\u7406\u5178\u578b\u4ee3\u8868<\/tr>\n<tbody>\n<tr>\n<td>ChannelInboundHandler<\/td>\n<td>\u5165\u7ad9&#xff1a;\u751f\u547d\u5468\u671f &#043; \u6570\u636e\u8bfb\u5165<\/td>\n<td>\u4e1a\u52a1\u5904\u7406\u5668\u3001\u89e3\u7801\u5668\u3001IdleStateHandler<\/td>\n<\/tr>\n<tr>\n<td>ChannelOutboundHandler<\/td>\n<td>\u51fa\u7ad9&#xff1a;\u5199\/\u8fde\u63a5\/\u5173\u95ed<\/td>\n<td>\u7f16\u7801\u5668<\/td>\n<\/tr>\n<tr>\n<td>ChannelDuplexHandler<\/td>\n<td>\u53cc\u5411<\/td>\n<td>\u7f16\u89e3\u7801\u5408\u4e00\u3001\u65e5\u5fd7&#xff08;LoggingHandler&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u76f4\u63a5\u5b9e\u73b0\u63a5\u53e3\u8981\u5199\u5341\u51e0\u4e2a\u65b9\u6cd5&#xff0c;\u6240\u4ee5\u51e0\u4e4e\u90fd\u7528\u9002\u914d\u5668\u57fa\u7c7b&#xff1a;ChannelInboundHandlerAdapter \/ ChannelOutboundHandlerAdapter \/ ChannelDuplexHandlerAdapter\u2014\u2014\u7a7a\u5b9e\u73b0&#xff0c;\u53ea\u8986\u5199\u5173\u5fc3\u7684\u65b9\u6cd5\u3002<\/p>\n<h4>2.2 ChannelHandlerContext&#xff1a;Handler \u7684\u8fd0\u884c\u65f6\u8eab\u4efd<\/h4>\n<p>Context \u662f Handler \u5728 Pipeline \u4e2d\u7684\u4f4d\u7f6e\u5bf9\u8c61&#xff1a;<\/p>\n<p>ctx<span class=\"token punctuation\">.<\/span><span class=\"token function\">channel<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/ \u6240\u5c5e Channel<\/span><br \/>\nctx<span class=\"token punctuation\">.<\/span><span class=\"token function\">pipeline<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/ \u6240\u5c5e Pipeline<\/span><br \/>\nctx<span class=\"token punctuation\">.<\/span><span class=\"token function\">executor<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/ \u6240\u5c5e EventLoop<\/span><br \/>\nctx<span class=\"token punctuation\">.<\/span><span class=\"token function\">name<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>         <span class=\"token comment\">\/\/ \u8282\u70b9\u540d<\/span><br \/>\nctx<span class=\"token punctuation\">.<\/span><span class=\"token function\">write<\/span><span class=\"token punctuation\">(<\/span>msg<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/ \u26a0 \u4ece\u672c\u8282\u70b9\u5411 Head \u65b9\u5411\u8d70\u51fa\u7ad9\u94fe<\/span><br \/>\nctx<span class=\"token punctuation\">.<\/span><span class=\"token function\">fireChannelRead<\/span><span class=\"token punctuation\">(<\/span>msg<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u7ee7\u7eed\u5165\u7ad9\u4f20\u64ad<\/span><\/p>\n<h4>2.3 ctx.write \u4e0e channel.write \u7684\u5dee\u5f02&#xff08;\u2b50 \u9ad8\u9891\u8003\u70b9&#xff09;<\/h4>\n<p>Pipeline&#xff1a;Head \u21c4 [\u89e3\u7801] \u21c4 [\u4e1a\u52a1] \u21c4 [\u7f16\u7801\u5668] \u21c4 Tail<\/p>\n<p>\u4e1a\u52a1 Handler \u4e2d&#xff1a;<br \/>\n  ctx.write(msg)     \u2192 \u4ece\u300c\u4e1a\u52a1\u300d\u8282\u70b9\u51fa\u53d1 \u2192 \u53ea\u7ecf\u8fc7\u300c\u7f16\u7801\u5668\u300d\u2192 Head<br \/>\n  channel.write(msg) \u2192 \u4ece Tail \u51fa\u53d1 \u2192 \u7ecf\u8fc7\u300c\u7f16\u7801\u5668\u300d\u2192\u300c\u4e1a\u52a1\u300d\u2192\u300c\u89e3\u7801\u300d\u2192 Head<br \/>\n                       &#xff08;\u51fa\u7ad9\u53ea\u8d70\u51fa\u7ad9\u578b\u8282\u70b9&#xff0c;\u5165\u7ad9\u8282\u70b9\u8df3\u8fc7&#xff0c;\u4f46\u4ecd\u8981\u904d\u5386&#xff09;<\/p>\n<p>\u7ed3\u8bba&#xff1a;<\/p>\n<ul>\n<li>\u4e24\u8005\u6700\u7ec8\u90fd\u80fd\u7ecf\u8fc7\u7f16\u7801\u5668&#xff08;\u53ea\u8981\u7f16\u7801\u5668\u5728\u4e1a\u52a1\u4e4b\u540e\u4e14\u662f\u51fa\u7ad9\u578b&#xff09;&#xff0c;\u4f46 ctx.write \u8def\u5f84\u66f4\u77ed\u3001\u5f00\u9500\u66f4\u5c0f&#xff1b;<\/li>\n<li>\u771f\u6b63\u7684\u9677\u9631\u573a\u666f&#xff1a;\u7f16\u7801\u5668\u52a0\u5728\u4e1a\u52a1\u8282\u70b9\u4e4b\u524d&#xff08;\u9760\u8fd1 Head&#xff09;&#xff0c;\u6b64\u65f6 ctx.write \u4ece\u4e1a\u52a1\u51fa\u53d1\u5411 Head \u8d70\u4f1a\u7ecf\u8fc7\u7f16\u7801\u5668\u6ca1\u95ee\u9898&#xff1b;\u4f46\u82e5\u7f16\u7801\u5668\u52a0\u5728\u4e1a\u52a1\u4e4b\u540e&#xff08;\u9760\u8fd1 Tail&#xff09;&#xff0c;ctx.write \u5c31\u7ed5\u8fc7\u4e86\u5b83\u2014\u2014\u5199\u51fa\u7684\u662f\u672a\u7f16\u7801\u5bf9\u8c61\u76f4\u63a5\u62a5\u9519&#xff1b;<\/li>\n<li>\u5b9e\u8df5\u89c4\u5219&#xff1a;\u51fa\u7ad9\u64cd\u4f5c\u7528 ctx.writeAndFlush \u65f6&#xff0c;\u786e\u8ba4\u7f16\u7801\u5668\u5728\u5f53\u524d\u4f4d\u7f6e\u7684\u300c\u5411 Head \u65b9\u5411\u300d&#xff1b;\u62ff\u4e0d\u51c6\u5c31\u7528 channel.writeAndFlush&#xff08;\u8d70\u5168\u7a0b&#xff0c;\u8bed\u4e49\u6700\u7a33&#xff09;\u3002<\/li>\n<\/ul>\n<h4>2.4 &#064;Sharable \u4e0e Handler \u5171\u4eab<\/h4>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b ChannelInitializer \u6bcf\u8fde\u63a5 new \u4e00\u4e2a Handler\u2014\u2014\u6700\u5b89\u5168\u3002\u5171\u4eab\u5355\u4f8b\u7684\u6761\u4ef6\u4e0e\u6807\u6ce8&#xff1a;<\/p>\n<p><span class=\"token annotation punctuation\">&#064;ChannelHandler.Sharable<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">MetricsHandler<\/span> <span class=\"token keyword\">extends<\/span> <span class=\"token class-name\">ChannelDuplexHandler<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">final<\/span> <span class=\"token class-name\">LongAdder<\/span> counter <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">LongAdder<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u81ea\u5e26\u5e76\u53d1\u5b89\u5168<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u4e0d\u6301\u6709\u4efb\u4f55\u300c\u8fde\u63a5\u7ea7\u300d\u53ef\u53d8\u72b6\u6001<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u89c4\u5219&#xff1a;<\/p>\n<ul>\n<li>\u6709\u8fde\u63a5\u7ea7\u72b6\u6001&#xff08;\u4f1a\u8bdd\u3001\u7d2f\u79ef\u7f13\u51b2\u533a\u3001\u89e3\u7801\u72b6\u6001\u673a&#xff09;\u7684 Handler \u7edd\u4e0d\u80fd\u5171\u4eab\u2014\u2014\u5178\u578b\u4e8b\u6545&#xff1a;\u7d2f\u79ef\u89e3\u7801\u5668\u88ab\u5171\u4eab&#xff0c;A \u8fde\u63a5\u7684\u534a\u5305\u6570\u636e\u6d41\u8fdb B \u8fde\u63a5&#xff1b;<\/li>\n<li>&#064;Sharable \u53ea\u662f\u58f0\u660e\u300c\u53ef\u4ee5\u5171\u4eab\u300d&#xff0c;\u4e0d\u4fdd\u8bc1\u7ebf\u7a0b\u5b89\u5168&#xff0c;\u5e76\u53d1\u6b63\u786e\u6027\u81ea\u5df1\u8d1f\u8d23&#xff1b;<\/li>\n<li>\u5224\u65ad\u53e3\u8bc0&#xff1a;\u8fd9\u4e2a Handler \u6709\u6ca1\u6709\u5b57\u6bb5\u968f\u8fde\u63a5\u53d8\u5316&#xff1f;\u6709 \u2192 \u6bcf\u8fde\u63a5\u65b0\u5efa\u3002<\/li>\n<\/ul>\n<h4>2.5 handlerAdded \/ handlerRemoved<\/h4>\n<p><span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">handlerAdded<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">ChannelHandlerContext<\/span> ctx<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u52a0\u5165 Pipeline&#xff1a;\u521d\u59cb\u5316\u8fde\u63a5\u7ea7\u8d44\u6e90&#xff08;\u5982\u65b0\u5206\u914d\u7d2f\u79ef\u7f13\u51b2&#xff09;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">handlerRemoved<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">ChannelHandlerContext<\/span> ctx<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u79fb\u51fa&#xff1a;\u91ca\u653e\u8d44\u6e90&#xff08;\u91ca\u653e\u672a\u6d88\u8d39\u7684\u7f13\u51b2\u2014\u2014\u5f15\u7528\u8ba1\u6570&#xff0c;06 \u7bc7&#xff09;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6bd4 channelActive\/channelInactive \u66f4\u65e9\/\u66f4\u665a\u7684\u751f\u547d\u5468\u671f\u6302\u70b9&#xff0c;\u9002\u5408\u8d44\u6e90\u7684\u7cbe\u786e\u914d\u5bf9\u7ba1\u7406\u3002<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u4e8b\u4ef6\u4f20\u64ad\u673a\u5236<\/h3>\n<h4>3.1 \u5165\u7ad9\u4e8b\u4ef6\u5168\u666f<\/h4>\n<table>\n<tr>\u4e8b\u4ef6\u89e6\u53d1\u65f6\u673a\u5e38\u89c1\u7528\u9014<\/tr>\n<tbody>\n<tr>\n<td>channelRegistered<\/td>\n<td>\u6ce8\u518c\u5230 EventLoop<\/td>\n<td>\u5c11\u7528<\/td>\n<\/tr>\n<tr>\n<td>channelActive<\/td>\n<td>\u8fde\u63a5\u5efa\u7acb<\/td>\n<td>\u63e1\u624b\u3001\u52a0\u5165\u8fde\u63a5\u7ec4<\/td>\n<\/tr>\n<tr>\n<td>channelRead<\/td>\n<td>\u8bfb\u5230\u6570\u636e<\/td>\n<td>\u89e3\u7801\u3001\u4e1a\u52a1<\/td>\n<\/tr>\n<tr>\n<td>channelReadComplete<\/td>\n<td>\u672c\u8f6e\u8bfb\u5b8c\u6210<\/td>\n<td>\u51b3\u5b9a\u662f\u5426\u7ee7\u7eed\u8bfb\u3001\u6279\u91cf\u5904\u7406<\/td>\n<\/tr>\n<tr>\n<td>userEventTriggered<\/td>\n<td>\u81ea\u5b9a\u4e49\u4e8b\u4ef6<\/td>\n<td>IdleStateEvent \u5fc3\u8df3&#xff08;07 \u7bc7&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>channelWritabilityChanged<\/td>\n<td>\u5199\u6c34\u4f4d\u7ffb\u8f6c<\/td>\n<td>\u80cc\u538b\u63a7\u5236&#xff08;05 \u7bc7&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>channelInactive<\/td>\n<td>\u65ad\u5f00<\/td>\n<td>\u6e05\u7406<\/td>\n<\/tr>\n<tr>\n<td>exceptionCaught<\/td>\n<td>\u94fe\u4e0a\u629b\u5f02\u5e38<\/td>\n<td>\u515c\u5e95<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>3.2 \u4f20\u64ad\u89c4\u5219&#xff1a;\u5904\u7406\u3001\u7ee7\u7eed\u3001\u7ec8\u6b62<\/h4>\n<p><span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">channelRead<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">ChannelHandlerContext<\/span> ctx<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">Object<\/span> msg<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u4e09\u79cd\u9009\u62e9&#xff1a;<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u2460 \u5904\u7406\u5e76\u7ee7\u7eed&#xff1a;\u5904\u7406\u540e ctx.fireChannelRead(msg);<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u2461 \u5904\u7406\u5e76\u7ec8\u6b62&#xff08;\u6d88\u8d39&#xff09;&#xff1a;\u5904\u7406\u540e\u4e0d\u518d\u4f20\u64ad&#xff08;\u6ce8\u610f\u91ca\u653e&#xff0c;\u89c1 3.4&#xff09;<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u2462 \u8df3\u8fc7&#xff1a;\u76f4\u63a5 ctx.fireChannelRead(msg);<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u4e0d\u8c03\u7528 fireXxx \u5c31\u662f\u62e6\u622a\/\u6d88\u8d39\u2014\u2014\u8d23\u4efb\u94fe\u7684\u5f00\u5173\u5c31\u5728\u4f60\u624b\u91cc\u3002\u51fa\u7ad9\u65b9\u5411\u540c\u7406&#xff1a;write \u4e8b\u4ef6\u7ecf\u8fc7\u51fa\u7ad9 Handler&#xff0c;\u53ef\u6539\u5199\u6d88\u606f\u3001\u7edf\u8ba1\u3001\u9650\u6d41&#xff0c;\u7136\u540e\u8c03 ctx.write \u7ee7\u7eed&#xff08;\u4e0d\u7ee7\u7eed &#061; \u6d88\u606f\u88ab\u541e&#xff0c;\u8fd9\u662f\u300c\u5199\u62e6\u622a\u5668\u4e22\u5931\u6d88\u606f\u300d\u7684\u5e38\u89c1\u539f\u56e0&#xff09;\u3002<\/p>\n<h4>3.3 \u5f02\u5e38\u4f20\u64ad<\/h4>\n<p>\u5f02\u5e38\u6cbf\u5165\u7ad9\u65b9\u5411\u5411\u540e\u4f20\u64ad&#xff1a;<\/p>\n<p>\u89e3\u7801\u5668\u629b\u5f02\u5e38 \u2192 \u89e3\u7801\u5668\u4e4b\u540e\u7684\u5165\u7ad9 Handler \u7684 exceptionCaught<br \/>\n            \u2192 \u4e00\u8def\u5411\u540e&#xff0c;\u76f4\u5230\u67d0\u4e2a Handler \u5904\u7406<br \/>\n            \u2192 \u65e0\u4eba\u5904\u7406&#xff1a;Tail \u6253\u5370\u544a\u8b66\u65e5\u5fd7&#xff08;\u8fde\u63a5\u4e0d\u4f1a\u81ea\u52a8\u5173\u95ed&#xff09;<\/p>\n<p>\u751f\u4ea7\u60ef\u4f8b&#xff1a;<\/p>\n<li>\u5c3e\u90e8\u515c\u5e95&#xff1a;\u94fe\u8def\u6700\u540e\u4e00\u4e2a\u5165\u7ad9 Handler \u5b9e\u73b0 exceptionCaught&#xff1a;\u8bb0\u65e5\u5fd7 &#043; \u5173\u95ed\u8fde\u63a5&#xff08;\u9632\u810f\u8fde\u63a5&#xff09;&#xff1b;<\/li>\n<li>\u5c31\u8fd1\u5904\u7406&#xff1a;\u4e1a\u52a1\u8bed\u4e49\u660e\u786e\u7684\u5f02\u5e38&#xff08;\u89e3\u7801\u5931\u8d25\u3001\u9274\u6743\u5931\u8d25&#xff09;\u5728\u5bf9\u5e94 Handler \u5185\u76f4\u63a5\u5904\u7406&#xff08;\u56de\u9519\u8bef\u5305 &#043; close&#xff09;&#xff0c;\u4e0d\u4f9d\u8d56\u515c\u5e95&#xff1b;<\/li>\n<li>\u4e0d\u8981\u628a exceptionCaught \u5f53\u4e1a\u52a1\u56de\u8c03\u7528\u2014\u2014\u5b83\u53ea\u8be5\u51fa\u73b0\u5728\u5f02\u5e38\u5904\u7406\u4e0a\u3002<\/li>\n<h4>3.4 \u6d88\u606f\u5bf9\u8c61\u7684\u6240\u6709\u6743\u6d41\u8f6c&#xff08;\u5f15\u7528\u8ba1\u6570\u4f0f\u7b14&#xff09;<\/h4>\n<p>channelRead(ctx, msg) \u62ff\u5230\u7684 msg&#xff08;\u901a\u5e38\u662f ByteBuf&#xff09;\u5e26\u7740\u6240\u6709\u6743&#xff1a;<\/p>\n<p>\u89c4\u5219&#xff1a;\u8c01\u6700\u540e\u6301\u6709&#xff0c;\u8c01\u8d1f\u8d23\u5904\u7406<br \/>\n  &#8211; \u7ee7\u7eed\u4f20\u64ad&#xff1a;\u6240\u6709\u6743\u4ea4\u7ed9\u4e0b\u6e38&#xff08;\u4e0d\u8981 release&#xff09;<br \/>\n  &#8211; \u6d88\u8d39\u6389&#xff1a;\u5fc5\u987b release&#xff08;04\/06 \u7bc7\u5f15\u7528\u8ba1\u6570&#xff09;<br \/>\n  &#8211; \u5199\u51fa&#xff1a;\u6240\u6709\u6743\u4ea4\u7ed9\u5199\u6d41\u7a0b&#xff08;\u5199\u6210\u529f\/\u5931\u8d25\u7531\u6846\u67b6\u91ca\u653e&#xff09;<\/p>\n<p>\u8fdd\u53cd\u5373\u5806\u5916\u5185\u5b58\u6cc4\u6f0f\u2014\u2014\u8fd9\u662f Netty \u6700\u5e38\u89c1\u7684\u8d44\u6e90\u4e8b\u6545&#xff0c;06 \u7bc7\u4f1a\u7cfb\u7edf\u5c55\u5f00\u6cc4\u6f0f\u68c0\u6d4b\u4e0e\u6392\u67e5\u3002<\/p>\n<hr \/>\n<h3>\u56db\u3001SimpleChannelInboundHandler<\/h3>\n<h4>4.1 \u80fd\u529b\u4e0e\u6a21\u677f<\/h4>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">BizHandler<\/span> <span class=\"token keyword\">extends<\/span> <span class=\"token class-name\">SimpleChannelInboundHandler<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">OrderMessage<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n    <span class=\"token keyword\">protected<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">channelRead0<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">ChannelHandlerContext<\/span> ctx<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">OrderMessage<\/span> msg<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u53ea\u63a5\u6536 OrderMessage \u7c7b\u578b&#xff1b;\u65b9\u6cd5\u8fd4\u56de\u540e\u6846\u67b6\u81ea\u52a8 msg.release()<\/span><br \/>\n        <span class=\"token function\">process<\/span><span class=\"token punctuation\">(<\/span>ctx<span class=\"token punctuation\">,<\/span> msg<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">exceptionCaught<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">ChannelHandlerContext<\/span> ctx<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">Throwable<\/span> cause<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        ctx<span class=\"token punctuation\">.<\/span><span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span><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>\u4e24\u4e2a\u81ea\u52a8\u5316\u80fd\u529b&#xff1a;<\/p>\n<li>\u6cdb\u578b\u8fc7\u6ee4&#xff1a;\u975e OrderMessage \u7c7b\u578b\u7684\u6d88\u606f\u81ea\u52a8\u900f\u4f20\u7ed9\u4e0b\u4e00\u4e2a Handler&#xff08;\u591a\u7c7b\u578b\u5206\u53d1\u573a\u666f\u53ef\u6302\u591a\u4e2a Simple \u4e32\u8054&#xff09;&#xff1b;<\/li>\n<li>\u81ea\u52a8\u91ca\u653e&#xff1a;channelRead0 \u8fd4\u56de\u540e ReferenceCountUtil.release(msg)\u2014\u201406 \u7bc7\u5f15\u7528\u8ba1\u6570\u7684\u300c\u6846\u67b6\u5e2e\u4f60\u505a\u300d\u6848\u4f8b\u3002<\/li>\n<h4>4.2 autoRelease \u53c2\u6570\u4e0e\u9677\u9631<\/h4>\n<p><span class=\"token keyword\">new<\/span> <span class=\"token class-name\">SimpleChannelInboundHandler<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">Msg<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><span class=\"token punctuation\">(<\/span><span class=\"token boolean\">false<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span> <span class=\"token punctuation\">}<\/span>   <span class=\"token comment\">\/\/ autoRelease &#061; false<\/span><\/p>\n<p>\u8bbe\u4e3a false \u7684\u573a\u666f&#xff1a;\u6d88\u606f\u8981\u5f02\u6b65\u6682\u5b58&#xff08;\u653e\u5165\u961f\u5217\u4ea4\u7ed9\u4e1a\u52a1\u7ebf\u7a0b\u6c60\u7a0d\u540e\u5904\u7406&#xff09;\u6216\u8981\u7ee7\u7eed\u4f20\u64ad\u3002\u9677\u9631\u7ec4\u5408&#xff1a;<\/p>\n<ul>\n<li>autoRelease &#061; true&#xff08;\u9ed8\u8ba4&#xff09;\u5374\u5728 channelRead0 \u91cc\u628a msg \u5b58\u8d77\u6765\u5f02\u6b65\u7528 \u2192 \u4f7f\u7528\u5df2\u91ca\u653e\u7684\u7f13\u51b2&#xff0c;\u62a5 IllegalReferenceCountException&#xff1b;<\/li>\n<li>\u60f3\u628a\u6d88\u606f fireChannelRead \u7ed9\u4e0b\u6e38&#xff0c;\u5374\u7ee7\u627f Simple \u9ed8\u8ba4\u91ca\u653e \u2192 \u4e0b\u6e38\u62ff\u5230\u5df2\u91ca\u653e\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<p>\u539f\u5219&#xff1a;\u6d88\u606f\u7684\u751f\u547d\u5468\u671f\u5fc5\u987b\u5355\u4e00\u4e14\u660e\u786e\u2014\u2014\u8981\u4e48\u6846\u67b6\u91ca\u653e\u3001\u8981\u4e48\u4f60\u91ca\u653e&#xff0c;\u4e0d\u5141\u8bb8\u53cc\u5934\u6216\u65e0\u4e3b\u3002<\/p>\n<h4>4.3 \u4e0e Adapter \u7684\u53d6\u820d<\/h4>\n<table>\n<tr>\u9700\u6c42\u9009\u62e9<\/tr>\n<tbody>\n<tr>\n<td>\u5355\u4e00\u6d88\u606f\u7c7b\u578b&#xff0c;\u6d88\u8d39\u5373\u5f03<\/td>\n<td>SimpleChannelInboundHandler&lt;T&gt;<\/td>\n<\/tr>\n<tr>\n<td>\u5904\u7406\u539f\u59cb ByteBuf&#xff08;\u89e3\u7801\u5668\u81ea\u5df1&#xff09;<\/td>\n<td>ByteToMessageDecoder&#xff08;04 \u7bc7&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u591a\u7c7b\u578b\u6d88\u606f\u624b\u52a8\u5206\u53d1<\/td>\n<td>ChannelInboundHandlerAdapter<\/td>\n<\/tr>\n<tr>\n<td>\u9700\u8981\u63a7\u5236\u91ca\u653e\u65f6\u673a&#xff08;\u5f02\u6b65\u5904\u7406&#xff09;<\/td>\n<td>Adapter &#043; \u624b\u52a8\u91ca\u653e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u4e94\u3001\u7f16\u89e3\u7801\u5668\u63a5\u5165\u4f4d\u7f6e<\/h3>\n<h4>5.1 \u65b9\u5411\u5f52\u5c5e\u4e0e\u7ecf\u5178\u987a\u5e8f<\/h4>\n<p>\u6807\u51c6\u4e1a\u52a1\u94fe&#xff08;\u670d\u52a1\u7aef&#xff09;&#xff1a;<\/p>\n<p> \u5165\u7ad9\u65b9\u5411 \u2192  [\u5e27\u89e3\u7801\u5668] \u2192 [\u534f\u8bae\u89e3\u7801\u5668] \u2192 [\u9274\u6743] \u2192 [\u4e1a\u52a1]<br \/>\n \u51fa\u7ad9\u65b9\u5411 \u2190  [\u534f\u8bae\u7f16\u7801\u5668] \u2190&#xff08;\u4e1a\u52a1\u5199\u51fa&#xff09;<\/p>\n<p>Pipeline addLast \u987a\u5e8f&#xff1a;<br \/>\n  1. IdleStateHandler&#xff08;\u5fc3\u8df3&#xff0c;07 \u7bc7&#xff09;<br \/>\n  2. LengthFieldBasedFrameDecoder&#xff08;\u62c6\u5305&#xff0c;04 \u7bc7&#xff09;<br \/>\n  3. MsgDecoder&#xff08;\u5b57\u8282 \u2192 \u6d88\u606f\u5bf9\u8c61&#xff09;<br \/>\n  4. MsgEncoder&#xff08;\u6d88\u606f\u5bf9\u8c61 \u2192 \u5b57\u8282&#xff09;<br \/>\n  5. AuthHandler&#xff08;\u53ef\u52a8\u6001\u79fb\u9664&#xff09;<br \/>\n  6. BizHandler&#xff08;\u4e1a\u52a1&#xff0c;\u901a\u5e38\u94fe\u5c3e&#xff09;<\/p>\n<p>\u89c4\u5219\u63d0\u70bc&#xff1a;<\/p>\n<ul>\n<li>\u89e3\u7801\u5668\u653e\u4e1a\u52a1\u4e4b\u524d&#xff08;\u5165\u7ad9\u5148\u89e3\u7801&#xff09;&#xff1b;<\/li>\n<li>\u7f16\u7801\u5668\u4e0e\u4e1a\u52a1\u7684\u76f8\u5bf9\u4f4d\u7f6e\u51b3\u5b9a ctx.write \u662f\u5426\u7ecf\u8fc7\u5b83&#xff08;2.3 \u8282&#xff09;\u2014\u2014\u4fdd\u5b88\u505a\u6cd5\u662f\u7f16\u7801\u5668\u7d27\u90bb\u4e1a\u52a1\u4e4b\u524d&#xff0c;\u4e1a\u52a1\u5185\u7528 ctx.writeAndFlush&#xff1b;<\/li>\n<li>\u5fc3\u8df3\u4e0e\u7a7a\u95f2\u68c0\u6d4b\u653e\u6700\u524d&#xff0c;\u4fdd\u8bc1\u4efb\u4f55\u60c5\u51b5\u4e0b\u90fd\u80fd\u611f\u77e5\u8fde\u63a5\u6b7b\u6d3b\u3002<\/li>\n<\/ul>\n<h4>5.2 \u7ec4\u5408\u4e0e\u52a8\u6001\u6a21\u5f0f<\/h4>\n<ul>\n<li>CombinedChannelDuplexHandler&#xff1a;\u628a\u914d\u5bf9\u7684\u7f16\/\u89e3\u7801\u5668\u5408\u6210\u4e00\u4e2a\u8282\u70b9&#xff0c;\u7b80\u5316\u94fe\u7ba1\u7406&#xff1b;<\/li>\n<li>MessageToMessageCodec&lt;IN, OUT&gt;&#xff1a;\u6d88\u606f\u5230\u6d88\u606f\u7684\u53cc\u5411\u8f6c\u6362&#xff08;\u5982\u5185\u90e8\u534f\u8bae\u5bf9\u8c61 \u2194 \u5916\u90e8\u534f\u8bae\u5bf9\u8c61&#xff09;&#xff1b;<\/li>\n<li>\u534f\u5546\u540e\u66ff\u6362&#xff1a;\u63e1\u624b\u671f\u94fe &#061; [\u957f\u5ea6\u89e3\u7801 &#043; \u63e1\u624b\u6d88\u606f\u7f16\u89e3\u7801 &#043; \u534f\u5546 Handler]&#xff1b;\u534f\u5546\u5b8c\u6210 \u2192 pipeline.remove(\u534f\u5546) &#043; pipeline.addLast(\u7a33\u6001\u7f16\u89e3\u7801)\u2014\u2014\u8fd0\u884c\u65f6\u70ed\u5207\u6362&#xff0c;\u8fde\u63a5\u4e0d\u65ad\u3002<\/li>\n<\/ul>\n<h4>5.3 \u5e38\u89c1\u9519\u8bef\u6e05\u5355<\/h4>\n<table>\n<tr>\u9519\u8bef\u540e\u679c<\/tr>\n<tbody>\n<tr>\n<td>\u89e3\u7801\u5668\u52a0\u5728\u4e1a\u52a1\u4e4b\u540e<\/td>\n<td>\u4e1a\u52a1\u62ff\u5230\u539f\u59cb\u5b57\u8282&#xff0c;ClassCastException<\/td>\n<\/tr>\n<tr>\n<td>\u7f16\u7801\u5668\u4f4d\u7f6e\u88ab ctx.write \u7ed5\u8fc7<\/td>\n<td>\u672a\u7f16\u7801\u5bf9\u8c61\u76f4\u8fbe\u5e95\u5c42&#xff0c;UnsupportedMessageTypeException<\/td>\n<\/tr>\n<tr>\n<td>\u5e27\u89e3\u7801\u5668 maxFrameLength \u8fc7\u5c0f<\/td>\n<td>\u5927\u6d88\u606f\u88ab\u622a\u65ad\u629b TooLongFrameException&#xff0c;\u8fde\u63a5\u88ab\u5173<\/td>\n<\/tr>\n<tr>\n<td>\u591a\u4e2a\u89e3\u7801\u5668\u987a\u5e8f\u98a0\u5012&#xff08;\u5148\u4e1a\u52a1\u89e3\u7801\u540e\u62c6\u5305&#xff09;<\/td>\n<td>\u534a\u5305\u76f4\u63a5\u8fdb\u4e1a\u52a1\u89e3\u7801&#xff0c;\u89e3\u7801\u5931\u8d25<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<li>Pipeline \u662f\u4e0e Channel 1:1 \u7684\u53cc\u5411\u94fe\u8868&#xff0c;\u8282\u70b9\u662f Context&#xff1b;Head\/Tail \u5185\u7f6e\u7aef\u70b9&#xff1b;\u5165\u7ad9\u4ece Head \u5230 Tail&#xff0c;\u51fa\u7ad9\u53cd\u5411&#xff0c;\u8de8\u65b9\u5411\u8282\u70b9\u4e92\u4e0d\u5e72\u6270\u3002<\/li>\n<li>Context \u662f Handler \u7684\u4f4d\u7f6e\u5bf9\u8c61&#xff1a;ctx.write \u4ece\u5f53\u524d\u8282\u70b9\u5411 Head \u8d70\u3001channel.write \u4ece Tail \u8d70\u5168\u7a0b\u2014\u2014\u7f16\u7801\u5668\u4f4d\u7f6e\u4e0e\u5199\u51fa\u65b9\u5f0f\u5fc5\u987b\u5339\u914d&#xff0c;\u62ff\u4e0d\u51c6\u7528 channel.writeAndFlush\u3002<\/li>\n<li>&#064;Sharable \u53ea\u58f0\u660e\u53ef\u5171\u4eab&#xff0c;\u4e0d\u4fdd\u8bc1\u5b89\u5168&#xff1b;\u6709\u8fde\u63a5\u7ea7\u72b6\u6001\u7684 Handler \u5fc5\u987b\u6bcf\u8fde\u63a5\u65b0\u5efa&#xff1b;\u5171\u4eab\u7684\u5224\u65ad\u6807\u51c6\u662f\u300c\u6709\u65e0\u968f\u8fde\u63a5\u53d8\u5316\u7684\u5b57\u6bb5\u300d\u3002<\/li>\n<li>\u4e8b\u4ef6\u4f20\u64ad &#061; \u8d23\u4efb\u94fe&#xff1a;\u4e0d fireXxx \u5373\u6d88\u8d39\/\u62e6\u622a&#xff1b;\u5f02\u5e38\u6cbf\u5165\u7ad9\u5411\u540e\u4f20\u64ad&#xff0c;\u5c3e\u90e8\u515c\u5e95 &#043; \u5c31\u8fd1\u5904\u7406\u53cc\u4fdd\u9669\u3002<\/li>\n<li>\u6d88\u606f\u6240\u6709\u6743\u7eaa\u5f8b&#xff1a;\u4f20\u64ad\u4ea4\u4e0b\u6e38\u3001\u6d88\u8d39\u8981\u91ca\u653e\u3001\u5199\u51fa\u4ea4\u6846\u67b6\u2014\u2014\u751f\u547d\u5468\u671f\u5355\u4e00\u660e\u786e&#xff0c;\u8fd9\u662f 06 \u7bc7\u5f15\u7528\u8ba1\u6570\u7684\u524d\u7f6e\u8ba4\u77e5\u3002<\/li>\n<li>Simple \u7684\u81ea\u52a8\u5316\u662f\u53cc\u5203\u5251&#xff1a;\u7c7b\u578b\u8fc7\u6ee4 &#043; \u81ea\u52a8\u91ca\u653e\u7701\u5fc3&#xff0c;\u4f46\u5f02\u6b65\u6682\u5b58\/\u7ee7\u7eed\u4f20\u64ad\u5fc5\u987b autoRelease &#061; false\u3002<\/li>\n<li>\u7f16\u89e3\u7801\u63a5\u5165\u987a\u5e8f&#xff1a;\u5fc3\u8df3 \u2192 \u62c6\u5305 \u2192 \u89e3\u7801 \u2192 \u7f16\u7801 \u2192 \u9274\u6743&#xff08;\u53ef\u52a8\u6001&#xff09;\u2192 \u4e1a\u52a1&#xff1b;\u534f\u5546\u6bb5\u652f\u6301\u8fd0\u884c\u65f6\u70ed\u66ff\u6362\u3002<\/li>\n<hr \/>\n<h3>\u4e03\u3001\u5e38\u89c1\u9ad8\u9891\u9762\u8bd5\u9898<\/h3>\n<p>1. ChannelPipeline \u7684\u7ed3\u6784\u662f\u4ec0\u4e48&#xff1f;\u4e8b\u4ef6\u5982\u4f55\u6d41\u52a8&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;\u4e0e Channel 1:1 \u7684\u53cc\u5411\u94fe\u8868&#xff0c;\u8282\u70b9\u662f ChannelHandlerContext&#xff08;\u5305\u88c5 Handler&#xff09;&#xff0c;\u7aef\u70b9\u4e3a\u5185\u7f6e Head \u4e0e Tail\u3002\u5165\u7ad9\u4e8b\u4ef6&#xff08;\u8bfb\/\u6fc0\u6d3b&#xff09;\u4ece Head \u6d41\u5411 Tail&#xff0c;\u51fa\u7ad9\u4e8b\u4ef6&#xff08;\u5199\/\u5173\u95ed&#xff09;\u53cd\u5411\u3002Handler \u53ea\u5904\u7406\u81ea\u5df1\u65b9\u5411\u7684\u4e8b\u4ef6\u3002\u6240\u6709\u56de\u8c03\u5728\u6240\u5c5e Channel \u7684 EventLoop \u4e0a\u4e32\u884c\u6267\u884c\u3002<\/p>\n<p>2. ChannelHandler \u548c ChannelHandlerContext \u7684\u533a\u522b&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;Handler \u662f\u4e1a\u52a1\u903b\u8f91\u8f7d\u4f53&#xff08;\u65e0\u4f4d\u7f6e\u6982\u5ff5&#xff09;&#xff0c;Context \u662f Handler \u5728 Pipeline \u4e2d\u7684\u5305\u88c5&#xff1a;\u6301\u6709\u94fe\u8868\u524d\u540e\u5f15\u7528\u3001\u63d0\u4f9b channel\/pipeline\/executor \u8bbf\u95ee\u3001\u63d0\u4f9b fire\/write \u7b49\u4f20\u64ad\u5165\u53e3\u3002\u540c\u4e00 Handler \u52a0\u5165\u4e0d\u540c Pipeline \u4f1a\u6709\u4e0d\u540c Context\u3002<\/p>\n<p>3. ctx.write \u548c channel.write \u7684\u533a\u522b&#xff1f;\u4ec0\u4e48\u65f6\u5019\u4f1a\u51fa\u95ee\u9898&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;ctx.write \u4ece\u5f53\u524d Context \u5411 Head \u65b9\u5411\u8d70\u51fa\u7ad9\u94fe&#xff1b;channel.write \u4ece Tail \u51fa\u53d1\u8d70\u5b8c\u6574\u51fa\u7ad9\u94fe\u3002\u95ee\u9898\u573a\u666f&#xff1a;\u7f16\u7801\u5668\u52a0\u5728\u5f53\u524d\u4e1a\u52a1\u8282\u70b9\u9760 Tail \u4e00\u4fa7\u65f6&#xff0c;ctx.write \u4f1a\u7ed5\u8fc7\u7f16\u7801\u5668\u5bfc\u81f4\u672a\u7f16\u7801\u5bf9\u8c61\u76f4\u8fbe\u5e95\u5c42\u62a5\u9519\u3002\u89c4\u5219&#xff1a;\u786e\u8ba4\u7f16\u7801\u5668\u5728\u5411 Head \u7684\u8def\u5f84\u4e0a&#xff0c;\u5426\u5219\u7528 channel.writeAndFlush\u3002<\/p>\n<p>4. &#064;Sharable \u7684\u4f5c\u7528&#xff1f;\u5171\u4eab Handler \u8981\u6ce8\u610f\u4ec0\u4e48&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;\u6807\u6ce8\u540e\u540c\u4e00\u5b9e\u4f8b\u53ef\u52a0\u5165\u591a\u6761 Pipeline&#xff08;\u5355\u4f8b\u590d\u7528&#xff09;\u3002\u5b83\u53ea\u58f0\u660e\u53ef\u5171\u4eab&#xff0c;\u4e0d\u4fdd\u8bc1\u7ebf\u7a0b\u5b89\u5168&#xff1a;\u5fc5\u987b\u65e0\u8fde\u63a5\u7ea7\u53ef\u53d8\u72b6\u6001&#xff0c;\u5171\u4eab\u72b6\u6001\u8981\u81ea\u5e26\u5e76\u53d1\u63a7\u5236\u3002\u6709\u72b6\u6001&#xff08;\u89e3\u7801\u7f13\u51b2\u3001\u4f1a\u8bdd&#xff09;\u7684 Handler \u5171\u4eab\u4f1a\u5bfc\u81f4\u6570\u636e\u4e32\u8fde\u63a5&#xff0c;\u5fc5\u987b\u6bcf\u8fde\u63a5\u65b0\u5efa\u3002<\/p>\n<p>5. Netty \u7684\u5f02\u5e38\u662f\u5982\u4f55\u4f20\u64ad\u7684&#xff1f;\u6700\u4f73\u5b9e\u8df5&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;\u94fe\u4e0a\u629b\u51fa\u7684\u5f02\u5e38\u6cbf\u5165\u7ad9\u65b9\u5411\u5411\u540e\u4f20\u64ad\u5230\u540e\u7eed Handler \u7684 exceptionCaught&#xff1b;\u65e0\u4eba\u5904\u7406\u65f6 Tail \u6253\u544a\u8b66\u65e5\u5fd7&#xff0c;\u8fde\u63a5\u4e0d\u4f1a\u81ea\u52a8\u5173\u95ed\u3002\u5b9e\u8df5&#xff1a;\u5c3e\u90e8\u653e\u515c\u5e95&#xff08;\u65e5\u5fd7&#043;\u5173\u95ed&#xff09;&#xff0c;\u4e1a\u52a1\u8bed\u4e49\u660e\u786e\u7684\u5f02\u5e38\u5c31\u8fd1\u5904\u7406&#xff08;\u56de\u9519\u8bef\u5305&#043;\u5173\u95ed&#xff09;&#xff1b;\u4e0d\u8981\u4f9d\u8d56\u515c\u5e95\u505a\u4e1a\u52a1\u6062\u590d\u3002<\/p>\n<p>6. channelRead \u4e2d\u7684 msg \u5e94\u8be5\u600e\u4e48\u5904\u7406&#xff1f;\u4e0d\u5904\u7406\u4f1a\u600e\u6837&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;msg&#xff08;\u5e38\u4e3a ByteBuf&#xff09;\u5e26\u6240\u6709\u6743&#xff1a;\u7ee7\u7eed\u4f20\u64ad\u5219\u4ea4\u4e0b\u6e38&#xff08;\u4e0d\u91ca\u653e&#xff09;&#xff1b;\u6d88\u8d39\u5219\u5fc5\u987b release&#xff08;\u5f15\u7528\u8ba1\u6570&#xff09;&#xff1b;\u5199\u51fa\u5219\u6240\u6709\u6743\u4ea4\u5199\u6d41\u7a0b\u3002\u65e2\u4e0d\u4f20\u64ad\u4e5f\u4e0d\u91ca\u653e\u4f1a\u5bfc\u81f4\u5806\u5916\u5185\u5b58\u6cc4\u6f0f&#xff0c;\u5f00 LeakDetector \u53ef\u68c0\u51fa\u3002SimpleChannelInboundHandler \u9ed8\u8ba4\u5728\u56de\u8c03\u540e\u81ea\u52a8\u91ca\u653e\u3002<\/p>\n<p>7. SimpleChannelInboundHandler \u76f8\u6bd4 ChannelInboundHandlerAdapter \u591a\u4e86\u4ec0\u4e48&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;\u4e24\u70b9\u2014\u2014\u6309\u6cdb\u578b\u7c7b\u578b\u81ea\u52a8\u8fc7\u6ee4&#xff08;\u4e0d\u5339\u914d\u7684\u6d88\u606f\u900f\u4f20&#xff09;&#xff1b;\u56de\u8c03\u8fd4\u56de\u540e\u81ea\u52a8 release \u6d88\u606f&#xff08;autoRelease \u9ed8\u8ba4 true&#xff09;\u3002\u6ce8\u610f\u82e5\u6d88\u606f\u8981\u5f02\u6b65\u6682\u5b58\u6216\u7ee7\u7eed\u4f20\u64ad&#xff0c;\u5fc5\u987b\u6784\u9020\u65f6\u8bbe autoRelease&#061;false \u5e76\u81ea\u884c\u7ba1\u7406\u91ca\u653e&#xff0c;\u5426\u5219\u62a5 IllegalReferenceCountException \u6216\u4e0b\u6e38\u62ff\u5230\u5df2\u91ca\u653e\u7f13\u51b2\u3002<\/p>\n<p>8. \u4e00\u6761\u6d88\u606f\u4ece\u7f51\u7edc\u5230\u8fbe\u5230\u4e1a\u52a1\u5904\u7406\u7684\u5b8c\u6574\u94fe\u8def&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;OP_READ \u5c31\u7eea \u2192 EventLoop \u89e6\u53d1\u8bfb \u2192 ByteBuf \u8bfb\u5165\u5185\u6838\u6570\u636e \u2192 \u5165\u7ad9\u4e8b\u4ef6\u4ece Head \u4f20\u64ad&#xff1a;\u5e27\u89e3\u7801\u5668&#xff08;\u62c6\u5305&#xff09;\u2192 \u534f\u8bae\u89e3\u7801\u5668&#xff08;\u5b57\u8282\u8f6c\u6d88\u606f&#xff09;\u2192 \u9274\u6743\/\u4e1a\u52a1 Handler \u5904\u7406\u3002\u5904\u7406\u5b8c\u6210\u53ef\u9009\u5199\u51fa&#xff1a;\u4e1a\u52a1 \u2192 \u7f16\u7801\u5668 \u2192 Head \u2192 \u5185\u6838\u3002\u671f\u95f4\u4efb\u4f55\u73af\u8282\u53ef\u62e6\u622a\u6216\u7ec8\u6b62\u4f20\u64ad\u3002<\/p>\n<p>9. \u5982\u4f55\u5b9e\u73b0\u8fd0\u884c\u65f6\u52a8\u6001\u8c03\u6574 Pipeline&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;pipeline \u652f\u6301 addBefore\/addAfter\/remove\/replace \u8fd0\u884c\u671f\u64cd\u4f5c&#xff0c;\u6846\u67b6\u81ea\u52a8\u8c03\u5ea6\u7ebf\u7a0b\u5b89\u5168\u3002\u5178\u578b\u573a\u666f&#xff1a;\u63e1\u624b\u671f\u6302\u534f\u8bae\u534f\u5546\u4e0e\u9274\u6743 Handler&#xff0c;\u5b8c\u6210\u540e remove \u6362\u6210\u7a33\u6001\u94fe&#xff1b;\u534f\u8bae\u70ed\u5347\u7ea7\u7528 replace\u3002\u6ce8\u610f\u987a\u5e8f\u8bed\u4e49\u4ee5\u5b9e\u9645\u6267\u884c\u65f6\u523b\u4e3a\u51c6\u3002<\/p>\n<p>10. \u51fa\u7ad9\u4e8b\u4ef6\u5728 Pipeline \u4e2d\u7684\u4f20\u64ad\u6709\u4ec0\u4e48\u7279\u70b9&#xff1f;<\/p>\n<p>\u8981\u70b9&#xff1a;\u51fa\u7ad9\u4e8b\u4ef6\u4ece\u89e6\u53d1\u70b9&#xff08;\u6216 Tail&#xff09;\u5411 Head \u4f20\u64ad&#xff0c;\u53ea\u7ecf\u8fc7\u51fa\u7ad9\u578b&#xff08;Outbound\/Duplex&#xff09;Handler&#xff0c;\u5165\u7ad9 Handler \u88ab\u8df3\u8fc7\u3002\u5199\u64cd\u4f5c\u4e0d\u662f\u7acb\u5373\u6267\u884c&#xff1a;\u5148\u8fdb ChannelOutboundBuffer \u6392\u961f&#xff0c;flush \u65f6\u624d\u771f\u6b63\u5199\u5185\u6838&#xff1b;\u7ed3\u679c\u901a\u8fc7 Future\/Listener \u5f02\u6b65\u53cd\u9988\u3002\u51fa\u7ad9 Handler \u53ef\u5b9e\u73b0\u6539\u5199\u3001\u7edf\u8ba1\u3001\u9650\u6d41&#xff0c;\u4f46\u5fc5\u987b\u7ee7\u7eed\u8c03\u7528 ctx.write \u5426\u5219\u6d88\u606f\u88ab\u541e\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922013256-6ab1dac8048d4.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Netty Pipeline \u4e0e Handler \u4f53\u7cfb\u8be6\u89e3 \u5b9a\u4f4d&#xff1a;Netty \u76ee\u5f55\u7b2c 03 \u7bc7&#xff0c;Pipeline \u7ed3\u6784\u3001Handler \u4e0e Context\u3001\u4e8b\u4ef6\u4f20\u64ad\u673a\u5236\u4e0e\u7f16\u89e3\u7801\u63a5\u5165\u5168\u89e3 \u9002\u7528\u7248\u672c&#xff1a;Netty 4.1.x&#xff08;JDK 8&#xff09; \u76ee\u5f55<br \/>\nChannelPipelineChannelHandler \u4e0e Context\u4e8b\u4ef6\u4f20\u64ad\u673a\u5236SimpleChannelInboundHandler\u7f16\u89e3\u7801\u5668\u63a5\u5165\u4f4d\u7f6e\u603b\u7ed3\u5e38\u89c1<\/p>\n","protected":false},"author":2,"featured_media":108631,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[188,78],"topic":[],"class_list":["post-108632","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-188","tag-78"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Netty Pipeline \u4e0e Handler \u4f53\u7cfb\u8be6\u89e3 - \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\/108632.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Netty Pipeline \u4e0e Handler \u4f53\u7cfb\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Netty Pipeline \u4e0e Handler \u4f53\u7cfb\u8be6\u89e3 \u5b9a\u4f4d&#xff1a;Netty \u76ee\u5f55\u7b2c 03 \u7bc7&#xff0c;Pipeline \u7ed3\u6784\u3001Handler \u4e0e Context\u3001\u4e8b\u4ef6\u4f20\u64ad\u673a\u5236\u4e0e\u7f16\u89e3\u7801\u63a5\u5165\u5168\u89e3 \u9002\u7528\u7248\u672c&#xff1a;Netty 4.1.x&#xff08;JDK 8&#xff09; \u76ee\u5f55 ChannelPipelineChannelHandler \u4e0e Context\u4e8b\u4ef6\u4f20\u64ad\u673a\u5236SimpleChannelInboundHandler\u7f16\u89e3\u7801\u5668\u63a5\u5165\u4f4d\u7f6e\u603b\u7ed3\u5e38\u89c1\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/108632.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-22T01:32:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922013256-6ab1dac8048d4.png\" \/>\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=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/108632.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/108632.html\",\"name\":\"Netty Pipeline \u4e0e Handler \u4f53\u7cfb\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-22T01:32:57+00:00\",\"dateModified\":\"2026-09-22T01:32:57+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/108632.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/108632.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/108632.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Netty Pipeline \u4e0e Handler \u4f53\u7cfb\u8be6\u89e3\"}]},{\"@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":"Netty Pipeline \u4e0e Handler \u4f53\u7cfb\u8be6\u89e3 - \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\/108632.html","og_locale":"zh_CN","og_type":"article","og_title":"Netty Pipeline \u4e0e Handler \u4f53\u7cfb\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Netty Pipeline \u4e0e Handler \u4f53\u7cfb\u8be6\u89e3 \u5b9a\u4f4d&#xff1a;Netty \u76ee\u5f55\u7b2c 03 \u7bc7&#xff0c;Pipeline \u7ed3\u6784\u3001Handler \u4e0e Context\u3001\u4e8b\u4ef6\u4f20\u64ad\u673a\u5236\u4e0e\u7f16\u89e3\u7801\u63a5\u5165\u5168\u89e3 \u9002\u7528\u7248\u672c&#xff1a;Netty 4.1.x&#xff08;JDK 8&#xff09; \u76ee\u5f55 ChannelPipelineChannelHandler \u4e0e Context\u4e8b\u4ef6\u4f20\u64ad\u673a\u5236SimpleChannelInboundHandler\u7f16\u89e3\u7801\u5668\u63a5\u5165\u4f4d\u7f6e\u603b\u7ed3\u5e38\u89c1","og_url":"https:\/\/www.wsisp.com\/helps\/108632.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-22T01:32:57+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260922013256-6ab1dac8048d4.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/108632.html","url":"https:\/\/www.wsisp.com\/helps\/108632.html","name":"Netty Pipeline \u4e0e Handler \u4f53\u7cfb\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-22T01:32:57+00:00","dateModified":"2026-09-22T01:32:57+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/108632.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/108632.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/108632.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Netty Pipeline \u4e0e Handler \u4f53\u7cfb\u8be6\u89e3"}]},{"@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\/108632","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=108632"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/108632\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/108631"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=108632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=108632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=108632"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=108632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}