{"id":10006147,"date":"2022-08-09T13:08:53","date_gmt":"2022-08-09T05:08:53","guid":{"rendered":"https:\/\/ityet.com\/?p=10006147"},"modified":"2022-08-09T13:08:53","modified_gmt":"2022-08-09T05:08:53","slug":"%e5%8d%87%e7%ba%a7spring-cloud%e6%9c%80%e6%96%b0%e7%89%88%e5%90%8e%ef%bc%8c%e6%9c%89%e4%b8%aa%e9%87%8d%e8%a6%81%e7%9a%84%e7%bb%84%e4%bb%b6%e8%a2%ab%e5%bc%83%e7%94%a8%e4%ba%86%ef%bc%81","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006147","title":{"rendered":"\u5347\u7ea7Spring Cloud\u6700\u65b0\u7248\u540e\uff0c\u6709\u4e2a\u91cd\u8981\u7684\u7ec4\u4ef6\u88ab\u5f03\u7528\u4e86\uff01"},"content":{"rendered":"<blockquote><p>\u524d\u4e0d\u4e45\uff0c\u6211\u628a<a href=\"https:\/\/segmentfault.com\/a\/1190000042256434\">Mall\u5fae\u670d\u52a1\u7248\u672c\u5168\u9762\u5347\u7ea7\u4e86<\/a> \uff0c\u5728\u901a\u8fc7Gateway\u7f51\u5173\u8c03\u7528\u5176\u4ed6\u670d\u52a1\u7684\u65f6\u5019\uff0c\u51fa\u73b0\u4e86<code>Service Unavailable<\/code>\u7684\u95ee\u9898\u3002\u6392\u67e5\u539f\u56e0\u65f6\u53d1\u73b0\u4f5c\u4e3a\u8d1f\u8f7d\u5747\u8861\u7ec4\u4ef6\u7684Ribbon\u88ab\u5f03\u7528\u4e86\uff0c\u4f5c\u4e3aNetflix\u5f00\u6e90\u7684\u4e00\u4e2a\u7ec4\u4ef6\uff0cRibbon\u65e9\u5df2\u8fdb\u5165\u7ef4\u62a4\u72b6\u6001\u3002\u73b0\u5728\u63a8\u8350\u4f7f\u7528\u7684\u662fLoadbalancer\uff0c\u4eca\u5929\u6211\u4eec\u5c31\u6765\u804a\u804aLoadbalancer\u7684\u4f7f\u7528\uff01<\/p><\/blockquote>\n<p>SpringCloud\u5b9e\u6218\u7535\u5546\u9879\u76ee<code>mall-swarm<\/code>\uff088.8k+star\uff09\u5730\u5740\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=GpPPRYbTCvK6fQSGBwk2Ug%3D%3D.2s6eInAwMm4qOkXJN9oMjFa0YLiQ%2FZpX%2FUiRQAR6O8A5Niz4qZ39PurpD0RptW6P\" rel=\"nofollow\">https:\/\/github.com\/macrozheng\/mall-swarm<\/a><\/p>\n<h2>LoadBalancer\u7b80\u4ecb<\/h2>\n<p>LoadBalancer\u662fSpring Cloud\u5b98\u65b9\u63d0\u4f9b\u7684\u8d1f\u8f7d\u5747\u8861\u7ec4\u4ef6\uff0c\u53ef\u7528\u4e8e\u66ff\u4ee3Ribbon\u3002\u5176\u4f7f\u7528\u65b9\u5f0f\u4e0eRibbon\u57fa\u672c\u517c\u5bb9\uff0c\u53ef\u4ee5\u4eceRibbon\u8fdb\u884c\u5e73\u6ed1\u8fc7\u6e21\u3002<\/p>\n<h2>\u4f7f\u7528<\/h2>\n<blockquote><p>\u4e0b\u9762\u4ecb\u7ecd\u4e0bLoadBalancer\u7684\u57fa\u672c\u4f7f\u7528\uff0c\u6211\u4eec\u5c06\u4f7f\u7528Nacos\u4f5c\u4e3a\u6ce8\u518c\u4e2d\u5fc3\uff0c\u901a\u8fc7<code>nacos-loadbalancer-service<\/code>\u548c<code>nacos-user-service<\/code>\u4e24\u4e2a\u670d\u52a1\u95f4\u7684\u76f8\u4e92\u8c03\u7528\u6765\u8fdb\u884c\u6f14\u793a\u3002<\/p><\/blockquote>\n<h3>\u8d1f\u8f7d\u5747\u8861<\/h3>\n<blockquote><p>\u6211\u4eec\u5c06\u4f7f\u7528RestTemplate\u6765\u6f14\u793a\u4e0bLoadBalancer\u7684\u8d1f\u8f7d\u5747\u8861\u529f\u80fd\u3002<\/p><\/blockquote>\n<ul>\n<li>\u9996\u5148\u5728<code>nacos-loadbalancer-service<\/code>\u6a21\u5757\u7684<code>pom.xml<\/code>\u6587\u4ef6\u4e2d\u6dfb\u52a0LoadBalancer\u76f8\u5173\u4f9d\u8d56\uff1b<\/li>\n<\/ul>\n<pre><code class=\"xml\">&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-cloud-starter-loadbalancer&lt;\/artifactId&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n<ul>\n<li>\u7136\u540e\u521b\u5efaJava\u914d\u7f6e\u7c7b\uff0c\u7528\u4e8e\u914d\u7f6e<code>RestTemplate<\/code>\uff0c\u540c\u65f6\u4f7f\u7528<code>@LoadBalanced<\/code>\u6ce8\u89e3\u8d4b\u4e88\u5176\u8d1f\u8f7d\u5747\u8861\u80fd\u529b\uff1b<\/li>\n<\/ul>\n<pre><code class=\"java\">\/**\n * RestTemplate\u76f8\u5173\u914d\u7f6e\n * Created by macro on 2019\/8\/29.\n *\/\n@Configuration\npublic class RestTemplateConfig {\n\n    @Bean\n    @ConfigurationProperties(prefix = &quot;rest.template.config&quot;)\n    public HttpComponentsClientHttpRequestFactory customHttpRequestFactory() {\n        return new HttpComponentsClientHttpRequestFactory();\n    }\n\n    @Bean\n    @LoadBalanced\n    public RestTemplate restTemplate() {\n        return new RestTemplate(customHttpRequestFactory());\n    }\n}<\/code><\/pre>\n<ul>\n<li>\u5728<code>application.yml<\/code>\u4e2d\u53ef\u4ee5\u4f7f\u7528\u81ea\u5b9a\u4e49\u914d\u7f6e\u5bf9RestTemplate\u7684\u8c03\u7528\u8d85\u65f6\u8fdb\u884c\u914d\u7f6e\uff1b<\/li>\n<\/ul>\n<pre><code class=\"yaml\">rest:\n  template:\n    config: # RestTemplate\u8c03\u7528\u8d85\u65f6\u914d\u7f6e\n      connectTimeout: 5000\n      readTimeout: 5000<\/code><\/pre>\n<ul>\n<li>\u7136\u540e\u5728Controller\u4e2d\u4f7f\u7528RestTemplate\u8fdb\u884c\u8fdc\u7a0b\u8c03\u7528\uff1b<\/li>\n<\/ul>\n<pre><code class=\"java\">\/**\n * Created by macro on 2019\/8\/29.\n *\/\n@RestController\n@RequestMapping(&quot;\/user&quot;)\npublic class UserLoadBalancerController {\n    @Autowired\n    private RestTemplate restTemplate;\n    @Value(&quot;${service-url.nacos-user-service}&quot;)\n    private String userServiceUrl;\n\n    @GetMapping(&quot;\/{id}&quot;)\n    public CommonResult getUser(@PathVariable Long id) {\n        return restTemplate.getForObject(userServiceUrl + &quot;\/user\/{1}&quot;, CommonResult.class, id);\n    }\n\n    @GetMapping(&quot;\/getByUsername&quot;)\n    public CommonResult getByUsername(@RequestParam String username) {\n        return restTemplate.getForObject(userServiceUrl + &quot;\/user\/getByUsername?username={1}&quot;, CommonResult.class, username);\n    }\n\n    @GetMapping(&quot;\/getEntityByUsername&quot;)\n    public CommonResult getEntityByUsername(@RequestParam String username) {\n        ResponseEntity&lt;CommonResult&gt; entity = restTemplate.getForEntity(userServiceUrl + &quot;\/user\/getByUsername?username={1}&quot;, CommonResult.class, username);\n        if (entity.getStatusCode().is2xxSuccessful()) {\n            return entity.getBody();\n        } else {\n            return new CommonResult(&quot;\u64cd\u4f5c\u5931\u8d25&quot;, 500);\n        }\n    }\n\n    @PostMapping(&quot;\/create&quot;)\n    public CommonResult create(@RequestBody User user) {\n        return restTemplate.postForObject(userServiceUrl + &quot;\/user\/create&quot;, user, CommonResult.class);\n    }\n\n    @PostMapping(&quot;\/update&quot;)\n    public CommonResult update(@RequestBody User user) {\n        return restTemplate.postForObject(userServiceUrl + &quot;\/user\/update&quot;, user, CommonResult.class);\n    }\n\n    @PostMapping(&quot;\/delete\/{id}&quot;)\n    public CommonResult delete(@PathVariable Long id) {\n        return restTemplate.postForObject(userServiceUrl + &quot;\/user\/delete\/{1}&quot;, null, CommonResult.class, id);\n    }\n}<\/code><\/pre>\n<ul>\n<li>\u5728<code>nacos-user-service<\/code>\u4e2d\u6211\u4eec\u5df2\u7ecf\u5b9e\u73b0\u4e86\u8fd9\u4e9b\u63a5\u53e3\uff0c\u53ef\u4ee5\u63d0\u4f9b\u7ed9<code>nacos-loadbalancer-service<\/code>\u670d\u52a1\u8fdb\u884c\u8fdc\u7a0b\u8c03\u7528\uff1b<\/li>\n<\/ul>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042289026\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<ul>\n<li>\u7136\u540e\u542f\u52a8\u4e00\u4e2a<code>nacos-loadbalancer-service<\/code>\uff0c\u548c\u4e24\u4e2a<code>nacos-user-service<\/code>\uff0c\u6b64\u65f6Nacos\u4e2d\u4f1a\u663e\u793a\u5982\u4e0b\u670d\u52a1\uff1b<\/li>\n<\/ul>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042289027\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<ul>\n<li>\u6b64\u65f6\u901a\u8fc7<code>nacos-loadbalancer-service<\/code>\u8c03\u7528\u63a5\u53e3\u8fdb\u884c\u6d4b\u8bd5\uff0c\u4f1a\u53d1\u73b0\u4e24\u4e2a<code>nacos-user-service<\/code>\u4ea4\u66ff\u6253\u5370\u65e5\u5fd7\u4fe1\u606f\uff0c\u4f7f\u7528\u7684\u662f\u8f6e\u8be2\u7b56\u7565\uff0c\u8bbf\u95ee\u5730\u5740\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=p9L9w4CbLCAJ59eVOst4mQ%3D%3D.2qoSYSmW0t6ocbCJNJEB372V2mlmH0vFCwmvatFem88%3D\" rel=\"nofollow\">http:\/\/localhost:8308\/user\/1<\/a><\/li>\n<\/ul>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042289028\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u58f0\u660e\u5f0f\u670d\u52a1\u8c03\u7528<\/h3>\n<blockquote><p>\u5f53\u7136LoadBalancer\u9664\u4e86\u4f7f\u7528RestTemplate\u6765\u8fdb\u884c\u8fdc\u7a0b\u8c03\u7528\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528OpenFeign\u6765\u8fdb\u884c\u58f0\u660e\u5f0f\u670d\u52a1\u8c03\u7528\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u6765\u4ecb\u7ecd\u4e0b\u3002<\/p><\/blockquote>\n<ul>\n<li>\u9996\u5148<code>nacos-loadbalancer-service<\/code>\u6a21\u5757\u7684<code>pom.xml<\/code>\u6587\u4ef6\u4e2d\u6dfb\u52a0OpenFeign\u7684\u76f8\u5173\u4f9d\u8d56\uff1b<\/li>\n<\/ul>\n<pre><code class=\"xml\">&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.cloud&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-cloud-starter-openfeign&lt;\/artifactId&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n<ul>\n<li>\u7136\u540e\u5728OpenFeign\u7684\u5ba2\u6237\u7aef\u63a5\u53e3\u4e2d\u58f0\u660e\u597d\u9700\u8981\u8c03\u7528\u7684\u670d\u52a1\u63a5\u53e3\u4ee5\u53ca\u8c03\u7528\u65b9\u5f0f\uff1b<\/li>\n<\/ul>\n<pre><code class=\"java\">\/**\n * Created by macro on 2019\/9\/5.\n *\/\n@FeignClient(value = &quot;nacos-user-service&quot;)\npublic interface UserService {\n    @PostMapping(&quot;\/user\/create&quot;)\n    CommonResult create(@RequestBody User user);\n\n    @GetMapping(&quot;\/user\/{id}&quot;)\n    CommonResult&lt;User&gt; getUser(@PathVariable Long id);\n\n    @GetMapping(&quot;\/user\/getByUsername&quot;)\n    CommonResult&lt;User&gt; getByUsername(@RequestParam String username);\n\n    @PostMapping(&quot;\/user\/update&quot;)\n    CommonResult update(@RequestBody User user);\n\n    @PostMapping(&quot;\/user\/delete\/{id}&quot;)\n    CommonResult delete(@PathVariable Long id);\n}<\/code><\/pre>\n<ul>\n<li>\u518d\u5728Controller\u4e2d\u4f7f\u7528OpenFeign\u7684\u5ba2\u6237\u7aef\u63a5\u53e3\u6765\u8c03\u7528\u8fdc\u7a0b\u670d\u52a1\uff1b<\/li>\n<\/ul>\n<pre><code class=\"java\">\/**\n * Created by macro on 2019\/8\/29.\n *\/\n@RestController\n@RequestMapping(&quot;\/userFeign&quot;)\npublic class UserFeignController {\n    @Autowired\n    private UserService userService;\n\n    @GetMapping(&quot;\/{id}&quot;)\n    public CommonResult getUser(@PathVariable Long id) {\n        return userService.getUser(id);\n    }\n\n    @GetMapping(&quot;\/getByUsername&quot;)\n    public CommonResult getByUsername(@RequestParam String username) {\n        return userService.getByUsername(username);\n    }\n\n    @PostMapping(&quot;\/create&quot;)\n    public CommonResult create(@RequestBody User user) {\n        return userService.create(user);\n    }\n\n    @PostMapping(&quot;\/update&quot;)\n    public CommonResult update(@RequestBody User user) {\n        return userService.update(user);\n    }\n\n    @PostMapping(&quot;\/delete\/{id}&quot;)\n    public CommonResult delete(@PathVariable Long id) {\n        return userService.delete(id);\n    }\n}<\/code><\/pre>\n<ul>\n<li>\u5982\u679c\u4f60\u60f3\u8bbe\u7f6e\u4e0bOpenFeign\u7684\u8d85\u65f6\u914d\u7f6e\u7684\u8bdd\uff0c\u53ef\u4ee5\u5728<code>application.yml<\/code>\u4e2d\u6dfb\u52a0\u5982\u4e0b\u5185\u5bb9\uff1b<\/li>\n<\/ul>\n<pre><code class=\"yaml\">feign:\n  client:\n    config:\n      default: # Feign\u8c03\u7528\u8d85\u65f6\u914d\u7f6e\n        connectTimeout: 5000\n        readTimeout: 5000<\/code><\/pre>\n<ul>\n<li>\u63a5\u4e0b\u6765\u901a\u8fc7\u6d4b\u8bd5\u63a5\u53e3\u8c03\u7528\u8fdc\u7a0b\u670d\u52a1\uff0c\u53d1\u73b0\u53ef\u4ee5\u6b63\u5e38\u8c03\u7528\uff0c\u8bbf\u95ee\u5730\u5740\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=SyNawzwArVEJVVGt9cHSOg%3D%3D.y4%2Fc1SWzDbVN9pUzx%2BKpCE6UIOenHgo%2BzTM8jrUPHS2wzNKHDXH11Ev8xAX1rQJr\" rel=\"nofollow\">http:\/\/localhost:8308\/userFei&#8230;<\/a><\/li>\n<\/ul>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042289029\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u670d\u52a1\u5b9e\u4f8b\u7f13\u5b58<\/h3>\n<blockquote><p>LoadBalancer\u4e3a\u4e86\u63d0\u9ad8\u6027\u80fd\uff0c\u4e0d\u4f1a\u5728\u6bcf\u6b21\u8bf7\u6c42\u65f6\u53bb\u83b7\u53d6\u5b9e\u4f8b\u5217\u8868\uff0c\u800c\u662f\u5c06\u670d\u52a1\u5b9e\u4f8b\u5217\u8868\u8fdb\u884c\u4e86\u672c\u5730\u7f13\u5b58\u3002<\/p><\/blockquote>\n<p>\u9ed8\u8ba4\u7684\u7f13\u5b58\u65f6\u95f4\u4e3a<code>35s<\/code>\uff0c\u4e3a\u4e86\u51cf\u5c11\u670d\u52a1\u4e0d\u53ef\u7528\u8fd8\u4f1a\u88ab\u9009\u62e9\u7684\u53ef\u80fd\u6027\uff0c\u6211\u4eec\u53ef\u4ee5\u8fdb\u884c\u5982\u4e0b\u914d\u7f6e\u3002<\/p>\n<pre><code class=\"yaml\">spring:\n  cloud:\n    loadbalancer:\n      cache: # \u8d1f\u8f7d\u5747\u8861\u7f13\u5b58\u914d\u7f6e\n        enabled: true # \u5f00\u542f\u7f13\u5b58\n        ttl: 5s # \u8bbe\u7f6e\u7f13\u5b58\u65f6\u95f4\n        capacity: 256 # \u8bbe\u7f6e\u7f13\u5b58\u5927\u5c0f<\/code><\/pre>\n<h3>HTTP\u8bf7\u6c42\u8f6c\u6362<\/h3>\n<blockquote><p>\u5982\u679c\u4f60\u60f3\u5728\u6bcf\u6b21\u8fdc\u7a0b\u8c03\u7528\u4e2d\u4f20\u5165\u81ea\u5b9a\u4e49\u7684\u8bf7\u6c42\u5934\u7684\u8bdd\uff0c\u53ef\u4ee5\u8bd5\u8bd5<code>LoadBalancerRequestTransformer<\/code>\uff0c\u901a\u8fc7\u5b83\u53ef\u4ee5\u5bf9\u539f\u59cb\u8bf7\u6c42\u8fdb\u884c\u4e00\u5b9a\u7684\u8f6c\u6362\u3002<\/p><\/blockquote>\n<ul>\n<li>\u9996\u5148\u6211\u4eec\u9700\u8981\u914d\u7f6e\u597d<code>LoadBalancerRequestTransformer<\/code>\u7684Bean\u5b9e\u4f8b\uff0c\u8fd9\u91cc\u6211\u4eec\u5c06<code>ServiceInstance<\/code>\u7684<code>instanceId<\/code>\u653e\u5165\u5230\u8bf7\u6c42\u5934<code>X-InstanceId<\/code>\u4e2d\uff1b<\/li>\n<\/ul>\n<pre><code class=\"java\">\/**\n * LoadBalancer\u76f8\u5173\u914d\u7f6e\n * Created by macro on 2022\/7\/26.\n *\/\n@Configuration\npublic class LoadBalancerConfig {\n    @Bean\n    public LoadBalancerRequestTransformer transformer() {\n        return new LoadBalancerRequestTransformer() {\n            @Override\n            public HttpRequest transformRequest(HttpRequest request, ServiceInstance instance) {\n                return new HttpRequestWrapper(request) {\n                    @Override\n                    public HttpHeaders getHeaders() {\n                        HttpHeaders headers = new HttpHeaders();\n                        headers.putAll(super.getHeaders());\n                        headers.add(&quot;X-InstanceId&quot;, instance.getInstanceId());\n                        return headers;\n                    }\n                };\n            }\n        };\n    }\n}<\/code><\/pre>\n<ul>\n<li>\u7136\u540e\u4fee\u6539<code>nacos-user-service<\/code>\u4e2d\u7684\u4ee3\u7801\uff0c\u6253\u5370\u83b7\u53d6\u5230\u7684\u8bf7\u6c42\u5934<code>X-InstanceId<\/code>\u7684\u4fe1\u606f\uff1b<\/li>\n<\/ul>\n<pre><code class=\"java\">\/**\n * Created by macro on 2019\/8\/29.\n *\/\n@RestController\n@RequestMapping(&quot;\/user&quot;)\npublic class UserController {\n    @GetMapping(&quot;\/{id}&quot;)\n    public CommonResult&lt;User&gt; getUser(@PathVariable Long id) {\n        User user = userService.getUser(id);\n        LOGGER.info(&quot;\u6839\u636eid\u83b7\u53d6\u7528\u6237\u4fe1\u606f\uff0c\u7528\u6237\u540d\u79f0\u4e3a\uff1a{}&quot;, user.getUsername());\n        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();\n        HttpServletRequest request = servletRequestAttributes.getRequest();\n        String instanceId = request.getHeader(&quot;X-InstanceId&quot;);\n        if (StrUtil.isNotEmpty(instanceId)) {\n            LOGGER.info(&quot;\u83b7\u53d6\u5230\u81ea\u5b9a\u4e49\u8bf7\u6c42\u5934:X-InstanceId={}&quot;, instanceId);\n        }\n        return new CommonResult&lt;&gt;(user);\n    }\n}<\/code><\/pre>\n<ul>\n<li>\u63a5\u4e0b\u6765\u8bbf\u95ee\u63a5\u53e3\u8fdb\u884c\u6d4b\u8bd5\uff0c<code>nacos-user-service<\/code>\u63a7\u5236\u53f0\u5c06\u6253\u5370\u5982\u4e0b\u65e5\u5fd7\uff0c\u53d1\u73b0\u81ea\u5b9a\u4e49\u8bf7\u6c42\u5934\u5df2\u7ecf\u6210\u529f\u4f20\u9012\u4e86\uff0c\u8bbf\u95ee\u5730\u5740\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=lUeiFvnVLIgt9O8n%2FPZiuA%3D%3D.S99p26twW0pT74OA7GsBCRm%2F5KSwGQf0BdhaOLa3s9Q%3D\" rel=\"nofollow\">http:\/\/localhost:8308\/user\/1<\/a><\/li>\n<\/ul>\n<pre><code>2022-07-26 15:05:19.920  INFO 14344 --- [nio-8206-exec-5] c.macro.cloud.controller.UserController  : \u6839\u636eid\u83b7\u53d6\u7528\u6237\u4fe1\u606f\uff0c\u7528\u6237\u540d\u79f0\u4e3a\uff1amacro\n2022-07-26 15:05:19.921  INFO 14344 --- [nio-8206-exec-5] c.macro.cloud.controller.UserController  : \u83b7\u53d6\u5230\u81ea\u5b9a\u4e49\u8bf7\u6c42\u5934:X-InstanceId=192.168.3.227#8206#DEFAULT#DEFAULT_GROUP@@nacos-user-service<\/code><\/pre>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u4eca\u5929\u901a\u8fc7\u5bf9LoadBalancer\u7684\u4e00\u6ce2\u5b9e\u8df5\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff0c\u4f7f\u7528LoadBalancer\u548cRibbon\u7684\u533a\u522b\u5176\u5b9e\u5e76\u4e0d\u5927\uff0c\u4e3b\u8981\u662f\u4e00\u4e9b\u914d\u7f6e\u65b9\u5f0f\u7684\u76f8\u540c\u3002\u5982\u679c\u4f60\u4e4b\u524d\u4f7f\u7528\u8fc7Ribbon\u7684\u8bdd\uff0c\u57fa\u672c\u4e0a\u53ef\u4ee5\u65e0\u7f1d\u5207\u6362\u5230LoadBalancer\u3002<\/p>\n<h2>\u53c2\u8003\u8d44\u6599<\/h2>\n<blockquote><p>\u5b98\u65b9\u6587\u6863\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=kYsz5kZLeS0x8UIWZ98Sbw%3D%3D.VQF7HixUluuKIfIZ7IJUTLWrPFAv17PAWLyU82y0gUl0VmtVmsqts1%2FaArqwInmX4vB6Qp4m3ua9RKFRJxpPExjPk8ys8PhknrCJxT803YAAaaYSsLUf6QbiSVwPQshKERmd3Z510OI6fEE6gmA3Qg%3D%3D\" rel=\"nofollow\">https:\/\/docs.spring.io\/spring&#8230;<\/a><\/p><\/blockquote>\n<h2>\u9879\u76ee\u6e90\u7801\u5730\u5740<\/h2>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=QBhUg7D6FnFT%2BiPno%2BdX7A%3D%3D.RxWapzTpNKLmfb1NE1VpKru27x7aOpHC98hBQ4tyXC8Iw4XLlM2xYeULww%2FzO1tsHoov8JZHjuxncxArhoFHYjSOj9CfNtwwOyohSL8kKdAtPj8NHiH45C5ta%2BtVxX4z\" rel=\"nofollow\">https:\/\/github.com\/macrozheng&#8230;<\/a><\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042289023\">https:\/\/segmentfault.com\/a\/1190000042289023<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u4e0d\u4e45\uff0c\u6211\u628aMall\u5fae\u670d\u52a1\u7248\u672c\u5168\u9762\u5347\u7ea7\u4e86 \uff0c\u5728\u901a\u8fc7Gateway\u7f51\u5173\u8c03\u7528\u5176\u4ed6\u670d\u52a1\u7684\u65f6\u5019\uff0c\u51fa\u73b0\u4e86Service  [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-10006147","post","type-post","status-publish","format-standard","hentry"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10006147"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006147\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}