{"id":646,"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 \u6267\u884c\u8bf7\u6c42","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/646.html","title":{"rendered":"SpringCloud \u6267\u884c\u8bf7\u6c42"},"content":{"rendered":"


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

\n

SpringCloud \u6267\u884c\u8bf7\u6c42<\/h1>\n<\/p><\/div>\n
\n \u6b65\u9aa41: <\/strong>\u8fd0\u884c
\n netflix-eureka-naming-server\u3002<\/strong>\n <\/div>\n
\n \u6b65\u9aa42: <\/strong>\u5728\u7aef\u53e3
\n 8000 <\/strong>\u4e0a\u8fd0\u884c
\n currency-exchange-service <\/strong>\u3002\n <\/div>\n
\n \u6b65\u9aa43: <\/strong>\u5728\u7aef\u53e3
\n 8100 <\/strong>\u4e0a\u8fd0\u884c
\n currency-conversion-service <\/strong>\u3002\n <\/div>\n
\n \u6b65\u9aa44: <\/strong>\u8fd0\u884c
\n netflix-zuul-api-gateway-server\u3002<\/strong>\n <\/div>\n
\n \u6b65\u9aa45: <\/strong>\u6253\u5f00\u6d4f\u89c8\u5668\u5e76\u8c03\u7528URL http:\/\/localhost:8761 \u3002\u5b83\u663e\u793a\u4e86\u5728Eureka\u547d\u540d\u670d\u52a1\u5668\u4e0a\u6ce8\u518c\u7684\u6240\u6709\u670d\u52a1\u3002\n <\/div>\n

SpringCloud \u6267\u884c\u8bf7\u6c42_https:\/\/bianchenghao6.com_\u3010SpringCloud \u6559\u7a0b\u3011_\u7b2c1\u5f20 <\/p>\n

\n \u6b65\u9aa46 <\/strong>: \u8c03\u7528URL http:\/\/localhost:8000\/currency-exchange\/from\/EUR\/to\/INR \u3002\u6211\u4eec\u5f97\u5230\u4e86\u54cd\u5e94\uff0c\u4f46\u662f\u8bf7\u6c42\u6ca1\u6709\u901a\u8fc7Zuul API\u7f51\u5173\u3002\n <\/div>\n

SpringCloud \u6267\u884c\u8bf7\u6c42_https:\/\/bianchenghao6.com_\u3010SpringCloud \u6559\u7a0b\u3011_\u7b2c2\u5f20 <\/p>\n

\n \u8ba9\u6211\u4eec\u901a\u8fc7Zuul API\u7f51\u5173\u8c03\u7528\u8bf7\u6c42\u3002\u6211\u4eec\u4f7f\u7528\u4ee5\u4e0bURL: http:\/\/localhost:8765\/{application-name}\/{uri} \u3002\u7aef\u53e3
\n 8765 <\/strong>\u662fZuul API\u7f51\u5173\u670d\u52a1\u5668\u7684\u9ed8\u8ba4\u7aef\u53e3\u3002\n <\/div>\n
\n \u5728\u6211\u4eec\u7684\u793a\u4f8b\u4e2d\uff0c
\n \u5e94\u7528\u7a0b\u5e8f\u540d\u79f0<\/strong>\u662f
\n currency-exchange-server<\/strong>\u548c
\n URI <\/strong>\u662f
\n \/currency-exchange\/from\/EUR\/to\/INR <\/strong>\u3002\u56e0\u6b64\uff0c\u5b8c\u6574\u7684URL\u5982\u4e0b\u6240\u793a:\n <\/div>\n
\n http:\/\/localhost:8765\/currency-exchange-service\/currency-exchange\/from\/EUR\/to\/INR\n <\/div>\n
\n \u6b65\u9aa47: <\/strong>\u590d\u5236\u4e0a\u9762\u7684URL\u5e76\u5c06\u5176\u7c98\u8d34\u5230\u6d4f\u89c8\u5668\u4e2d\u3002\u6211\u4eec\u5f97\u5230\u4e0e\u4e0a\u8ff0\u76f8\u540c\u7684\u54cd\u5e94\uff0c\u4f46\u6b64\u65f6\uff0c\u8bf7\u6c42\u6b63\u5728\u901a\u8fc7
\n Zuul API\u7f51\u5173<\/strong>\u3002\n <\/div>\n

SpringCloud \u6267\u884c\u8bf7\u6c42_https:\/\/bianchenghao6.com_\u3010SpringCloud \u6559\u7a0b\u3011_\u7b2c3\u5f20 <\/p>\n

\n \u6211\u4eec\u8fd8\u53ef\u4ee5\u770b\u5230\u5728Zuul API Gateway\u670d\u52a1\u5668\u4e0a\u6253\u5370\u7684\u8bf7\u6c42\u5185\u5bb9\u3002\u8be5\u8bf7\u6c42\u5c06\u6253\u5370\u8bf7\u6c42URI\u3002\n <\/div>\n

SpringCloud \u6267\u884c\u8bf7\u6c42_https:\/\/bianchenghao6.com_\u3010SpringCloud \u6559\u7a0b\u3011_\u7b2c4\u5f20 <\/p>\n

\n \u6211\u4eec\u5df2\u7ecf\u901a\u8fc7Zuul API\u7f51\u5173\u53d1\u9001\u4e86\u8bf7\u6c42\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u8c03\u7528\u5fae\u670d\u52a1\u3002\n <\/div>\n

\u5728\u5fae\u670d\u52a1\u8c03\u7528\u4e4b\u95f4\u8bbe\u7f6eZuul API\u7f51\u5173<\/h2>\n
\n \u5728\u4e0a\u4e00\u6b65\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u76f4\u63a5URL\u901a\u8fc7Zuul API Gateway\u4ee3\u7406\u6267\u884ccurrency-exchange-service\u3002\u5f53\u6211\u4eec\u4f7f\u7528URL http:\/\/localhost:8765\/currency-exchange-service\/currency-exchange\/from\/EUR\/to\/INR \uff0c\u5b83\u4f7f\u7528\u7aef\u53e38765\u4f5c\u4e3aAPI\u7f51\u5173\u7684\u4ee3\u7406\u3002\n <\/div>\n
\n \u5728\u6b64\u90e8\u5206\u4e2d\uff0c\u6211\u4eec\u5c06\u8d27\u5e01\u79f0\u4e3a-\u8c03\u7528\u8d27\u5e01\u5151\u6362\u670d\u52a1\u7684\u8ba1\u7b97\u670d\u52a1(currency-conversion-service)\u3002\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u6211\u4eec\u6b63\u5728\u76f4\u63a5\u81f4\u7535\u8be5\u670d\u52a1\u3002\u73b0\u5728\uff0c\u6211\u4eec\u5c06\u901a\u8fc7Zuul API\u7f51\u5173\u8c03\u7528\u5b83\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u8c03\u7528currency-exchange-service\u3002\n <\/div>\n
\n \u6b65\u9aa41: <\/strong>\u9009\u62e9\u9879\u76ee
\n currency-conversion-service <\/strong>\u3002\n <\/div>\n
\n \u6b65\u9aa42: <\/strong>\u6253\u5f00
\n CurrencyExchangeServiceProxy.java <\/strong>\u6587\u4ef6\u3002\n <\/div>\n
\n \u6b65\u9aa43: <\/strong>\u4f7f\u7528\u5e26\u6709\u5c5e\u6027
\n name=\"netflix-zuul-api-gateway-server\"<\/strong>\u7684\u6ce8\u91ca
\n @FeignClient <\/strong>\u542f\u7528
\n \u5047\u5192<\/strong>\u3002\n <\/div>\n
\n
\r\n@FeignClient(name=\"netflix-zuul-api-gateway-server\"<\/span>)\r\n<\/pre>\n

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

\n \u8bb0\u4f4f: <\/strong> \u5220\u9664\u6216\u6ce8\u91ca
\n CurrencyExchangeServiceProxy.java <\/strong>\u6587\u4ef6\u4e2d\u7684\u6240\u6709\u5176\u4ed6\u6ce8\u91ca@FeignClient\u3002\n <\/div>\n
\n \u6b65\u9aa44: <\/strong>\u4e3aZuul API\u7f51\u5173\u670d\u52a1\u5668\u5b9a\u4e49
\n \u6620\u5c04<\/strong>\u3002\n <\/div>\n
\n
\r\n@GetMapping(\"\/currency-exchange-service\/currency-exchange\/from\/{from}\/to\/{to}\"<\/span>)\r\n<\/pre>\n

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

\n \u6b65\u9aa45: <\/strong>\u8fd0\u884c
\n netflix-eureka-naming-server\uff0ccurrency-exchange-server<\/strong>\u548c
\n netflix-zuul-api-gateway-server <\/strong>\u7684\u987a\u5e8f\u76f8\u540c\u3002\n <\/div>\n
\n \u8bb0\u4f4f: <\/strong> \u786e\u4fdd\u6240\u6709
\n \u56db\u4e2a<\/strong>\u670d\u52a1\u5747\u6b63\u5e38\u8fd0\u884c\u3002\n <\/div>\n
\n \u6b65\u9aa46: <\/strong>\u6253\u5f00\u6d4f\u89c8\u5668\u5e76\u8c03\u7528URL http:\/\/localhost:8100\/currency-converter-feign\/from\/USD\/to\/INR\/quantity\/1000 \u3002\u5b83\u8fd4\u56de\u4ee5\u4e0b\u54cd\u5e94:\n <\/div>\n

SpringCloud \u6267\u884c\u8bf7\u6c42_https:\/\/bianchenghao6.com_\u3010SpringCloud \u6559\u7a0b\u3011_\u7b2c5\u5f20 <\/p>\n

\n \u8ba9\u6211\u4eec\u67e5\u770b
\n NetflixZullApiGatewayServerApplication\u7684\u65e5\u5fd7\u3002<\/strong>\n <\/div>\n
\n \u6b65\u9aa47: <\/strong>\u5355\u51fb\u63a7\u5236\u53f0\u56fe\u6807\u65c1\u8fb9\u7684\u7bad\u5934\uff0c\u7136\u540e\u9009\u62e9
\n NetflixZullApiGatewayServerApplication\u3002<\/strong>\n <\/div>\n

SpringCloud \u6267\u884c\u8bf7\u6c42_https:\/\/bianchenghao6.com_\u3010SpringCloud \u6559\u7a0b\u3011_\u7b2c6\u5f20 <\/p>\n

\n \u5b83\u663e\u793a\u4e86\u51e0\u4e2a\u65e5\u5fd7\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002\n <\/div>\n

SpringCloud \u6267\u884c\u8bf7\u6c42_https:\/\/bianchenghao6.com_\u3010SpringCloud \u6559\u7a0b\u3011_\u7b2c7\u5f20 <\/p>\n

\n \u6b65\u9aa48: <\/strong>\u518d\u6b21\u5237\u65b0URL\u3002\u5b83\u5728\u63a7\u5236\u53f0\u4e0a\u663e\u793a\u5355\u4e2a\u65e5\u5fd7\u3002\n <\/div>\n

SpringCloud \u6267\u884c\u8bf7\u6c42_https:\/\/bianchenghao6.com_\u3010SpringCloud \u6559\u7a0b\u3011_\u7b2c8\u5f20 <\/p>\n

\n \u6bcf\u5f53\u6211\u4eec\u901a\u8fc7Feign\u8c03\u7528CurrencyClaculationService(currency-converter-service)\u65f6\uff0c\u90fd\u4f1a\u901a\u8fc7API Gateway\u670d\u52a1\u5668\u8fdb\u884c\u8def\u7531\u3002\u7f51\u5173\u6267\u884c\u4e00\u4e2a\u540d\u4e3a
\n ZuulLoggingFilter <\/strong>\u7684\u8fc7\u6ee4\u5668\uff0c\u8be5\u8fc7\u6ee4\u5668\u8c03\u7528currency-exchange-server\u3002\n <\/div>\n
\n \u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u62e6\u622a
\n currency converter-service <\/strong>\u548c
\n currency-exchange-service\u4e4b\u95f4\u7684\u8c03\u7528 <\/strong>\u3002\u8fd9\u610f\u5473\u7740\u5f53\u6211\u4eec\u8c03\u7528URL\u65f6\uff0cAPI\u7f51\u5173\u4f1a\u6267\u884c
\n \u4e24\u6b21<\/strong>\u3002\n <\/div>\n

\u7b2c\u4e00\u6b21<\/strong>\uff0cAPI\u7f51\u5173\u5728\u6211\u4eec\u8c03\u7528currency-conversion-service\u65f6\u6267\u884c\u3002\u8fd9\u610f\u5473\u7740\u5728\u6267\u884ccurrency-conversion-service\u4e4b\u524d\u3002\u901a\u8fc7API\u7f51\u5173\u8def\u7531\u7684currency-conversion-service\u3002<\/span>
\n \u7b2c\u4e8c\u6b21 API\u7f51\u5173\u5728currency-conversion-service\u8c03\u7528\u8d27\u5e01\u5151\u6362\u670d\u52a1\u65f6\u6267\u884c\u3002\u8fd9\u610f\u5473\u7740\u5728\u6267\u884c currency-conversion-service <\/strong>\u4e4b\u540e\u4e4b\u540e<\/strong>\uff0c\u5728 currency-exchange-service <\/strong>\u6267\u884c\u4e4b\u524d\u4e4b\u524d<\/strong>\u3002\u8d27\u5e01\u5151\u6362\u670d\u52a1\u4e5f\u901a\u8fc7API\u7f51\u5173\u8def\u7531\u3002<\/span> <\/p>\n

\n \u8ba9\u6211\u4eec\u5728\u6211\u4eec\u7684\u9879\u76ee\u4e2d\u5b9e\u73b0\u62e6\u622a\u3002\n <\/div>\n
\n \u53d1\u9001\u8bf7\u6c42 http:\/\/localhost:8765 API\u7f51\u5173\u8bbf\u95ee \u3002 URI\u5c06\u4e3a
\n \/{application-name}\/{uri}\u3002<\/strong>\u5b8c\u6574\u7684URL\u5982\u4e0b\u6240\u793a:\n <\/div>\n
\n http:\/\/localhost:8765\/currency-conversion-service\/currency-converter-feign\/from\/USD\/to\/INR\/quantity\/100
\n 0 <\/u>\n <\/div>\n
\n \u8c03\u7528\u4e0a\u8ff0\u7f51\u5740\u3002\u5b83\u8fd4\u56de\u4e0eURLhttp:\/\/localhost:8100\/currency-converter-feign\/from\/USD\/to\/INR\/quantity\/1000 \u8fd4\u56de\u76f8\u540c\u7684\u54cd\u5e94\u3002\n <\/div>\n

SpringCloud \u6267\u884c\u8bf7\u6c42_https:\/\/bianchenghao6.com_\u3010SpringCloud \u6559\u7a0b\u3011_\u7b2c9\u5f20 <\/p>\n

\n \u6211\u4eec\u5728\u65e5\u5fd7\u4e2d\u770b\u5230\u65e5\u5fd7\u8bb0\u5f55\u8fc7\u6ee4\u5668\u6267\u884c\u4e86
\n \u4e24\u6b21<\/strong>\u3002
\n \u9996\u6b21<\/strong>\u8c03\u7528
\n \u8d27\u5e01\u8f6c\u6362\u5668\u670d\u52a1<\/strong>\uff0c
\n \u7b2c\u4e8c\u6b21<\/strong>\u8c03\u7528
\n \u8d27\u5e01\u8f6c\u6362\u5668\u670d\u52a1<\/strong>\u79f0\u4e3a
\n currency-exchange-service <\/strong>\u3002\n <\/div>\n

SpringCloud \u6267\u884c\u8bf7\u6c42_https:\/\/bianchenghao6.com_\u3010SpringCloud \u6559\u7a0b\u3011_\u7b2c10\u5f20 <\/p>\n

\n \u5728\u672c\u8282\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u901a\u8fc7Zuul API\u7f51\u5173\u670d\u52a1\u5668\u6267\u884c\u4e86\u8fd9\u4e24\u9879\u670d\u52a1\u3002\n <\/div>\n
\n

<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"SpringCloud \u6267\u884c\u8bf7\u6c42zh-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-646","post","type-post","status-publish","format-standard","hentry","category-bc_springcloud_jc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/646"}],"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=646"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/646\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}