{"id":9556,"date":"2023-11-28T21:06:08","date_gmt":"2023-11-28T13:06:08","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=9556"},"modified":"2023-12-06T17:18:59","modified_gmt":"2023-12-06T09:18:59","slug":"springcloud-zhongribbon-de-fu-zai-jun-heng-ce-lue","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/springcloud-zhongribbon-de-fu-zai-jun-heng-ce-lue\/","title":{"rendered":"SpringCloud\u4e2dribbon\u7684\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\uff1f"},"content":{"rendered":"<p>Ribbon \u662f Spring Cloud \u4e2d\u7684\u4e00\u4e2a\u8d1f\u8f7d\u5747\u8861\u5668\uff0c\u7528\u4e8e\u5728\u591a\u4e2a\u670d\u52a1\u5b9e\u4f8b\u4e4b\u95f4\u5206\u53d1\u8bf7\u6c42\u3002Ribbon \u63d0\u4f9b\u4e86\u591a\u79cd\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\uff0c\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u7b56\u7565\u3002\u4ee5\u4e0b\u662f Ribbon \u652f\u6301\u7684\u4e00\u4e9b\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\uff1a<\/p>\n<ol>\n<li>\n<strong>\u8f6e\u8be2\uff08Round Robin\uff09\uff1a<\/strong><\/p>\n<ul>\n<li>\u9ed8\u8ba4\u7684\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\uff0c\u4f9d\u6b21\u8f6e\u8be2\u9009\u62e9\u53ef\u7528\u7684\u670d\u52a1\u5b9e\u4f8b\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<strong>\u968f\u673a\uff08Random\uff09\uff1a<\/strong><\/p>\n<ul>\n<li>\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u53ef\u7528\u7684\u670d\u52a1\u5b9e\u4f8b\u8fdb\u884c\u8bf7\u6c42\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<strong>\u52a0\u6743\u8f6e\u8be2\uff08Weighted Round Robin\uff09\uff1a<\/strong><\/p>\n<ul>\n<li>\u6839\u636e\u670d\u52a1\u5b9e\u4f8b\u7684\u6743\u91cd\u5206\u914d\u8bf7\u6c42\uff0c\u6743\u91cd\u8d8a\u9ad8\uff0c\u88ab\u9009\u4e2d\u7684\u6982\u7387\u8d8a\u5927\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<strong>\u52a0\u6743\u968f\u673a\uff08Weighted Random\uff09\uff1a<\/strong><\/p>\n<ul>\n<li>\u6839\u636e\u670d\u52a1\u5b9e\u4f8b\u7684\u6743\u91cd\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u8fdb\u884c\u8bf7\u6c42\uff0c\u6743\u91cd\u8d8a\u9ad8\uff0c\u88ab\u9009\u4e2d\u7684\u6982\u7387\u8d8a\u5927\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<strong>\u6700\u5c0f\u5e76\u53d1\u8fde\u63a5\uff08Least Connections\uff09\uff1a<\/strong><\/p>\n<ul>\n<li>\u9009\u62e9\u5f53\u524d\u8fde\u63a5\u6570\u6700\u5c0f\u7684\u670d\u52a1\u5b9e\u4f8b\u8fdb\u884c\u8bf7\u6c42\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<strong>\u53ef\u7528\u8fc7\u6ee4\uff08Availability Filter\uff09\uff1a<\/strong><\/p>\n<ul>\n<li>\u8fc7\u6ee4\u6389\u5e76\u53d1\u8fde\u63a5\u6570\u8fc7\u591a\u7684\u670d\u52a1\u5b9e\u4f8b\uff0c\u9009\u62e9\u5176\u4e2d\u4e00\u4e2a\u8fdb\u884c\u8bf7\u6c42\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<strong>\u54cd\u5e94\u65f6\u95f4\u52a0\u6743\uff08Response Time Weighted\uff09\uff1a<\/strong><\/p>\n<ul>\n<li>\u6839\u636e\u670d\u52a1\u5b9e\u4f8b\u7684\u54cd\u5e94\u65f6\u95f4\u52a0\u6743\u9009\u62e9\uff0c\u54cd\u5e94\u65f6\u95f4\u8d8a\u77ed\uff0c\u88ab\u9009\u4e2d\u7684\u6982\u7387\u8d8a\u5927\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<strong>\u81ea\u5b9a\u4e49\u7b56\u7565\uff1a<\/strong><\/p>\n<ul>\n<li>\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u9700\u6c42\u81ea\u5b9a\u4e49\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\uff0c\u5b9e\u73b0 <code>IRule<\/code> \u63a5\u53e3\uff0c\u5e76\u5728\u914d\u7f6e\u4e2d\u6307\u5b9a\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u914d\u7f6e\u793a\u4f8b\uff08\u5728 Spring Cloud \u4e2d\u4f7f\u7528 <code>@RibbonClient<\/code> \u6216\u914d\u7f6e\u6587\u4ef6\u4e2d\u914d\u7f6e\uff09\uff1a<\/p>\n<pre><code class=\"language-yaml\"># \u914d\u7f6e\u5168\u5c40\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\nribbon:\n  NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule\n<\/code><\/pre>\n<p>\u6216<\/p>\n<pre><code class=\"language-java\">@Configuration\npublic class RibbonConfig {\n\n    @Bean\n    public IRule ribbonRule() {\n        \/\/ \u4f7f\u7528\u968f\u673a\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\n        return new RandomRule();\n    }\n}\n<\/code><\/pre>\n<p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u9009\u62e9\u9002\u5f53\u7684\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u4e1a\u52a1\u9700\u6c42\u548c\u7cfb\u7edf\u7279\u6027\u3002\u4e0d\u540c\u7684\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u573a\u666f\uff0c\u4f8b\u5982\uff0c\u8f6e\u8be2\u9002\u7528\u4e8e\u670d\u52a1\u5b9e\u4f8b\u7684\u914d\u7f6e\u76f8\u540c\uff0c\u800c\u52a0\u6743\u8f6e\u8be2\u9002\u7528\u4e8e\u914d\u7f6e\u4e0d\u540c\u7684\u573a\u666f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ribbon \u662f Spring Cloud \u4e2d\u7684\u4e00\u4e2a\u8d1f\u8f7d\u5747\u8861\u5668\uff0c\u7528\u4e8e\u5728\u591a\u4e2a\u670d\u52a1\u5b9e\u4f8b\u4e4b\u95f4\u5206\u53d1\u8bf7\u6c42\u3002Ribbon  [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117],"tags":[],"class_list":["post-9556","post","type-post","status-publish","format-standard","hentry","category-springcloud"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/9556","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=9556"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/9556\/revisions"}],"predecessor-version":[{"id":16738,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/9556\/revisions\/16738"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=9556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=9556"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=9556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}