{"id":2234,"date":"2024-06-07T17:04:19","date_gmt":"2024-06-07T09:04:19","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=2234"},"modified":"2024-06-07T17:04:19","modified_gmt":"2024-06-07T09:04:19","slug":"discovery-service%ef%bc%9a%e5%ad%a6%e4%b9%a0%e6%9c%8d%e5%8a%a1%e5%8f%91%e7%8e%b0%e5%92%8c%e4%be%9d%e8%b5%96%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2024\/06\/07\/discovery-service%ef%bc%9a%e5%ad%a6%e4%b9%a0%e6%9c%8d%e5%8a%a1%e5%8f%91%e7%8e%b0%e5%92%8c%e4%be%9d%e8%b5%96%e9%85%8d%e7%bd%ae\/","title":{"rendered":"discovery-service\uff1a\u5b66\u4e60\u670d\u52a1\u53d1\u73b0\u548c\u4f9d\u8d56\u914d\u7f6e"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">1. discovery-service \u7684\u89d2\u8272<\/h4>\n\n\n\n<p>\u5728\u5fae\u670d\u52a1\u67b6\u6784\u4e2d\uff0c\u670d\u52a1\u53d1\u73b0\uff08Service Discovery\uff09\u662f\u4e00\u4e2a\u5173\u952e\u7ec4\u4ef6\uff0c\u5b83\u5141\u8bb8\u670d\u52a1\u81ea\u52a8\u6ce8\u518c\u5e76\u80fd\u52a8\u6001\u67e5\u627e\u5176\u4ed6\u670d\u52a1\u7684\u4f4d\u7f6e\u3002Eureka\u662fNetflix\u5f00\u6e90\u7684\u4e00\u4e2a\u670d\u52a1\u53d1\u73b0\u7ec4\u4ef6\uff0c\u5728Spring Cloud\u4e2d\u88ab\u5e7f\u6cdb\u4f7f\u7528\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2. \u914d\u7f6e\u89e3\u8bfb<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><code>version: \"3.7\"\nservices:\n  discovery-service:\n    image: piomin\/discovery-service:1.1-SNAPSHOT\n    ports:\n      - \"8061:8061\"\n    depends_on:\n      config-service:\n        condition: service_healthy\n    links:\n      - config-service\n    healthcheck:\n      test: curl --fail http:\/\/localhost:8061\/eureka\/v2\/apps || exit 1\n      interval: 4s\n      timeout: 2s\n      retries: 3\n    environment:\n      SPRING_PROFILES_ACTIVE: docker\n<\/code><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3. \u670d\u52a1\u53d1\u73b0<\/h4>\n\n\n\n<p>\u670d\u52a1\u53d1\u73b0\u7684\u4f5c\u7528\u662f\u8ba9\u670d\u52a1\u53ef\u4ee5\u52a8\u6001\u5730\u627e\u5230\u5176\u4ed6\u670d\u52a1\u7684\u5b9e\u4f8b\uff0c\u800c\u4e0d\u9700\u8981\u786c\u7f16\u7801\u670d\u52a1\u5730\u5740\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Eureka<\/strong>\uff1aNetflix\u7684\u4e00\u4e2a\u670d\u52a1\u53d1\u73b0\u7ec4\u4ef6\uff0c\u63d0\u4f9b\u670d\u52a1\u6ce8\u518c\u548c\u53d1\u73b0\u529f\u80fd\u3002\u670d\u52a1\u5728\u542f\u52a8\u65f6\u4f1a\u6ce8\u518c\u5230Eureka Server\u4e0a\uff0cEureka Server\u4f1a\u7ef4\u62a4\u4e00\u4e2a\u670d\u52a1\u5b9e\u4f8b\u5217\u8868\uff0c\u4f9b\u5176\u4ed6\u670d\u52a1\u67e5\u627e\u3002<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">4. \u4f9d\u8d56\u914d\u7f6e\uff08depends_on \u548c links\uff09<\/h4>\n\n\n\n<p>\u4f9d\u8d56\u914d\u7f6e\u7528\u4e8e\u5b9a\u4e49\u670d\u52a1\u4e4b\u95f4\u7684\u542f\u52a8\u987a\u5e8f\u548c\u7f51\u7edc\u8fde\u63a5\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>depends_on<\/strong>: \u5b9a\u4e49\u670d\u52a1\u7684\u542f\u52a8\u987a\u5e8f\u548c\u4f9d\u8d56\u5173\u7cfb\u3002<\/li><li><strong>links<\/strong>: \u5efa\u7acb\u5bb9\u5668\u4e4b\u95f4\u7684\u7f51\u7edc\u8fde\u63a5\uff0c\u4f7f\u5f97\u4e00\u4e2a\u5bb9\u5668\u53ef\u4ee5\u901a\u8fc7\u540d\u79f0\u8bbf\u95ee\u53e6\u4e00\u4e2a\u5bb9\u5668\u3002<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">5. \u914d\u7f6e\u8be6\u89e3<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><code>image: piomin\/discovery-service:1.1-SNAPSHOT<\/code><\/strong>: \u4f7f\u7528\u6307\u5b9a\u7684\u955c\u50cf\u6765\u8fd0\u884cdiscovery-service\u3002<\/li><li><strong><code>ports: [\"8061:8061\"]<\/code><\/strong>: \u5c06\u4e3b\u673a\u76848061\u7aef\u53e3\u6620\u5c04\u5230\u5bb9\u5668\u76848061\u7aef\u53e3\u3002<\/li><li><strong><code>depends_on<\/code><\/strong>: \u5b9a\u4e49\u670d\u52a1\u7684\u4f9d\u8d56\u5173\u7cfb\u3002<ul><li><code>config-service<\/code>: \u5b9a\u4e49\u4f9d\u8d56\u7684\u670d\u52a1\u3002<\/li><li><code>condition: service_healthy<\/code>: \u8868\u793a\u53ea\u6709\u5f53config-service\u5065\u5eb7\u68c0\u67e5\u901a\u8fc7\u65f6\uff0cdiscovery-service\u624d\u4f1a\u542f\u52a8\u3002<\/li><\/ul><\/li><li><strong><code>links<\/code><\/strong>: \u4f7fdiscovery-service\u53ef\u4ee5\u901a\u8fc7\u540d\u79f0\u8bbf\u95eeconfig-service\u3002<ul><li><code>config-service<\/code>: \u94fe\u63a5\u5230config-service\u5bb9\u5668\u3002<\/li><\/ul><\/li><li><strong><code>healthcheck<\/code><\/strong>: \u914d\u7f6e\u5065\u5eb7\u68c0\u67e5\u3002<ul><li><code>test: curl --fail http:\/\/localhost:8061\/eureka\/v2\/apps || exit 1<\/code>: \u68c0\u67e5Eureka Server\u7684API\u63a5\u53e3\u662f\u5426\u53ef\u7528\u3002<\/li><li><code>interval: 4s<\/code>: \u6bcf4\u79d2\u8fdb\u884c\u4e00\u6b21\u5065\u5eb7\u68c0\u67e5\u3002<\/li><li><code>timeout: 2s<\/code>: \u5065\u5eb7\u68c0\u67e5\u7684\u8d85\u65f6\u65f6\u95f4\u4e3a2\u79d2\u3002<\/li><li><code>retries: 3<\/code>: \u5982\u679c\u8fde\u7eed3\u6b21\u5065\u5eb7\u68c0\u67e5\u5931\u8d25\uff0c\u5219\u8ba4\u4e3a\u5bb9\u5668\u4e0d\u5065\u5eb7\u3002<\/li><\/ul><\/li><li><strong><code>environment<\/code><\/strong>: \u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3002<ul><li><code>SPRING_PROFILES_ACTIVE: docker<\/code>: \u8bbe\u7f6eSpring Boot\u7684\u6fc0\u6d3b\u914d\u7f6e\u6587\u4ef6\u4e3adocker\u3002<\/li><\/ul><\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">6. \u5b9e\u8df5\u793a\u4f8b<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Docker Compose \u6587\u4ef6\u793a\u4f8b<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code><code>version: \"3.7\"\nservices:\n  config-service:\n    image: piomin\/config-service:1.1-SNAPSHOT\n    ports:\n      - \"8088:8088\"\n    healthcheck:\n      test: curl --fail http:\/\/localhost:8088\/employee\/docker || exit 1\n      interval: 5s\n      timeout: 2s\n      retries: 3\n\n  discovery-service:\n    image: piomin\/discovery-service:1.1-SNAPSHOT\n    ports:\n      - \"8061:8061\"\n    depends_on:\n      config-service:\n        condition: service_healthy\n    links:\n      - config-service\n    healthcheck:\n      test: curl --fail http:\/\/localhost:8061\/eureka\/v2\/apps || exit 1\n      interval: 4s\n      timeout: 2s\n      retries: 3\n    environment:\n      SPRING_PROFILES_ACTIVE: docker\n<\/code><\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">\u8fd0\u884c\u670d\u52a1<\/h5>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>\u542f\u52a8config-service\u548cdiscovery-service<\/strong>:bash\u590d\u5236\u4ee3\u7801<code>docker-compose up -d config-service discovery-service<\/code><\/li><li><strong>\u9a8c\u8bc1\u670d\u52a1\u5065\u5eb7\u72b6\u51b5<\/strong>:<ul><li>\u68c0\u67e5config-service\u662f\u5426\u542f\u52a8\u5e76\u5065\u5eb7\u3002<\/li><li>\u68c0\u67e5discovery-service\u662f\u5426\u80fd\u591f\u6210\u529f\u542f\u52a8\u5e76\u5065\u5eb7\u3002<\/li><\/ul><\/li><li><strong>\u67e5\u770bEureka Server<\/strong>:<ul><li>\u6253\u5f00\u6d4f\u89c8\u5668\uff0c\u8bbf\u95ee<code>http:\/\/localhost:8061<\/code>\uff0c\u4f60\u5e94\u8be5\u80fd\u591f\u770b\u5230Eureka Server\u7684\u63a7\u5236\u53f0\u754c\u9762\uff0c\u5176\u4e2d\u5217\u51fa\u4e86\u5df2\u6ce8\u518c\u7684\u670d\u52a1\u3002<\/li><\/ul><\/li><\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">7. \u7ed3\u8bba<\/h4>\n\n\n\n<p>\u901a\u8fc7\u5b66\u4e60\u670d\u52a1\u53d1\u73b0\u548c\u4f9d\u8d56\u914d\u7f6e\uff0c\u4f60\u53ef\u4ee5\u66f4\u597d\u5730\u7ba1\u7406\u548c\u534f\u8c03\u5fae\u670d\u52a1\u7684\u542f\u52a8\u987a\u5e8f\u548c\u5065\u5eb7\u72b6\u51b5\u3002\u670d\u52a1\u53d1\u73b0\u7ec4\u4ef6\u5982Eureka\u4f7f\u5f97\u670d\u52a1\u53ef\u4ee5\u52a8\u6001\u6ce8\u518c\u548c\u53d1\u73b0\uff0c\u7b80\u5316\u4e86\u670d\u52a1\u95f4\u7684\u901a\u4fe1\u548c\u7ba1\u7406\u3002\u4f9d\u8d56\u914d\u7f6e\u786e\u4fdd\u670d\u52a1\u5728\u6b63\u786e\u7684\u987a\u5e8f\u4e2d\u542f\u52a8\uff0c\u5e76\u4e14\u53ef\u4ee5\u81ea\u52a8\u5904\u7406\u670d\u52a1\u7684\u5065\u5eb7\u72b6\u51b5\uff0c\u4ece\u800c\u63d0\u9ad8\u7cfb\u7edf\u7684\u53ef\u9760\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. discovery-ser&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-2234","post","type-post","status-publish","format-standard","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/2234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=2234"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/2234\/revisions"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=2234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=2234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=2234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}