{"id":644,"date":"2023-03-23T21:42:05","date_gmt":"2023-03-23T13:42:05","guid":{"rendered":""},"modified":"2023-03-23T21:42:05","modified_gmt":"2023-03-23T13:42:05","slug":"SpringCloud Zuul API\u7f51\u5173","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/644.html","title":{"rendered":"SpringCloud Zuul API\u7f51\u5173"},"content":{"rendered":"


\n <\/head>
\n <\/p>\n

\n

SpringCloud Zuul API\u7f51\u5173<\/h1>\n<\/p><\/div>\n

\u4ec0\u4e48\u662fZuul\uff1f<\/h2>\n
\n Zuul Server\u662fAPI\u7f51\u5173\u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u5904\u7406\u6240\u6709\u8bf7\u6c42\u5e76\u6267\u884c\u5fae\u670d\u52a1\u5e94\u7528\u7a0b\u5e8f\u7684\u52a8\u6001\u8def\u7531\u3002\u5b83\u5145\u5f53\u6240\u6709\u8bf7\u6c42\u7684\u524d\u95e8\u3002\u5b83\u4e5f\u79f0\u4e3a
\n \u8fb9\u7f18\u670d\u52a1\u5668\u3002<\/strong>\n <\/div>\n
\n Zuul\u65e8\u5728\u5b9e\u73b0
\n \u52a8\u6001\u8def\u7531\uff0c\u76d1\u89c6\uff0c\u5f39\u6027\uff0c<\/strong>\u548c
\n \u5b89\u5168\u6027\u3002<\/strong>\u5b83\u8fd8\u53ef\u4ee5\u5c06\u8bf7\u6c42\u8def\u7531\u5230\u591a\u4e2a
\n Amazon Auto Scaling\u7ec4<\/strong>\u3002\n <\/div>\n
\n \u4f8b\u5982\uff0c
\n \/api\/products <\/strong>\u6620\u5c04\u5230
\n \u4ea7\u54c1<\/strong>\u670d\u52a1\u548c
\n \/api\/user <\/strong>\u6620\u5c04\u5230
\n user <\/strong>\u670d\u52a1\u3002 Zuul\u670d\u52a1\u5668\u5c06\u8bf7\u6c42\u52a8\u6001\u8def\u7531\u5230\u76f8\u5e94\u7684\u540e\u7aef\u5e94\u7528\u7a0b\u5e8f\u3002\n <\/div>\n

\u4e3a\u4ec0\u4e48\u4f7f\u7528Zuul\uff1f<\/h2>\n
\n Netflix API\u6d41\u91cf\u7684\u6570\u91cf\u548c\u79cd\u7c7b\u6709\u65f6\u4f1a\u5bfc\u81f4\u751f\u4ea7\u95ee\u9898\u5f88\u5feb\u5c31\u51fa\u73b0\u4e86\uff0c\u6ca1\u6709\u8b66\u544a\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u80fd\u591f\u5feb\u901f\u6539\u53d8\u884c\u4e3a\u4ee5\u5bf9\u8fd9\u4e9b\u60c5\u51b5\u505a\u51fa\u53cd\u5e94\u7684\u7cfb\u7edf\u3002\n <\/div>\n
\n Zuul\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u4e0d\u540c\u7c7b\u578b\u7684
\n \u8fc7\u6ee4\u5668<\/strong>\uff0c\u4f7f\u6211\u4eec\u80fd\u591f\u5feb\u901f\u7075\u6d3b\u5730\u8fdb\u884c\u64cd\u4f5c\u3002\u5c06\u529f\u80fd\u5e94\u7528\u4e8e\u6211\u4eec\u7684\u8fb9\u7f18\u670d\u52a1\u3002\u8fc7\u6ee4\u5668\u6267\u884c\u4ee5\u4e0b\u529f\u80fd:\n <\/div>\n

\u8eab\u4efd\u9a8c\u8bc1\u548c\u5b89\u5168\u6027: <\/strong>\u5b83\u63d0\u4f9b\u4e86\u6bcf\u79cd\u8d44\u6e90\u7684\u8eab\u4efd\u9a8c\u8bc1\u8981\u6c42\u3002<\/span>
\n \u6d1e\u5bdf\u548c\u76d1\u89c6: <\/strong>\u5b83\u8ddf\u8e2a\u6709\u610f\u4e49\u7684\u6570\u636e\u548c\u7edf\u8ba1\u4fe1\u606f\uff0c\u4f7f\u6211\u4eec\u53ef\u4ee5\u51c6\u786e\u5730\u4e86\u89e3\u751f\u4ea7\u60c5\u51b5\u3002<\/span>
\n \u52a8\u6001\u8def\u7531: <\/strong>\u5b83\u6839\u636e\u9700\u8981\u5c06\u8bf7\u6c42\u52a8\u6001\u8def\u7531\u5230\u5176\u4ed6\u652f\u6301\u7684\u7fa4\u96c6\u3002<\/span>
\n \u538b\u529b\u6d4b\u8bd5: <\/strong>\u5b83\u589e\u52a0\u4e86\u5230\u7fa4\u96c6\u7684\u6d41\u91cf\u4ee5\u6d4b\u8bd5\u6027\u80fd\u3002<\/span>
\n \u8d1f\u8f7d: <\/strong>\u5b83\u4e3a\u6bcf\u79cd\u7c7b\u578b\u7684\u8bf7\u6c42\u5206\u914d\u5bb9\u91cf\uff0c\u5e76\u4e22\u5f03\u8d85\u51fa\u9650\u5236\u7684\u8bf7\u6c42\u3002<\/span>
\n \u9759\u6001\u54cd\u5e94\u5904\u7406: <\/strong>\u5b83\u76f4\u63a5\u5728\u8fb9\u7f18\u6784\u5efa\u4e00\u4e9b\u54cd\u5e94\uff0c\u800c\u4e0d\u662f\u5c06\u5176\u8f6c\u53d1\u5230\u5185\u90e8\u96c6\u7fa4\u3002<\/span>
\n \u591a\u533a\u57df\u5f39\u6027: <\/strong> \u5b83\u8de8AWS\u533a\u57df\u8def\u7531\u8bf7\u6c42\uff0c\u4ee5\u591a\u6837\u5316\u6211\u4eec\u7684ELB\u7528\u6cd5\u3002<\/span> <\/p>\n

Zuul\u7ec4\u4ef6<\/h2>\n
\n Zuul 2.x\u7ec4\u4ef6: <\/strong>\n <\/div>\n

zuul-core: <\/strong> \u5b83\u662f\u4e00\u4e2a\u5305\u542bZuul 2.0\u6838\u5fc3\u529f\u80fd\u7684\u5e93\u3002<\/span>
\n zuul-sample: <\/strong>\u662fZuul 2.0\u7684\u793a\u4f8b\u9a71\u52a8\u7a0b\u5e8f\u5e94\u7528\u7a0b\u5e8f<\/span> <\/p>\n

\n Zuul 1.x\u7ec4\u4ef6: <\/strong>\n <\/div>\n

zuul-core: <\/strong>\u3002\u5b83\u5b9a\u4e49\u4e86\u6838\u5fc3\u529f\u80fd\u3002<\/span>
\n zuul-simple-webapp: <\/strong>\u4e00\u4e2aWeb\u5e94\u7528\u7a0b\u5e8f\uff0c\u5176\u4e2d\u663e\u793a\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u8bf4\u660e\u5982\u4f55\u4f7f\u7528zuul-core\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u3002<\/span>
\n zuul-netflix: <\/strong>\u662f\u4e00\u4e2a\u5c06\u5176\u4ed6NetflixOSS\u7ec4\u4ef6\u6dfb\u52a0\u5230Zuul\u7684\u5e93\u3002<\/span>
\n zuul-netflix-webapp: <\/strong>\u8fd9\u662f\u4e00\u4e2a\u5c06zuul-core\u548czuul-netflix\u6253\u5305\u5728\u4e00\u8d77\u7684webapp\u3002<\/span> <\/p>\n

\u8bbe\u7f6eZuul API\u7f51\u5173\u670d\u52a1\u5668<\/h2>\n
\n \u6709
\n \u4e09\u4e2a<\/strong>\u6b65\u9aa4\u6765\u8bbe\u7f6eZuul API\u7f51\u5173:\n <\/div>\n

\u4e3aZuul API\u7f51\u5173\u521b\u5efa\u4e00\u4e2a\u7ec4\u4ef6<\/span>
\n \u786e\u5b9aZuul API\u7f51\u5173\u5e94\u505a\u7684\u4e8b\u60c5<\/span>
\n \u6240\u6709\u91cd\u8981\u8bf7\u6c42\u5747\u914d\u7f6e\u4e3a\u901a\u8fc7Zuul API\u7f51\u5173<\/span> <\/p>\n

\n \u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8bbe\u7f6eZuul API\u7f51\u5173\u670d\u52a1\u5668\u3002\n <\/div>\n
\n \u6b65\u9aa41: <\/strong>\u6253\u5f00
\n Spring Initializr <\/strong> https:\/\/start.spring.io \u3002\n <\/div>\n
\n \u6b65\u9aa42: <\/strong>
\n Group<\/strong>\u540d\u79f0\u3002\u6211\u4eec\u5df2\u7ecf\u63d0\u4f9b\u4e86
\n com.lidihuo.microservices\u3002<\/strong>\n <\/div>\n
\n \u6b65\u9aa43: <\/strong>\u63d0\u4f9b
\n Artifact id<\/strong>\uff0c\u6211\u4eec\u63d0\u4f9b\u4e86
\n netflix-zuul-api-gateway-server\u3002<\/strong>\n <\/div>\n
\n \u6b65\u9aa44: <\/strong>\u6dfb\u52a0\u4ee5\u4e0b\u4f9d\u8d56\u9879:
\n Zuul\uff0cEureka Discovery\uff0cActuator <\/strong>\u548c
\n DevTools\u3002<\/strong>\n <\/div>\n

SpringCloud Zuul API\u7f51\u5173_https:\/\/bianchenghao6.com_\u3010SpringCloud \u6559\u7a0b\u3011_\u7b2c1\u5f20 <\/p>\n

\n \u6b65\u9aa45: <\/strong>\u5355\u51fb
\n Generate <\/strong>(\u751f\u6210)\u6309\u94ae\u3002\u5b83\u5c06\u5f00\u59cb\u5c06\u9879\u76ee\u6253\u5305\u5230
\n zip <\/strong>\u6587\u4ef6\u4e2d\u5e76\u4e0b\u8f7d\u3002\n <\/div>\n

SpringCloud Zuul API\u7f51\u5173_https:\/\/bianchenghao6.com_\u3010SpringCloud \u6559\u7a0b\u3011_\u7b2c2\u5f20 <\/p>\n

\n \u6b65\u9aa46: \u63d0\u53d6<\/strong>\u538b\u7f29\u6587\u4ef6\u5e76\u5c06\u5176\u7c98\u8d34\u5230Spring Tool Suite\u7684\u5de5\u4f5c\u533a\u4e2d\u3002\n <\/div>\n
\n \u6b65\u9aa47: \u5bfc\u5165<\/strong>\u9879\u76ee\n <\/div>\n
\n \u6587\u4ef6->\u5bfc\u5165->\u73b0\u6709Maven\u9879\u76ee->\u6d4f\u89c8->\u9009\u62e9
\n netflix-zuul-api-gateway-server <\/strong>->\u9009\u62e9\u6587\u4ef6\u5939->\u5b8c\u6210\n <\/div>\n
\n \u5bfc\u5165\u9700\u8981\u4e00\u4e9b\u65f6\u95f4\u3002\n <\/div>\n
\n \u6b65\u9aa48: <\/strong>\u6253\u5f00
\n NetflixZuulApiGatewayServerApplication.java <\/strong>\u6587\u4ef6\u5e76\u542f\u7528zuul\u4ee3\u7406\u548c\u53d1\u73b0\u5206\u522b\u4f7f\u7528
\n @EnableZuulProxy <\/strong>\u548c
\n @EnableDiscoveryClient <\/strong>
\n \u3002<\/strong>\n <\/div>\n
\n NetflixZuulApiGatewayServerApplication.java <\/strong>\n <\/div>\n
\n
\r\npackage <\/span>com.lidihuo.microservices.netflixzuulapigatewayserver;\r\nimport org.springframework.boot.SpringApplication;\r\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\r\nimport org.springframework.cloud.client.discovery.EnableDiscoveryClient;\r\nimport org.springframework.cloud.netflix.zuul.EnableZuulProxy;\r\n@EnableZuulProxy\r\n@EnableDiscoveryClient\r\n@SpringBootApplication\r\npublic <\/span>class <\/span>NetflixZuulApiGatewayServerApplication \r\n{\r\npublic <\/span>static void <\/span>main(String[] args) \r\n{\r\nSpringApplication.run<\/span>(NetflixZuulApiGatewayServerApplication.class, args);\r\n}\r\n}\r\n<\/pre>\n

<\/code>\n <\/div>\n

\n \u6b65\u9aa49: <\/strong>\u6253\u5f00
\n application.properties <\/strong>\u6587\u4ef6\uff0c\u5e76\u914d\u7f6e
\n \u5e94\u7528\u7a0b\u5e8f\u540d\u79f0\uff0c\u7aef\u53e3\uff0c<\/strong>\u548c
\n eureka\u547d\u540d\u670d\u52a1\u5668<\/strong>\u3002\n <\/div>\n
\n application.properties <\/strong>\n <\/div>\n
\n
\r\nspring.application.name=netflix-zuul-api-gateway-server\r\nserver.port=8765\r\neureka.client.service-url.default-zone=http:\/\/localhost:8765\/eureka\r\n<\/pre>\n

<\/code>\n <\/div>\n


\n

<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"SpringCloud Zuul API\u7f51\u5173zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[106],"tags":[],"class_list":["post-644","post","type-post","status-publish","format-standard","hentry","category-bc_springcloud_jc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/644"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=644"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/644\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}