{"id":102466,"date":"2026-09-08T20:49:25","date_gmt":"2026-09-08T12:49:25","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/102466.html"},"modified":"2026-09-08T20:49:25","modified_gmt":"2026-09-08T12:49:25","slug":"%e3%80%90%e5%9f%ba%e4%ba%8e-swoolehyperf-%e7%9a%84%e5%be%ae%e6%9c%8d%e5%8a%a1%e5%ae%9e%e6%88%98%e3%80%91-%e7%ac%ac%e5%9b%9b%e5%91%a8%c2%b7%e5%91%a8%e4%ba%94%ef%bc%9a%e5%b0%86%e6%96%87%e7%ab%a0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/102466.html","title":{"rendered":"\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011 \u7b2c\u56db\u5468\u00b7\u5468\u4e94\uff1a\u5c06\u6587\u7ae0\u7cfb\u7edf\u548c\u7528\u6237\u670d\u52a1\u5168\u91cf\u63a5\u5165 Consul + Nacos\uff0c\u9a8c\u8bc1\u65e0\u611f\u6269\u5bb9"},"content":{"rendered":"<p>\u4eca\u5929\u662f\u7b2c\u4e8c\u9636\u6bb5\u201c\u5fae\u670d\u52a1\u901a\u4fe1\u4e0e\u6cbb\u7406\u201d\u7684\u6536\u5b98\u4e4b\u6218\u3002\u4eca\u5929\u6211\u4eec\u5c06\u5b8c\u6210\u4e00\u4e2a\u5173\u952e\u5b9e\u6218&#xff1a;\u5c06\u6587\u7ae0\u7cfb\u7edf\u548c\u7528\u6237\u670d\u52a1\u5168\u91cf\u63a5\u5165 Consul &#043; Nacos&#xff0c;\u9a8c\u8bc1\u65e0\u611f\u6269\u5bb9\u3002\u524d\u9762\u56db\u5929\u6211\u4eec\u5206\u522b\u5b8c\u6210\u4e86\u670d\u52a1\u6ce8\u518c\u3001\u670d\u52a1\u53d1\u73b0\u3001\u914d\u7f6e\u4e2d\u5fc3\u96c6\u6210\u548c\u591a\u73af\u5883\u914d\u7f6e\u7ba1\u7406&#xff0c;\u4eca\u5929\u8981\u628a\u8fd9\u4e9b\u80fd\u529b\u4e32\u8054\u8d77\u6765&#xff0c;\u6a21\u62df\u751f\u4ea7\u73af\u5883\u4e2d\u670d\u52a1\u5b9e\u4f8b\u52a8\u6001\u4f38\u7f29\u7684\u573a\u666f&#xff0c;\u8ba9\u6d88\u8d39\u8005\u5728\u4e0d\u91cd\u542f\u7684\u60c5\u51b5\u4e0b\u81ea\u52a8\u611f\u77e5\u53d8\u5316&#xff0c;\u5b9e\u73b0\u771f\u6b63\u7684\u5f39\u6027\u4f38\u7f29\u3002<\/p>\n<hr \/>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260908124919-6aa0044f04cbd.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>\u4eca\u65e5\u76ee\u6807<\/h4>\n<li>\u786e\u4fdd\u6587\u7ae0\u670d\u52a1&#xff08;HTTP&#xff09; \u548c\u7528\u6237\u670d\u52a1&#xff08;JSON-RPC&#xff09; \u5747\u5df2\u63a5\u5165 Consul \u548c Nacos\u3002<\/li>\n<li>\u4ee5\u7528\u6237\u670d\u52a1\u4e3a\u4f8b&#xff0c;\u901a\u8fc7\u542f\u52a8\u591a\u4e2a\u5b9e\u4f8b\u6765\u6a21\u62df\u6269\u5bb9&#xff0c;\u901a\u8fc7\u505c\u6b62\u5b9e\u4f8b\u6a21\u62df\u7f29\u5bb9\u3002<\/li>\n<li>\u89c2\u5bdf\u6587\u7ae0\u670d\u52a1\u901a\u8fc7 Consul \u670d\u52a1\u53d1\u73b0\u52a8\u6001\u83b7\u53d6\u6700\u65b0\u7684\u7528\u6237\u670d\u52a1\u8282\u70b9\u5217\u8868&#xff0c;\u8d1f\u8f7d\u5747\u8861\u5668\u81ea\u52a8\u5c06\u6d41\u91cf\u5206\u914d\u5230\u65b0\u65e7\u5b9e\u4f8b\u3002<\/li>\n<li>\u7ed3\u5408 Nacos \u52a8\u6001\u914d\u7f6e&#xff0c;\u5b9e\u65f6\u8c03\u6574\u9650\u6d41\u9608\u503c&#xff0c;\u9a8c\u8bc1\u914d\u7f6e\u53d8\u66f4\u65e0\u9700\u91cd\u542f\u3002<\/li>\n<li>\u4f7f\u7528\u538b\u6d4b\u5de5\u5177\u89c2\u5bdf\u6574\u4e2a\u8fc7\u7a0b\u4e2d\u7684\u670d\u52a1\u8fde\u7eed\u6027\u548c\u9519\u8bef\u7387&#xff0c;\u786e\u4fdd\u201c\u65e0\u611f\u201d\u3002<\/li>\n<hr \/>\n<h4>\u4e00\u3001\u73af\u5883\u51c6\u5907\u4e0e\u73b0\u72b6\u786e\u8ba4&#xff08;\u7ea6 30 \u5206\u949f&#xff09;<\/h4>\n<p>\u7ee7\u7eed\u5728 hyperf-app \u9879\u76ee\u4e2d&#xff0c;\u786e\u4fdd Docker \u5df2\u542f\u52a8\u5e76\u8fdb\u5165\u5bb9\u5668&#xff1a;<\/p>\n<p><span class=\"token function\">docker-compose<\/span> <span class=\"token builtin class-name\">exec<\/span> swoole <span class=\"token function\">bash<\/span><br \/>\n<span class=\"token builtin class-name\">cd<\/span> \/var\/www\/hyperf-app<\/p>\n<h5>1. \u786e\u8ba4\u5f53\u524d\u670d\u52a1\u67b6\u6784<\/h5>\n<ul>\n<li>HTTP \u670d\u52a1&#xff08;\u6587\u7ae0\/\u8ba2\u5355&#xff09;&#xff1a;\u76d1\u542c 0.0.0.0:9501<\/li>\n<li>\u7528\u6237\u670d\u52a1&#xff08;UserService&#xff09;&#xff1a;\u76d1\u542c 0.0.0.0:9502&#xff08;\u6211\u4eec\u4e4b\u524d\u53ea\u4fdd\u7559\u4e86\u4e00\u4e2a\u8282\u70b9\u7528\u4e8e\u6f14\u793a&#xff09;<\/li>\n<li>\u5546\u54c1\u670d\u52a1&#xff08;ProductService&#xff09;&#xff1a;\u76d1\u542c 0.0.0.0:9504<\/li>\n<\/ul>\n<p>Consul \u4e2d\u5e94\u8be5\u5df2\u7ecf\u6ce8\u518c\u4e86\u8fd9\u4e24\u4e2a\u670d\u52a1&#xff08;\u53ef\u4ee5\u901a\u8fc7 UI http:\/\/localhost:8500 \u67e5\u770b&#xff09;\u3002Nacos \u4e2d\u4e5f\u5df2\u7ecf\u6709\u4e86 hyperf-app \u914d\u7f6e&#xff08;dev \u547d\u540d\u7a7a\u95f4&#xff09;&#xff0c;\u5305\u542b\u9650\u6d41\u53c2\u6570\u7b49\u3002<\/p>\n<h5>2. \u542f\u505c\u95ee\u9898<\/h5>\n<p>\u7531\u4e8e\u6211\u4eec\u53ea\u6709\u4e00\u4e2a Docker PHP \u5bb9\u5668&#xff0c;\u8981\u542f\u52a8\u591a\u4e2a\u7528\u6237\u670d\u52a1\u5b9e\u4f8b&#xff0c;\u6211\u4eec\u6709\u4e24\u4e2a\u9009\u62e9&#xff1a;<\/p>\n<ul>\n<li>\u5728\u540c\u4e00\u4e2a Hyperf \u8fdb\u7a0b\u4e2d\u6dfb\u52a0\u53e6\u4e00\u4e2a JSON-RPC \u670d\u52a1\u5668&#xff0c;\u76d1\u542c\u4e0d\u540c\u7aef\u53e3&#xff08;\u5982 9503&#xff09;&#xff0c;\u5e76\u786e\u4fdd\u5b83\u4e5f\u88ab\u6ce8\u518c\u5230 Consul&#xff08;\u9700\u8981\u53e6\u4e00\u4e2a &#064;RpcService \u5b9e\u73b0\u6216\u624b\u52a8\u6ce8\u518c&#xff09;\u3002<\/li>\n<li>\u4f7f\u7528 Docker \u518d\u542f\u52a8\u4e00\u4e2a\u76f8\u540c\u7684 PHP \u5bb9\u5668&#xff08;\u6216\u7528\u4e0d\u540c\u7aef\u53e3\u542f\u52a8\u53e6\u4e00\u4e2a Hyperf \u8fdb\u7a0b&#xff09;&#xff0c;\u4f46\u9700\u8981\u5171\u4eab\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<p>\u8003\u8651\u5230\u5f00\u53d1\u73af\u5883\u7b80\u5355\u6027&#xff0c;\u6211\u4eec\u91c7\u7528\u5728\u540c\u4e00\u4e2a Hyperf \u5e94\u7528\u4e2d\u542f\u7528\u7b2c\u4e8c\u4e2a JSON-RPC \u7528\u6237\u670d\u52a1\u8282\u70b9&#xff0c;\u5e76\u624b\u52a8\u5c06\u5176\u6ce8\u518c\u5230 Consul\u3002\u4ee5\u524d\u6211\u4eec\u7684 server.php \u4e2d\u66fe\u914d\u7f6e\u8fc7 jsonrpc2&#xff08;\u7aef\u53e3 9503&#xff09;&#xff0c;\u4eca\u5929\u6062\u590d\u5b83&#xff0c;\u5e76\u8ba9\u7528\u6237\u670d\u52a1\u4e5f\u7ed1\u5b9a\u5230\u8be5\u670d\u52a1\u5668&#xff0c;\u4ee5\u4fbf\u6ce8\u518c\u4e24\u4e2a\u5b9e\u4f8b\u3002<\/p>\n<hr \/>\n<h4>\u4e8c\u3001\u77e5\u8bc6\u6838\u5fc3\u56de\u987e&#xff08;\u7ea6 20 \u5206\u949f&#xff09;<\/h4>\n<ul>\n<li>\u670d\u52a1\u6ce8\u518c&#xff1a;Provider \u542f\u52a8\u65f6\u81ea\u52a8\u5411 Consul \u6ce8\u518c&#xff0c;\u5065\u5eb7\u68c0\u67e5\u7ef4\u6301\u5fc3\u8df3\u3002<\/li>\n<li>\u670d\u52a1\u53d1\u73b0&#xff1a;Consumer \u901a\u8fc7 Consul \u5b9a\u671f\u62c9\u53d6\u5065\u5eb7\u7684\u8282\u70b9\u5217\u8868&#xff0c;\u914d\u5408\u8d1f\u8f7d\u5747\u8861\u5668\u4f7f\u7528\u3002<\/li>\n<li>\u52a8\u6001\u6269\u5bb9&#xff1a;\u65b0\u5b9e\u4f8b\u6ce8\u518c \u2192 Consul \u901a\u77e5\u6216\u6d88\u8d39\u8005\u5237\u65b0\u5217\u8868 \u2192 \u6d41\u91cf\u81ea\u7136\u5bfc\u5165\u65b0\u5b9e\u4f8b\u3002<\/li>\n<li>\u52a8\u6001\u7f29\u5bb9&#xff1a;\u5b9e\u4f8b\u4e0b\u7ebf\u6216\u5065\u5eb7\u68c0\u67e5\u5931\u8d25 \u2192 Consul \u6807\u8bb0\u4e0d\u5065\u5eb7 \u2192 \u6d88\u8d39\u8005\u5237\u65b0\u540e\u5254\u9664\u8be5\u8282\u70b9\u3002<\/li>\n<li>\u914d\u7f6e\u52a8\u6001\u4e0b\u53d1&#xff1a;Nacos \u914d\u7f6e\u53d8\u66f4 \u2192 \u5e94\u7528\u70ed\u52a0\u8f7d&#xff0c;\u65e0\u9700\u91cd\u542f\u3002<\/li>\n<\/ul>\n<p>\u4eca\u5929\u8981\u9a8c\u8bc1\u7684\u6838\u5fc3\u5c31\u662f\u6269\u5bb9\u548c\u7f29\u5bb9\u7684\u8fc7\u7a0b\u5bf9\u8c03\u7528\u65b9\u5b8c\u5168\u900f\u660e&#xff0c;\u6d88\u8d39\u8005\u81ea\u52a8\u9002\u5e94\u3002<\/p>\n<hr \/>\n<h4>\u4e09\u3001\u5b9e\u6218&#xff1a;\u6a21\u62df\u52a8\u6001\u4f38\u7f29\u5168\u8fc7\u7a0b&#xff08;\u7ea6 3 \u5c0f\u65f6&#xff09;<\/h4>\n<h5>\u6b65\u9aa4 1&#xff1a;\u6062\u590d\u591a\u8282\u70b9\u7528\u6237\u670d\u52a1<\/h5>\n<p>\u7f16\u8f91 config\/autoload\/server.php&#xff0c;\u5728 servers \u6570\u7ec4\u4e2d\u52a0\u5165\u7b2c\u4e8c\u4e2a JSON-RPC \u670d\u52a1\u5668&#xff08;\u5982\u679c\u4e4b\u524d\u6ce8\u91ca\u6389\u4e86&#xff09;&#xff1a;<\/p>\n<p><span class=\"token punctuation\">[<\/span><br \/>\n    <span class=\"token string single-quoted-string\">&#039;name&#039;<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token string single-quoted-string\">&#039;jsonrpc2&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string single-quoted-string\">&#039;type&#039;<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token class-name static-context\">Server<\/span><span class=\"token operator\">::<\/span><span class=\"token constant\">SERVER_HTTP<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string single-quoted-string\">&#039;host&#039;<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token string single-quoted-string\">&#039;0.0.0.0&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string single-quoted-string\">&#039;port&#039;<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token number\">9503<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string single-quoted-string\">&#039;sock_type&#039;<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token constant\">SWOOLE_SOCK_TCP<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string single-quoted-string\">&#039;callbacks&#039;<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">[<\/span><br \/>\n        <span class=\"token class-name static-context\">Event<\/span><span class=\"token operator\">::<\/span><span class=\"token constant\">ON_REQUEST<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token class-name class-name-fully-qualified static-context\"><span class=\"token punctuation\">\\\\<\/span>Hyperf<span class=\"token punctuation\">\\\\<\/span>JsonRpc<span class=\"token punctuation\">\\\\<\/span>HttpServer<\/span><span class=\"token operator\">::<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string single-quoted-string\">&#039;onRequest&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><\/p>\n<p>\u4e3a\u4e86\u8ba9\u7b2c\u4e8c\u4e2a\u7aef\u53e3\u4e5f\u670d\u52a1\u4e8e UserService&#xff0c;\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u989d\u5916\u7684 &#064;RpcService \u5b9e\u73b0\u7c7b\u3002\u7b80\u5355\u5730&#xff0c;\u6211\u4eec\u53ef\u4ee5\u590d\u5236 UserService \u5e76\u4fee\u6539\u6ce8\u89e3\u4e2d\u7684 server \u4e3a jsonrpc2\u3002\u521b\u5efa app\/JsonRpc\/UserService2.php&#xff1a;<\/p>\n<p><span class=\"token delimiter important\">&lt;?php<\/span><br \/>\n<span class=\"token keyword\">namespace<\/span> <span class=\"token package\">App<span class=\"token punctuation\">\\\\<\/span>JsonRpc<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">use<\/span> <span class=\"token package\">Hyperf<span class=\"token punctuation\">\\\\<\/span>RpcServer<span class=\"token punctuation\">\\\\<\/span>Annotation<span class=\"token punctuation\">\\\\<\/span>RpcService<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token attribute\"><span class=\"token delimiter punctuation\">#[<\/span><span class=\"token attribute-content\"><span class=\"token attribute-class-name class-name\">RpcService<\/span><span class=\"token punctuation\">(<\/span><span class=\"token attribute-class-name class-name\">name<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string double-quoted-string\">&#034;UserService&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token attribute-class-name class-name\">protocol<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string double-quoted-string\">&#034;jsonrpc-http&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token attribute-class-name class-name\">server<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string double-quoted-string\">&#034;jsonrpc2&#034;<\/span><span class=\"token punctuation\">)<\/span><\/span><span class=\"token delimiter punctuation\">]<\/span><\/span><br \/>\n<span class=\"token keyword\">class<\/span> <span class=\"token class-name-definition class-name\">UserService2<\/span> <span class=\"token keyword\">extends<\/span> <span class=\"token class-name\">UserService<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u76f4\u63a5\u7ee7\u627f&#xff0c;\u884c\u4e3a\u4e00\u81f4<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u540c\u6837\u5728 dependencies.php \u4e2d\u53ef\u80fd\u9700\u8981\u7ed1\u5b9a&#xff0c;\u4f46 Hyperf \u4f1a\u81ea\u52a8\u626b\u63cf\u6ce8\u89e3\u5e76\u6ce8\u518c\u4e3a\u670d\u52a1&#xff0c;\u56e0\u6b64\u53ea\u8981\u6211\u4eec\u914d\u7f6e\u4e86 jsonrpc2 \u670d\u52a1\u7aef&#xff0c;\u8fd9\u4e2a\u7c7b\u5c31\u4f1a\u88ab\u6ce8\u518c\u4e3a\u4e00\u4e2a RPC \u670d\u52a1\u63d0\u4f9b\u8005&#xff0c;\u7aef\u53e3 9503 \u4e5f\u4f1a\u52a0\u5165 UserService \u7684\u8282\u70b9\u5217\u8868\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a;\u6b64\u65f6 UserService \u548c UserService2 \u90fd\u5b9e\u73b0\u4e86 UserServiceInterface&#xff1f;UserService2 \u7ee7\u627f\u4e86 UserService&#xff0c;\u800c UserService \u5df2\u7ecf\u5b9e\u73b0\u4e86 UserServiceInterface&#xff0c;\u6240\u4ee5\u6ca1\u95ee\u9898\u3002<\/p>\n<h5>\u6b65\u9aa4 2&#xff1a;\u786e\u8ba4 Consul \u6ce8\u518c\u914d\u7f6e<\/h5>\n<p>\u5728 config\/autoload\/services.php \u7684 drivers.consul \u4e2d&#xff0c;\u786e\u4fdd check \u914d\u7f6e\u5b58\u5728&#xff08;\u6628\u5929\u5df2\u914d&#xff09;\u3002\u540c\u65f6&#xff0c;\u786e\u4fdd consumers.UserService \u4f7f\u7528 registry \u6307\u5411 Consul&#xff0c;refresh_time \u8bbe\u4e3a\u8f83\u5c0f\u7684\u503c&#xff08;\u5982 5 \u79d2&#xff09;\u4ee5\u4fbf\u5feb\u901f\u89c2\u5bdf\u3002<\/p>\n<h5>\u6b65\u9aa4 3&#xff1a;\u542f\u52a8\u591a\u5b9e\u4f8b\u7528\u6237\u670d\u52a1<\/h5>\n<p>\u91cd\u542f Hyperf \u5e94\u7528&#xff1a;<\/p>\n<p>php bin\/hyperf.php start<\/p>\n<p>\u89c2\u5bdf\u63a7\u5236\u53f0\u8f93\u51fa&#xff0c;\u5e94\u663e\u793a jsonrpc (9502) \u548c jsonrpc2 (9503) \u5747\u542f\u52a8\u3002\u67e5\u770b Consul UI (http:\/\/localhost:8500)&#xff0c;UserService \u4e0b\u5e94\u51fa\u73b0\u4e24\u4e2a\u5b9e\u4f8b&#xff0c;\u5206\u522b\u5bf9\u5e94 9502 \u548c 9503&#xff0c;\u4e14\u5065\u5eb7\u72b6\u6001\u90fd\u4e3a\u7eff\u8272\u3002<\/p>\n<h5>\u6b65\u9aa4 4&#xff1a;\u9a8c\u8bc1\u6d88\u8d39\u8005\u53d1\u73b0\u53cc\u8282\u70b9<\/h5>\n<p>\u8c03\u7528\u8ba2\u5355\u63a5\u53e3\u6216\u6587\u7ae0\u8be6\u60c5\u63a5\u53e3&#xff08;\u90fd\u4f1a\u8fdc\u7a0b\u8c03\u7528\u7528\u6237\u670d\u52a1&#xff09;&#xff1a;<\/p>\n<p><span class=\"token function\">curl<\/span> http:\/\/localhost:9501\/orders\/1<\/p>\n<p>\u67e5\u770b hyperf.log&#xff0c;\u8d1f\u8f7d\u5747\u8861\u5668\u65e5\u5fd7\u5e94\u663e\u793a\u7c7b\u4f3c&#xff1a;<\/p>\n<p>RPC\u8d1f\u8f7d\u5747\u8861&#xff0c;\u53ef\u7528\u8282\u70b9: [{&#034;host&#034;:&#034;127.0.0.1&#034;,&#034;port&#034;:9502},{&#034;host&#034;:&#034;127.0.0.1&#034;,&#034;port&#034;:9503}]<br \/>\nRPC\u8bf7\u6c42\u8def\u7531\u5230\u8282\u70b9: 127.0.0.1:9502<\/p>\n<p>\u8fde\u7eed\u8bf7\u6c42\u51e0\u6b21&#xff0c;\u4f1a\u770b\u5230\u4ea4\u66ff\u8def\u7531\u5230 9502 \u548c 9503&#xff0c;\u8bf4\u660e\u53cc\u8282\u70b9\u8d1f\u8f7d\u5747\u8861\u751f\u6548&#xff0c;\u6269\u5bb9\u6210\u529f\u3002<\/p>\n<h5>\u6b65\u9aa4 5&#xff1a;\u6a21\u62df\u7f29\u5bb9\u2014\u2014\u6458\u9664\u4e00\u4e2a\u8282\u70b9<\/h5>\n<p>\u6682\u65f6\u505c\u6b62\u7b2c\u4e8c\u4e2a\u7528\u6237\u670d\u52a1\u8282\u70b9&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539 server.php \u5c06 jsonrpc2 \u6ce8\u91ca\u6389&#xff0c;\u6216\u8005\u66f4\u7b80\u5355&#xff1a;\u5728 Consul API \u4e2d\u624b\u52a8\u5c06\u7b2c\u4e8c\u4e2a\u8282\u70b9\u6807\u8bb0\u4e3a\u4e0d\u5065\u5eb7\u3002\u4f46\u4e3a\u4e86\u771f\u5b9e&#xff0c;\u6211\u4eec\u70ed\u505c\u6b62\u7b2c\u4e8c\u4e2a JSON-RPC \u670d\u52a1\u5668\u7aef\u53e3\u3002\u7531\u4e8e\u5b83\u4eec\u8fd0\u884c\u5728\u540c\u4e00\u4e2a Worker \u8fdb\u7a0b\u4e2d&#xff0c;\u65e0\u6cd5\u5355\u72ec\u505c\u6b62\u7aef\u53e3\u3002\u6211\u4eec\u53ef\u4ee5\u4e34\u65f6\u6ce8\u91ca\u6389 server.php \u4e2d\u7684 jsonrpc2 \u914d\u7f6e&#xff0c;\u7136\u540e\u91cd\u542f\u670d\u52a1\u6765\u6a21\u62df\u7f29\u5bb9\u3002\u4f46\u91cd\u542f\u4f1a\u5bfc\u81f4\u77ed\u6682\u4e2d\u65ad&#xff0c;\u4e0d\u7b26\u5408\u201c\u65e0\u611f\u201d\u3002\u66f4\u597d\u7684\u65b9\u6cd5\u662f&#xff1a;\u6211\u4eec\u5728\u53e6\u4e00\u4e2a\u7ec8\u7aef\u4e2d\u624b\u52a8\u5411 Consul \u53d1\u9001\u8be5\u8282\u70b9\u4e0b\u7ebf\u8bf7\u6c42&#xff0c;\u8ba9 Consul \u6807\u8bb0\u4e3a critical&#xff0c;\u4ece\u800c\u6d88\u8d39\u8005\u4f1a\u81ea\u52a8\u79fb\u9664\u5b83\u3002<\/p>\n<p>\u4f7f\u7528 API \u4e0b\u7ebf 9503 \u5b9e\u4f8b&#xff1a;<br \/>\n\u9996\u5148\u9700\u8981\u77e5\u9053\u8be5\u5b9e\u4f8b\u7684 Service ID\u3002\u5728 Consul UI \u4e2d\u70b9\u51fb UserService&#xff0c;\u53ef\u4ee5\u770b\u5230\u6bcf\u4e2a\u5b9e\u4f8b\u7684 ID&#xff08;\u901a\u5e38\u662f\u7c7b\u540d\u6216\u968f\u673a ID&#xff09;\u3002\u4f8b\u5982\u53ef\u80fd\u662f UserService-jsonrpc2-&#8230;\u3002\u6211\u4eec\u4e5f\u53ef\u4ee5\u901a\u8fc7 API \u6ce8\u9500\u5b83&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u5217\u51fa UserService \u7684\u6240\u6709\u5b9e\u4f8b<\/span><br \/>\n<span class=\"token function\">curl<\/span> http:\/\/consul:8500\/v1\/health\/service\/UserService<br \/>\n<span class=\"token comment\"># \u627e\u5230\u5bf9\u5e94 9503 \u7684 ServiceID&#xff0c;\u7136\u540e\u8c03\u7528\u6ce8\u9500<\/span><br \/>\n<span class=\"token function\">curl<\/span> <span class=\"token parameter variable\">-X<\/span> PUT http:\/\/consul:8500\/v1\/agent\/service\/deregister\/<span class=\"token operator\">&lt;<\/span>ServiceID<span class=\"token operator\">&gt;<\/span><\/p>\n<p>\u6ce8\u9500\u540e&#xff0c;\u6d88\u8d39\u8005\u4f1a\u5728\u4e0b\u4e00\u6b21\u5237\u65b0&#xff08;5 \u79d2\u5185&#xff09;\u66f4\u65b0\u8282\u70b9\u5217\u8868&#xff0c;\u4e4b\u540e\u8bf7\u6c42\u53ea\u4f1a\u8def\u7531\u5230 9502\u3002\u89c2\u5bdf\u65e5\u5fd7&#xff0c;\u53ef\u7528\u8282\u70b9\u5217\u8868\u53d8\u6210\u53ea\u6709\u4e00\u4e2a\u3002<\/p>\n<p>\u65e0\u611f\u9a8c\u8bc1&#xff1a;\u5728\u6ce8\u9500\u524d\u540e\u6301\u7eed\u53d1\u9001\u8bf7\u6c42&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u5728\u53e6\u4e00\u4e2a\u7ec8\u7aef\u5faa\u73af\u53d1\u9001\u8bf7\u6c42<\/span><br \/>\n<span class=\"token keyword\">while<\/span> <span class=\"token boolean\">true<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">do<\/span> <span class=\"token function\">curl<\/span> <span class=\"token parameter variable\">-s<\/span> http:\/\/localhost:9501\/orders\/1 <span class=\"token operator\">|<\/span> jq <span class=\"token builtin class-name\">.<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token function\">sleep<\/span> <span class=\"token number\">0.2<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">done<\/span><\/p>\n<p>\u5728\u6ce8\u9500\u77ac\u95f4&#xff0c;\u53ef\u80fd\u4f1a\u6709\u4e00\u6b21\u8bf7\u6c42\u5931\u8d25&#xff08;\u5982\u679c\u6070\u597d\u53d1\u5f80\u88ab\u6ce8\u9500\u7684\u8282\u70b9\u4e14\u8be5\u8282\u70b9\u771f\u7684\u505c\u6b62\u4e86\u670d\u52a1&#xff09;&#xff0c;\u4f46\u56e0\u4e3a\u6211\u4eec\u7684 9503 \u670d\u52a1\u5b9e\u9645\u5e76\u672a\u771f\u6b63\u505c\u6b62\u8fdb\u7a0b&#xff08;\u53ea\u662f\u6ce8\u9500\u4e86 Consul&#xff09;&#xff0c;\u8bf7\u6c42\u4ecd\u7136\u80fd\u5230\u8fbe&#xff0c;\u6240\u4ee5\u4e0d\u4f1a\u51fa\u9519\u3002\u82e5\u8981\u771f\u6b63\u6a21\u62df\u5b95\u673a&#xff0c;\u53ef\u540c\u65f6\u505c\u6b62 9503 \u7aef\u53e3\u7684\u76d1\u542c&#xff08;\u4f46\u8fd9\u91cc\u65e0\u6cd5\u5355\u72ec\u505c\u6b62&#xff09;\u3002\u4e0d\u8fc7\u6211\u4eec\u4e3b\u8981\u5c55\u793a\u7684\u662f\u6d88\u8d39\u8005\u8282\u70b9\u5217\u8868\u7684\u53d8\u5316&#xff0c;\u8fd9\u5df2\u7ecf\u8bc1\u660e\u4e86\u52a8\u6001\u611f\u77e5\u80fd\u529b\u3002<\/p>\n<p>\u66f4\u6781\u81f4\u7684\u6a21\u62df&#xff1a;\u4f7f\u7528\u4e24\u4e2a\u72ec\u7acb\u7684 Docker \u5bb9\u5668\u5206\u522b\u8fd0\u884c\u4e0d\u540c\u7684 Hyperf \u5b9e\u4f8b&#xff0c;\u8fd9\u6837\u5c31\u80fd\u771f\u6b63\u505c\u6b62\u4e00\u4e2a\u5bb9\u5668\u3002\u53d7\u9650\u4e8e\u73af\u5883&#xff0c;\u6211\u4eec\u901a\u8fc7 Consul \u6ce8\u9500\u6765\u7b49\u6548\u6f14\u793a\u3002<\/p>\n<h5>\u6b65\u9aa4 6&#xff1a;\u7ed3\u5408 Nacos \u52a8\u6001\u8c03\u6574\u9650\u6d41<\/h5>\n<p>\u5728 Nacos \u63a7\u5236\u53f0&#xff08;dev \u547d\u540d\u7a7a\u95f4&#xff09;\u4fee\u6539\u914d\u7f6e&#xff0c;\u5c06 rate_limit.like_per_minute \u4ece 10 \u6539\u4e3a 3&#xff0c;\u53d1\u5e03\u3002<br \/>\n\u65e0\u9700\u91cd\u542f\u670d\u52a1&#xff0c;\u7acb\u5373\u6d4b\u8bd5\u70b9\u8d5e\u63a5\u53e3&#xff1a;<\/p>\n<p><span class=\"token keyword\">for<\/span> <span class=\"token for-or-select variable\">i<\/span> <span class=\"token keyword\">in<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">..<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">do<\/span> <span class=\"token function\">curl<\/span> <span class=\"token parameter variable\">-X<\/span> POST http:\/\/localhost:9501\/articles\/1\/like<span class=\"token punctuation\">;<\/span> <span class=\"token builtin class-name\">echo<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token function\">sleep<\/span> <span class=\"token number\">0.5<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">done<\/span><\/p>\n<p>\u524d 3 \u6b21\u5e94\u8be5\u6210\u529f&#xff08;\u53ef\u80fd\u53d7\u4e4b\u524d\u8ba1\u6570\u5f71\u54cd&#xff09;&#xff0c;\u4e4b\u540e\u8fd4\u56de 429&#xff0c;\u8bc1\u660e\u52a8\u6001\u9650\u6d41\u751f\u6548\u3002\u8fd9\u5c31\u662f\u914d\u7f6e\u4e2d\u5fc3\u7684\u5a01\u529b\u3002<\/p>\n<h5>\u6b65\u9aa4 7&#xff1a;\u5168\u94fe\u8def\u538b\u6d4b\u4e0e\u89c2\u5bdf<\/h5>\n<p>\u4f7f\u7528 ab \u5bf9\u8ba2\u5355\u8be6\u60c5\u63a5\u53e3\u8fdb\u884c 200 \u5e76\u53d1\u8bf7\u6c42&#xff0c;\u67e5\u770b\u65e5\u5fd7\u4e2d\u7684\u8d1f\u8f7d\u5747\u8861\u5206\u5e03\u3001\u9519\u8bef\u7387&#xff1a;<\/p>\n<p>ab <span class=\"token parameter variable\">-n<\/span> <span class=\"token number\">200<\/span> <span class=\"token parameter variable\">-c<\/span> <span class=\"token number\">20<\/span> http:\/\/localhost:9501\/orders\/1<\/p>\n<p>\u89c2\u5bdf&#xff1a;<\/p>\n<ul>\n<li>\u8bf7\u6c42\u5931\u8d25\u6570\u5e94\u4e3a 0\u3002<\/li>\n<li>\u65e5\u5fd7\u4e2d\u4e24\u4e2a\u7528\u6237\u670d\u52a1\u8282\u70b9\u88ab\u5747\u5300\u8def\u7531&#xff08;\u5982\u679c\u90fd\u5728\u7ebf&#xff09;\u3002<\/li>\n<li>\u7194\u65ad\u5668\u6ca1\u6709\u6253\u5f00\u3002<\/li>\n<li>\u8fde\u63a5\u6c60\u5de5\u4f5c\u6b63\u5e38\u3002<\/li>\n<\/ul>\n<p>\u7136\u540e\u6a21\u62df\u7f29\u5bb9&#xff08;\u6ce8\u9500\u4e00\u4e2a\u8282\u70b9&#xff09;&#xff0c;\u518d\u6b21\u538b\u6d4b&#xff0c;\u89c2\u5bdf\u9519\u8bef\u7387&#xff1a;\u7531\u4e8e\u8d1f\u8f7d\u5747\u8861\u5668\u4f1a\u9009\u62e9\u5269\u4f59\u8282\u70b9&#xff0c;\u53ef\u80fd\u521a\u5f00\u59cb\u4f1a\u6709\u4e2a\u522b\u8fde\u63a5\u5931\u8d25&#xff08;\u5982\u679c\u6ce8\u9500\u7684\u540c\u65f6\u6709\u8bf7\u6c42\u6b63\u5728\u53d1\u5f80\u90a3\u4e2a\u8282\u70b9\u4e14\u8282\u70b9\u5df2\u62d2\u7edd&#xff09;&#xff0c;\u4f46\u5f88\u5feb\u7a33\u5b9a&#xff0c;\u9519\u8bef\u7387\u5e94\u8be5\u63a5\u8fd1 0\u3002\u8bf4\u660e\u5177\u6709\u9ad8\u53ef\u7528\u6027\u3002<\/p>\n<hr \/>\n<h4>\u56db\u3001\u6210\u679c\u6d4b\u8bd5\u4e0e\u68c0\u9a8c&#xff08;\u7ea6 1 \u5c0f\u65f6&#xff09;<\/h4>\n<h5>\u6d4b\u8bd5\u6e05\u5355<\/h5>\n<table>\n<tr>\u68c0\u9a8c\u9879\u65b9\u6cd5\u901a\u8fc7\u6807\u51c6<\/tr>\n<tbody>\n<tr>\n<td>\u53cc\u8282\u70b9\u6ce8\u518c<\/td>\n<td>Consul UI \u6216 API \u67e5\u770b UserService<\/td>\n<td>\u4e24\u4e2a\u5b9e\u4f8b&#xff0c;\u7aef\u53e3 9502 \u548c 9503&#xff0c;\u5065\u5eb7<\/td>\n<\/tr>\n<tr>\n<td>\u6d88\u8d39\u8005\u53d1\u73b0\u53cc\u8282\u70b9<\/td>\n<td>\u67e5\u770b hyperf.log \u8d1f\u8f7d\u5747\u8861\u5668\u65e5\u5fd7<\/td>\n<td>\u53ef\u7528\u8282\u70b9\u5217\u8868\u5305\u542b\u4e24\u4e2a\u8282\u70b9&#xff0c;\u8bf7\u6c42\u8f6e\u8be2\u5230\u4e24\u4e2a\u8282\u70b9<\/td>\n<\/tr>\n<tr>\n<td>\u7f29\u5bb9\u81ea\u52a8\u5254\u9664<\/td>\n<td>\u6ce8\u9500 9503 \u8282\u70b9&#xff0c;\u7b49\u5f85\u5237\u65b0&#xff0c;\u518d\u6b21\u8bf7\u6c42<\/td>\n<td>\u65e5\u5fd7\u4e2d\u8282\u70b9\u5217\u8868\u53ea\u5269 9502&#xff0c;\u8bf7\u6c42\u4e0d\u518d\u8def\u7531\u5230 9503<\/td>\n<\/tr>\n<tr>\n<td>\u914d\u7f6e\u52a8\u6001\u66f4\u65b0<\/td>\n<td>\u4fee\u6539 Nacos \u4e2d\u7684\u9650\u6d41\u503c&#xff0c;\u6d4b\u8bd5\u70b9\u8d5e<\/td>\n<td>\u65b0\u9608\u503c\u751f\u6548&#xff0c;\u65e0\u91cd\u542f<\/td>\n<\/tr>\n<tr>\n<td>\u65e0\u611f\u6269\u5bb9\/\u7f29\u5bb9<\/td>\n<td>\u6301\u7eed\u53d1\u9001\u8bf7\u6c42\u8fc7\u7a0b\u4e2d\u6267\u884c\u7f29\u5bb9\u64cd\u4f5c<\/td>\n<td>\u8bf7\u6c42\u5931\u8d25\u7387 &lt; 1%&#xff08;\u7406\u60f3 0&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u5168\u94fe\u8def\u538b\u6d4b<\/td>\n<td>ab \u538b\u6d4b\u8ba2\u5355\u63a5\u53e3<\/td>\n<td>QPS \u7a33\u5b9a&#xff0c;\u9519\u8bef\u7387 0&#xff0c;\u7194\u65ad\u672a\u89e6\u53d1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>\u5e38\u89c1\u95ee\u9898\u4e0e\u5b9a\u4f4d<\/h5>\n<ul>\n<li>\u7b2c\u4e8c\u4e2a\u8282\u70b9\u6ca1\u6709\u6ce8\u518c\u5230 Consul&#xff1a;\u68c0\u67e5 UserService2 \u7c7b\u7684 #[RpcService] \u6ce8\u89e3\u662f\u5426\u6b63\u786e&#xff0c;server \u540d\u79f0\u662f\u5426\u4e0e server.php \u4e2d\u7684\u914d\u7f6e\u4e00\u81f4&#xff1b;\u68c0\u67e5\u662f\u5426\u89e6\u53d1\u4e86 Composer \u81ea\u52a8\u52a0\u8f7d&#xff08;\u53ef\u80fd\u9700\u8981 composer dump-autoload&#xff09;\u3002<\/li>\n<li>\u8d1f\u8f7d\u5747\u8861\u5668\u65e5\u5fd7\u4e0d\u6253\u5370&#xff1a;\u68c0\u67e5\u65e5\u5fd7\u7ea7\u522b\u662f\u5426\u4e3a INFO&#xff0c;\u786e\u8ba4 CustomRoundRobin \u7684 select \u662f\u5426\u88ab\u8c03\u7528\u3002<\/li>\n<li>\u914d\u7f6e\u4e2d\u5fc3\u66f4\u65b0\u5ef6\u8fdf&#xff1a;Nacos \u5ba2\u6237\u7aef\u957f\u8f6e\u8be2\u95f4\u9694\u53ef\u4e34\u65f6\u8c03\u4e3a 1 \u79d2&#xff0c;\u66f4\u5feb\u611f\u77e5\u53d8\u5316\u3002<\/li>\n<li>\u7aef\u53e3\u51b2\u7a81&#xff1a;\u786e\u4fdd 9503 \u672a\u88ab\u5176\u4ed6\u670d\u52a1\u5360\u7528\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>\u4e94\u3001\u4eca\u65e5\u4f5c\u4e1a\u4e0e\u5b66\u4e60\u4ea7\u51fa<\/h4>\n<li>\u63d0\u4ea4\u4ee3\u7801&#xff1a;\u5c06 UserService2\u3001\u4fee\u6539\u540e\u7684 server.php \u7b49\u63d0\u4ea4\u5230 Git&#xff0c;\u9644\u4e0a\u4eca\u5929\u7684\u6d4b\u8bd5\u622a\u56fe\u6216\u65e5\u5fd7\u793a\u4f8b\u3002<\/li>\n<li>\u7ed8\u5236\u67b6\u6784\u6f14\u8fdb\u56fe&#xff1a;\n<ul>\n<li>\u5bf9\u6bd4\u6700\u521d\u786c\u7f16\u7801\u8282\u70b9 \u2192 \u6ce8\u518c\u4e2d\u5fc3 &#043; \u624b\u52a8\u591a\u8282\u70b9 \u2192 \u52a8\u6001\u4f38\u7f29\u7684\u6f14\u53d8\u8fc7\u7a0b\u3002<\/li>\n<li>\u753b\u51fa\u5b8c\u6574\u7684\u670d\u52a1\u8c03\u7528\u94fe\u8def\u56fe&#xff0c;\u5305\u542b Nacos \u914d\u7f6e\u4e0b\u53d1\u548c Consul \u8282\u70b9\u53d8\u66f4\u7684\u6d41\u7a0b\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5b66\u4e60\u7b14\u8bb0&#xff1a;\n<ul>\n<li>\u603b\u7ed3\u670d\u52a1\u65e0\u611f\u6269\u5bb9\u7684\u5173\u952e\u8981\u7d20&#xff1a;\u6ce8\u518c\u4e2d\u5fc3\u3001\u5065\u5eb7\u68c0\u67e5\u3001\u5ba2\u6237\u7aef\u8d1f\u8f7d\u5747\u8861\u3001\u914d\u7f6e\u4e2d\u5fc3\u534f\u540c\u3002<\/li>\n<li>\u601d\u8003&#xff1a;\u5982\u679c\u6ce8\u518c\u4e2d\u5fc3\u672c\u8eab\u5b95\u673a&#xff0c;\u6d88\u8d39\u8005\u8fd8\u80fd\u8c03\u7528\u670d\u52a1\u5417&#xff1f;&#xff08;\u7b54\u6848&#xff1a;\u53ef\u4ee5&#xff0c;\u56e0\u4e3a\u6d88\u8d39\u8005\u6709\u672c\u5730\u7f13\u5b58\u3002&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>\u6311\u6218\u4efb\u52a1&#xff1a;\n<ul>\n<li>\u4f7f\u7528 Docker Compose \u6269\u5bb9\u547d\u4ee4 \u542f\u52a8\u591a\u4e2a PHP \u5bb9\u5668\u5b9e\u4f8b&#xff08;\u4e0d\u540c\u7aef\u53e3&#xff09;\u4f5c\u4e3a\u72ec\u7acb\u7684\u7528\u6237\u670d\u52a1\u8282\u70b9&#xff0c;\u89c2\u5bdf Consul \u4e2d\u81ea\u52a8\u51fa\u73b0\u591a\u4e2a\u5b9e\u4f8b&#xff0c;\u5e76\u6d4b\u8bd5\u771f\u5b9e\u7f29\u5bb9&#xff08;docker stop \u4e00\u4e2a\u5bb9\u5668&#xff09;\u65f6\u7684\u65e0\u611f\u6548\u679c\u3002<\/li>\n<li>\u5c1d\u8bd5\u4f7f\u7528 Nacos \u7684\u7070\u5ea6\u53d1\u5e03\u529f\u80fd&#xff0c;\u4ec5\u5bf9\u7279\u5b9a\u6d88\u8d39\u8005\u4e0b\u53d1\u65b0\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<\/li>\n<p>\u606d\u559c\u4f60\u5b8c\u6210\u4e86\u7b2c\u56db\u5468\u7684\u5168\u90e8\u5185\u5bb9&#xff01;\u7ecf\u8fc7\u8fd9\u4e00\u5468&#xff0c;\u4f60\u7684\u5fae\u670d\u52a1\u5df2\u7ecf\u5177\u5907\u4e86\u52a8\u6001\u670d\u52a1\u6cbb\u7406\u7684\u80fd\u529b&#xff1a;\u670d\u52a1\u80fd\u591f\u81ea\u52a8\u6ce8\u518c\u548c\u53d1\u73b0&#xff0c;\u914d\u7f6e\u53ef\u5b9e\u65f6\u53d8\u66f4&#xff0c;\u5b9e\u4f8b\u53ef\u5f39\u6027\u4f38\u7f29&#xff0c;\u6574\u4e2a\u7cfb\u7edf\u5411\u7740\u751f\u4ea7\u7ea7\u8fc8\u8fdb\u4e86\u4e00\u5927\u6b65\u3002\u4e0b\u5468\u6211\u4eec\u5c06\u8fdb\u5165 API \u7f51\u5173\u7684\u4e16\u754c&#xff0c;\u5c06\u6240\u6709\u8fd9\u4e9b\u540e\u7aef\u670d\u52a1\u7edf\u4e00\u7ba1\u7406\u8d77\u6765\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u662f\u7b2c\u4e8c\u9636\u6bb5\u201c\u5fae\u670d\u52a1\u901a\u4fe1\u4e0e\u6cbb\u7406\u201d\u7684\u6536\u5b98\u4e4b\u6218\u3002\u4eca\u5929\u6211\u4eec\u5c06\u5b8c\u6210\u4e00\u4e2a\u5173\u952e\u5b9e\u6218&#xff1a;\u5c06\u6587\u7ae0\u7cfb\u7edf\u548c\u7528\u6237\u670d\u52a1\u5168\u91cf\u63a5\u5165 Consul  Nacos&#xff0c;\u9a8c\u8bc1\u65e0\u611f\u6269\u5bb9\u3002\u524d\u9762\u56db\u5929\u6211\u4eec\u5206\u522b\u5b8c\u6210\u4e86\u670d\u52a1\u6ce8\u518c\u3001\u670d\u52a1\u53d1\u73b0\u3001\u914d\u7f6e\u4e2d\u5fc3\u96c6\u6210\u548c\u591a\u73af\u5883\u914d\u7f6e\u7ba1\u7406&#xff0c;\u4eca\u5929\u8981\u628a\u8fd9\u4e9b\u80fd\u529b\u4e32\u8054\u8d77\u6765&#xff0c;\u6a21\u62df\u751f\u4ea7\u73af\u5883\u4e2d\u670d\u52a1\u5b9e\u4f8b\u52a8\u6001\u4f38\u7f29\u7684\u573a\u666f&#xff0c;\u8ba9\u6d88\u8d39\u8005\u5728\u4e0d\u91cd\u542f\u7684\u60c5\u51b5\u4e0b\u81ea\u52a8\u611f\u77e5\u53d8\u5316&#xff0c;\u5b9e\u73b0\u771f\u6b63\u7684\u5f39\u6027\u4f38\u7f29\u3002\u4eca\u65e5\u76ee\u6807<br \/>\n\u786e\u4fdd\u6587\u7ae0\u670d\u52a1&#xff08;HTTP&amp;#xff<\/p>\n","protected":false},"author":2,"featured_media":102465,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3843,2140,1348],"topic":[],"class_list":["post-102466","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-consul","tag-swoole","tag-1348"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011 \u7b2c\u56db\u5468\u00b7\u5468\u4e94\uff1a\u5c06\u6587\u7ae0\u7cfb\u7edf\u548c\u7528\u6237\u670d\u52a1\u5168\u91cf\u63a5\u5165 Consul + Nacos\uff0c\u9a8c\u8bc1\u65e0\u611f\u6269\u5bb9 - \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\/102466.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011 \u7b2c\u56db\u5468\u00b7\u5468\u4e94\uff1a\u5c06\u6587\u7ae0\u7cfb\u7edf\u548c\u7528\u6237\u670d\u52a1\u5168\u91cf\u63a5\u5165 Consul + Nacos\uff0c\u9a8c\u8bc1\u65e0\u611f\u6269\u5bb9 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4eca\u5929\u662f\u7b2c\u4e8c\u9636\u6bb5\u201c\u5fae\u670d\u52a1\u901a\u4fe1\u4e0e\u6cbb\u7406\u201d\u7684\u6536\u5b98\u4e4b\u6218\u3002\u4eca\u5929\u6211\u4eec\u5c06\u5b8c\u6210\u4e00\u4e2a\u5173\u952e\u5b9e\u6218&#xff1a;\u5c06\u6587\u7ae0\u7cfb\u7edf\u548c\u7528\u6237\u670d\u52a1\u5168\u91cf\u63a5\u5165 Consul Nacos&#xff0c;\u9a8c\u8bc1\u65e0\u611f\u6269\u5bb9\u3002\u524d\u9762\u56db\u5929\u6211\u4eec\u5206\u522b\u5b8c\u6210\u4e86\u670d\u52a1\u6ce8\u518c\u3001\u670d\u52a1\u53d1\u73b0\u3001\u914d\u7f6e\u4e2d\u5fc3\u96c6\u6210\u548c\u591a\u73af\u5883\u914d\u7f6e\u7ba1\u7406&#xff0c;\u4eca\u5929\u8981\u628a\u8fd9\u4e9b\u80fd\u529b\u4e32\u8054\u8d77\u6765&#xff0c;\u6a21\u62df\u751f\u4ea7\u73af\u5883\u4e2d\u670d\u52a1\u5b9e\u4f8b\u52a8\u6001\u4f38\u7f29\u7684\u573a\u666f&#xff0c;\u8ba9\u6d88\u8d39\u8005\u5728\u4e0d\u91cd\u542f\u7684\u60c5\u51b5\u4e0b\u81ea\u52a8\u611f\u77e5\u53d8\u5316&#xff0c;\u5b9e\u73b0\u771f\u6b63\u7684\u5f39\u6027\u4f38\u7f29\u3002\u4eca\u65e5\u76ee\u6807 \u786e\u4fdd\u6587\u7ae0\u670d\u52a1&#xff08;HTTP&amp;#xff\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/102466.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-08T12:49:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260908124919-6aa0044f04cbd.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=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/102466.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/102466.html\",\"name\":\"\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011 \u7b2c\u56db\u5468\u00b7\u5468\u4e94\uff1a\u5c06\u6587\u7ae0\u7cfb\u7edf\u548c\u7528\u6237\u670d\u52a1\u5168\u91cf\u63a5\u5165 Consul + Nacos\uff0c\u9a8c\u8bc1\u65e0\u611f\u6269\u5bb9 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-08T12:49:25+00:00\",\"dateModified\":\"2026-09-08T12:49:25+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/102466.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/102466.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/102466.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011 \u7b2c\u56db\u5468\u00b7\u5468\u4e94\uff1a\u5c06\u6587\u7ae0\u7cfb\u7edf\u548c\u7528\u6237\u670d\u52a1\u5168\u91cf\u63a5\u5165 Consul + Nacos\uff0c\u9a8c\u8bc1\u65e0\u611f\u6269\u5bb9\"}]},{\"@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":"\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011 \u7b2c\u56db\u5468\u00b7\u5468\u4e94\uff1a\u5c06\u6587\u7ae0\u7cfb\u7edf\u548c\u7528\u6237\u670d\u52a1\u5168\u91cf\u63a5\u5165 Consul + Nacos\uff0c\u9a8c\u8bc1\u65e0\u611f\u6269\u5bb9 - \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\/102466.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011 \u7b2c\u56db\u5468\u00b7\u5468\u4e94\uff1a\u5c06\u6587\u7ae0\u7cfb\u7edf\u548c\u7528\u6237\u670d\u52a1\u5168\u91cf\u63a5\u5165 Consul + Nacos\uff0c\u9a8c\u8bc1\u65e0\u611f\u6269\u5bb9 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4eca\u5929\u662f\u7b2c\u4e8c\u9636\u6bb5\u201c\u5fae\u670d\u52a1\u901a\u4fe1\u4e0e\u6cbb\u7406\u201d\u7684\u6536\u5b98\u4e4b\u6218\u3002\u4eca\u5929\u6211\u4eec\u5c06\u5b8c\u6210\u4e00\u4e2a\u5173\u952e\u5b9e\u6218&#xff1a;\u5c06\u6587\u7ae0\u7cfb\u7edf\u548c\u7528\u6237\u670d\u52a1\u5168\u91cf\u63a5\u5165 Consul Nacos&#xff0c;\u9a8c\u8bc1\u65e0\u611f\u6269\u5bb9\u3002\u524d\u9762\u56db\u5929\u6211\u4eec\u5206\u522b\u5b8c\u6210\u4e86\u670d\u52a1\u6ce8\u518c\u3001\u670d\u52a1\u53d1\u73b0\u3001\u914d\u7f6e\u4e2d\u5fc3\u96c6\u6210\u548c\u591a\u73af\u5883\u914d\u7f6e\u7ba1\u7406&#xff0c;\u4eca\u5929\u8981\u628a\u8fd9\u4e9b\u80fd\u529b\u4e32\u8054\u8d77\u6765&#xff0c;\u6a21\u62df\u751f\u4ea7\u73af\u5883\u4e2d\u670d\u52a1\u5b9e\u4f8b\u52a8\u6001\u4f38\u7f29\u7684\u573a\u666f&#xff0c;\u8ba9\u6d88\u8d39\u8005\u5728\u4e0d\u91cd\u542f\u7684\u60c5\u51b5\u4e0b\u81ea\u52a8\u611f\u77e5\u53d8\u5316&#xff0c;\u5b9e\u73b0\u771f\u6b63\u7684\u5f39\u6027\u4f38\u7f29\u3002\u4eca\u65e5\u76ee\u6807 \u786e\u4fdd\u6587\u7ae0\u670d\u52a1&#xff08;HTTP&amp;#xff","og_url":"https:\/\/www.wsisp.com\/helps\/102466.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-08T12:49:25+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260908124919-6aa0044f04cbd.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/102466.html","url":"https:\/\/www.wsisp.com\/helps\/102466.html","name":"\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011 \u7b2c\u56db\u5468\u00b7\u5468\u4e94\uff1a\u5c06\u6587\u7ae0\u7cfb\u7edf\u548c\u7528\u6237\u670d\u52a1\u5168\u91cf\u63a5\u5165 Consul + Nacos\uff0c\u9a8c\u8bc1\u65e0\u611f\u6269\u5bb9 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-08T12:49:25+00:00","dateModified":"2026-09-08T12:49:25+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/102466.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/102466.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/102466.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011 \u7b2c\u56db\u5468\u00b7\u5468\u4e94\uff1a\u5c06\u6587\u7ae0\u7cfb\u7edf\u548c\u7528\u6237\u670d\u52a1\u5168\u91cf\u63a5\u5165 Consul + Nacos\uff0c\u9a8c\u8bc1\u65e0\u611f\u6269\u5bb9"}]},{"@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\/102466","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=102466"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/102466\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/102465"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=102466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=102466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=102466"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=102466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}