{"id":1809,"date":"2023-03-27T22:55:17","date_gmt":"2023-03-27T14:55:17","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1809"},"modified":"2023-04-22T09:24:11","modified_gmt":"2023-04-22T01:24:11","slug":"spring-cloud-alibaba-2-1-1-new-features-sidecar-module-introduction","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/27\/spring-cloud-alibaba-2-1-1-new-features-sidecar-module-introduction\/","title":{"rendered":"Spring Cloud Alibaba 2.1.1 \u65b0\u7279\u6027Sidecar\u6a21\u5757\u4ecb\u7ecd"},"content":{"rendered":"<h2>Sidecar\u7b80\u4ecb<\/h2>\n<p>Spring Cloud Alibaba v2.1.1.RELEASE\u4e2d\u589e\u52a0\u4e86\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u65b0\u7279\u6027\uff0c\u5bf9Spring Cloud Alibaba Sidecar\u6a21\u5757\u652f\u6301\u3002<\/p>\n<p>\u8be5\u6a21\u5757\u4f5c\u4e3a\u4e00\u4e2a\u4ee3\u7406\u7684\u670d\u52a1\u6765\u95f4\u63a5\u6027\u7684\u8ba9<strong>\u5176\u4ed6\u8bed\u8a00<\/strong>\u53ef\u4ee5\u4f7f\u7528<code>spring cloud alibaba<\/code>\u7b49\u76f8\u5173\u7ec4\u4ef6\u3002\u901a\u8fc7\u4e0e\u7f51\u5173\u6765\u8fdb\u884c\u8def\u7531\u7684\u6620\u5c04\uff0c\u4ece\u800c\u53ef\u4ee5\u505a\u5230\u670d\u52a1\u7684\u83b7\u53d6\uff0c\u7136\u540e\u53ef\u4ee5\u4f7f\u7528<code>Ribbon<\/code>\u95f4\u63a5\u6027\u8c03\u7528\u3002<\/p>\n<p><!-- more --><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/Java\/Sidecar\u539f\u7406.jpg\" alt=\"Sidecar\u539f\u7406\" \/><\/p>\n<p>\u5982\u4e0a\u56fe\uff0c<code>Spring Cloud<\/code>\u5e94\u7528\u8bf7\u6c42<code>sidercar<\/code>\u7136\u540e\u8f6c\u53d1\u7ed9\u5176\u4ed6\u8bed\u8a00\u7684\u6a21\u5757\uff0c\u4f18\u52bf\u662f\u5bf9\u4e8e\u5f02\u6784\u670d\u52a1\u4ee3\u7801\u96f6\u4fb5\u5165\uff0c\u4e0d\u9700\u8981\u76f4\u63a5\u6839\u636e<code>nacos<\/code>\u6216\u5176\u4ed6\u6ce8\u518c\u4e2d\u5fc3<code>api<\/code>\u6ce8\u518c\u7b49\u3002<\/p>\n<h2>\u4f7f\u7528\u5165\u95e8<\/h2>\n<p>\u793a\u4f8b\u4ee3\u7801\u8bf7\u53c2\u9605\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/alibaba\/spring-cloud-alibaba\/tree\/master\/spring-cloud-alibaba-examples\/spring-cloud-alibaba-sidecar-examples\" title=\"spring-cloud-alibaba-sidecar-examples\">spring-cloud-alibaba-sidecar-examples<\/a><\/p>\n<p><code>Spring Cloud<\/code>\u521b\u5efa\u4e00\u4e2aSpring\u5e94\u7528\u6ce8\u518c\u5728<code>Nacos<\/code>\u4e0a\uff0c\u5e94\u7528\u8bf7\u6c42<code>8070<\/code>\u7aef\u53e3\uff0c\u901a\u8fc7<code>sidecar<\/code>\u8f6c\u5230\u672c\u673a<code>8060<\/code>\u7aef\u53e3<code>Node.js<\/code>\u670d\u52a1\u3002<\/p>\n<h3>Node.js\u670d\u52a1<\/h3>\n<pre><code class=\"language-javascript\">var http = require(&#039;http&#039;);\nvar url = require(&quot;url&quot;);\nvar path = require(&#039;path&#039;);\n\n\/\/ \u521b\u5efaserver\nvar server = http.createServer(function(req, res) {\n    \/\/ \u83b7\u5f97\u8bf7\u6c42\u7684\u8def\u5f84\n    var pathname = url.parse(req.url).pathname;\n    res.writeHead(200, { &#039;Content-Type&#039; : &#039;application\/json; charset=utf-8&#039; });\n    \/\/ \u8bbf\u95eehttp:\/\/localhost:8060\/\uff0c\u5c06\u4f1a\u8fd4\u56de{&quot;index&quot;:&quot;\u6b22\u8fce\u6765\u5230\u9996\u9875&quot;}\n    if (pathname === &#039;\/&#039;) {\n        res.end(JSON.stringify({ &quot;index&quot; : &quot;\u6b22\u8fce\u6765\u5230\u9996\u9875&quot; }));\n    }\n    \/\/ \u8bbf\u95eehttp:\/\/localhost:8060\/health\uff0c\u5c06\u4f1a\u8fd4\u56de{&quot;status&quot;:&quot;UP&quot;}\n    else if (pathname === &#039;\/health.json&#039;) {\n        res.end(JSON.stringify({ &quot;status&quot; : &quot;UP&quot; }));\n    }\n    \/\/ \u5176\u4ed6\u60c5\u51b5\u8fd4\u56de404\n    else {\n        res.end(&quot;404&quot;);\n    }\n});\n\/\/ \u521b\u5efa\u76d1\u542c\uff0c\u5e76\u6253\u5370\u65e5\u5fd7\nserver.listen(8060, function() {\n    console.log(&#039;listening on localhost:8060&#039;);\n});<\/code><\/pre>\n<h3>\u5f02\u6784\u670d\u52a1<\/h3>\n<ul>\n<li>Maven\u4f9d\u8d56<\/li>\n<\/ul>\n<pre><code class=\"language-xml\">&lt;dependencies&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-boot-starter-actuator&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-cloud-starter-gateway&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;com.alibaba.cloud&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-cloud-starter-alibaba-sidecar&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;com.alibaba.cloud&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-cloud-starter-alibaba-nacos-discovery&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n&lt;\/dependencies&gt;<\/code><\/pre>\n<ul>\n<li>\u5f02\u6784\u914d\u7f6e<\/li>\n<\/ul>\n<pre><code class=\"language-yml\">server:\n  port: 8070\nspring:\n  cloud:\n    nacos:\n      username: nacos\n      password: nacos\n      discovery:\n        server-addr: 127.0.0.1:8848\n        group: test\n    gateway:\n      discovery:\n        locator:\n          enabled: true\n\n  application:\n    name: node-service\nsidecar:\n  # \u5f02\u6784\u5fae\u670d\u52a1\u7684IP\n  ip: 127.0.0.1\n  # \u5f02\u6784\u5fae\u670d\u52a1\u7684\u7aef\u53e3\n  port: 8060\n  # \u5f02\u6784\u5fae\u670d\u52a1\u7684\u5065\u5eb7\u68c0\u67e5URL\n  #health-check-url: http:\/\/localhost:8060\/health.json\nmanagement:\n  endpoint:\n    health:\n      show-details: always<\/code><\/pre>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u968f\u7740\u5fae\u670d\u52a1\u8d8a\u6765\u8d8a\u6d41\u884c\uff0c\u8de8\u8bed\u8a00\u4e4b\u95f4\u8c03\u7528\u8d8a\u6765\u8d8a\u591a\uff0c<code>Restful OPEN API<\/code>\u867d\u7136\u63d0\u4f9b\u4e86\u8de8\u8bed\u8a00\u8c03\u7528\u7684\u4e00\u79cd\u65b9\u5f0f\uff0c\u4f46\u662f\u6548\u7387\u4f4e\uff0c\u540c\u65f6\u9700\u8981\u5404\u8bed\u8a00\u6765\u5b9e\u73b0<code>OPEN API<\/code>\u89c4\u8303\uff0c\u5f00\u53d1\u7ef4\u62a4\u6210\u672c\u9ad8\u3002<code>sidecar<\/code>\u6a21\u5757\u5b9e\u73b0\u4e86\u96f6\u4e00\u79cd\u65e0\u4fb5\u5165\u8de8\u8bed\u8a00\u5728\u5fae\u670d\u52a1\u7ec4\u4ef6\u4e4b\u95f4\u8c03\u7528\u7684\u673a\u5236\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sidecar\u7b80\u4ecb Spring Cloud Alibaba v2.1.1.RELEASE\u4e2d\u589e\u52a0\u4e86\u4e00\u4e2a\u975e\u5e38\u91cd\u8981 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42],"tags":[457,456],"class_list":["post-1809","post","type-post","status-publish","format-standard","hentry","category-spring-cloud","tag-sidecar","tag-spring-cloud-alibaba"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1809"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1809\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}