{"id":4673,"date":"2021-12-19T21:53:19","date_gmt":"2021-12-19T13:53:19","guid":{"rendered":"http:\/\/123.57.164.21\/?p=4673"},"modified":"2021-12-19T21:53:19","modified_gmt":"2021-12-19T13:53:19","slug":"spring-cloud-gateway-%e9%99%90%e6%b5%81","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=4673","title":{"rendered":"spring cloud gateway \u9650\u6d41"},"content":{"rendered":"\n<p>\u5728\u9ad8\u5e76\u53d1\u7684\u7cfb\u7edf\u4e2d\uff0c\u5f80\u5f80\u9700\u8981\u5728\u7cfb\u7edf\u4e2d\u505a\u9650\u6d41\uff0c\u4e00\u65b9\u9762\u662f\u4e3a\u4e86\u9632\u6b62\u5927\u91cf\u7684\u8bf7\u6c42\u4f7f\u670d\u52a1\u5668\u8fc7\u8f7d\uff0c\u5bfc\u81f4\u670d\u52a1\u4e0d\u53ef\u7528\uff0c\u53e6\u4e00\u65b9\u9762\u662f\u4e3a\u4e86\u9632\u6b62\u7f51\u7edc\u653b\u51fb\u3002<\/p>\n\n\n\n<p>\u5e38\u89c1\u7684\u9650\u6d41\u65b9\u5f0f\uff0c\u6bd4\u5982Hystrix\u9002\u7528\u7ebf\u7a0b\u6c60\u9694\u79bb\uff0c\u8d85\u8fc7\u7ebf\u7a0b\u6c60\u7684\u8d1f\u8f7d\uff0c\u8d70\u7194\u65ad\u7684\u903b\u8f91\u3002\u5728\u4e00\u822c\u5e94\u7528\u670d\u52a1\u5668\u4e2d\uff0c\u6bd4\u5982tomcat\u5bb9\u5668\u4e5f\u662f\u901a\u8fc7\u9650\u5236\u5b83\u7684\u7ebf\u7a0b\u6570\u6765\u63a7\u5236\u5e76\u53d1\u7684\uff1b\u4e5f\u6709\u901a\u8fc7\u65f6\u95f4\u7a97\u53e3\u7684\u5e73\u5747\u901f\u5ea6\u6765\u63a7\u5236\u6d41\u91cf\u3002\u5e38\u89c1\u7684\u9650\u6d41\u7eac\u5ea6\u6709\u6bd4\u5982\u901a\u8fc7Ip\u6765\u9650\u6d41\u3001\u901a\u8fc7uri\u6765\u9650\u6d41\u3001\u901a\u8fc7\u7528\u6237\u8bbf\u95ee\u9891\u6b21\u6765\u9650\u6d41\u3002<\/p>\n\n\n\n<p>\u4e00\u822c\u9650\u6d41\u90fd\u662f\u5728\u7f51\u5173\u8fd9\u4e00\u5c42\u505a\uff0c\u6bd4\u5982Nginx\u3001Openresty\u3001kong\u3001zuul\u3001Spring Cloud Gateway\u7b49\uff1b\u4e5f\u53ef\u4ee5\u5728\u5e94\u7528\u5c42\u901a\u8fc7Aop\u8fd9\u79cd\u65b9\u5f0f\u53bb\u505a\u9650\u6d41\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">\u5e38\u89c1\u7684\u9650\u6d41\u7b97\u6cd5<\/h5>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>\u8ba1\u6570\u5668\u7b97\u6cd5<\/strong><\/p>\n\n\n\n<p>\u8ba1\u6570\u5668\u7b97\u6cd5\u91c7\u7528\u8ba1\u6570\u5668\u5b9e\u73b0\u9650\u6d41\u6709\u70b9\u7b80\u5355\u7c97\u66b4\uff0c\u4e00\u822c\u6211\u4eec\u4f1a\u9650\u5236\u4e00\u79d2\u949f\u7684\u80fd\u591f\u901a\u8fc7\u7684\u8bf7\u6c42\u6570\uff0c\u6bd4\u5982\u9650\u6d41qps\u4e3a100\uff0c\u7b97\u6cd5\u7684\u5b9e\u73b0\u601d\u8def\u5c31\u662f\u4ece\u7b2c\u4e00\u4e2a\u8bf7\u6c42\u8fdb\u6765\u5f00\u59cb\u8ba1\u65f6\uff0c\u5728\u63a5\u4e0b\u53bb\u76841s\u5185\uff0c\u6bcf\u6765\u4e00\u4e2a\u8bf7\u6c42\uff0c\u5c31\u628a\u8ba1\u6570\u52a01\uff0c\u5982\u679c\u7d2f\u52a0\u7684\u6570\u5b57\u8fbe\u5230\u4e86100\uff0c\u90a3\u4e48\u540e\u7eed\u7684\u8bf7\u6c42\u5c31\u4f1a\u88ab\u5168\u90e8\u62d2\u7edd\u3002\u7b49\u52301s\u7ed3\u675f\u540e\uff0c\u628a\u8ba1\u6570\u6062\u590d\u62100\uff0c\u91cd\u65b0\u5f00\u59cb\u8ba1\u6570\u3002\u5177\u4f53\u7684\u5b9e\u73b0\u53ef\u4ee5\u662f\u8fd9\u6837\u7684\uff1a\u5bf9\u4e8e\u6bcf\u6b21\u670d\u52a1\u8c03\u7528\uff0c\u53ef\u4ee5\u901a\u8fc7AtomicLong#incrementAndGet()\u65b9\u6cd5\u6765\u7ed9\u8ba1\u6570\u5668\u52a01\u5e76\u8fd4\u56de\u6700\u65b0\u503c\uff0c\u901a\u8fc7\u8fd9\u4e2a\u6700\u65b0\u503c\u548c\u9608\u503c\u8fdb\u884c\u6bd4\u8f83\u3002\u8fd9\u79cd\u5b9e\u73b0\u65b9\u5f0f\uff0c\u76f8\u4fe1\u5927\u5bb6\u90fd\u77e5\u9053\u6709\u4e00\u4e2a\u5f0a\u7aef\uff1a\u5982\u679c\u6211\u5728\u5355\u4f4d\u65f6\u95f41s\u5185\u7684\u524d10ms\uff0c\u5df2\u7ecf\u901a\u8fc7\u4e86100\u4e2a\u8bf7\u6c42\uff0c\u90a3\u540e\u9762\u7684990ms\uff0c\u53ea\u80fd\u773c\u5df4\u5df4\u7684\u628a\u8bf7\u6c42\u62d2\u7edd\uff0c\u6211\u4eec\u628a\u8fd9\u79cd\u73b0\u8c61\u79f0\u4e3a\u201c\u7a81\u523a\u73b0\u8c61\u201d<\/p>\n\n\n\n<p><strong>\u6f0f\u6876\u7b97\u6cd5<\/strong><\/p>\n\n\n\n<p>\u6f0f\u6876\u7b97\u6cd5\u4e3a\u4e86\u6d88\u9664\u201d\u7a81\u523a\u73b0\u8c61\u201d\uff0c\u53ef\u4ee5\u91c7\u7528\u6f0f\u6876\u7b97\u6cd5\u5b9e\u73b0\u9650\u6d41\uff0c\u6f0f\u6876\u7b97\u6cd5\u8fd9\u4e2a\u540d\u5b57\u5c31\u5f88\u5f62\u8c61\uff0c\u7b97\u6cd5\u5185\u90e8\u6709\u4e00\u4e2a\u5bb9\u5668\uff0c\u7c7b\u4f3c\u751f\u6d3b\u7528\u5230\u7684\u6f0f\u6597\uff0c\u5f53\u8bf7\u6c42\u8fdb\u6765\u65f6\uff0c\u76f8\u5f53\u4e8e\u6c34\u5012\u5165\u6f0f\u6597\uff0c\u7136\u540e\u4ece\u4e0b\u7aef\u5c0f\u53e3\u6162\u6162\u5300\u901f\u7684\u6d41\u51fa\u3002\u4e0d\u7ba1\u4e0a\u9762\u6d41\u91cf\u591a\u5927\uff0c\u4e0b\u9762\u6d41\u51fa\u7684\u901f\u5ea6\u59cb\u7ec8\u4fdd\u6301\u4e0d\u53d8\u3002\u4e0d\u7ba1\u670d\u52a1\u8c03\u7528\u65b9\u591a\u4e48\u4e0d\u7a33\u5b9a\uff0c\u901a\u8fc7\u6f0f\u6876\u7b97\u6cd5\u8fdb\u884c\u9650\u6d41\uff0c\u6bcf10\u6beb\u79d2\u5904\u7406\u4e00\u6b21\u8bf7\u6c42\u3002\u56e0\u4e3a\u5904\u7406\u7684\u901f\u5ea6\u662f\u56fa\u5b9a\u7684\uff0c\u8bf7\u6c42\u8fdb\u6765\u7684\u901f\u5ea6\u662f\u672a\u77e5\u7684\uff0c\u53ef\u80fd\u7a81\u7136\u8fdb\u6765\u5f88\u591a\u8bf7\u6c42\uff0c\u6ca1\u6765\u5f97\u53ca\u5904\u7406\u7684\u8bf7\u6c42\u5c31\u5148\u653e\u5728\u6876\u91cc\uff0c\u65e2\u7136\u662f\u4e2a\u6876\uff0c\u80af\u5b9a\u662f\u6709\u5bb9\u91cf\u4e0a\u9650\uff0c\u5982\u679c\u6876\u6ee1\u4e86\uff0c\u90a3\u4e48\u65b0\u8fdb\u6765\u7684\u8bf7\u6c42\u5c31\u4e22\u5f03\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/12\/image-236.png\" alt=\"\" class=\"wp-image-4674\" width=\"644\" height=\"434\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-236.png 928w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-236-300x202.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-236-768x518.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-236-830x560.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-236-230x155.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-236-350x236.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-236-480x324.png 480w\" sizes=\"(max-width: 644px) 100vw, 644px\" \/><\/figure><\/div>\n\n\n\n<p>\u5728\u7b97\u6cd5\u5b9e\u73b0\u65b9\u9762\uff0c\u53ef\u4ee5\u51c6\u5907\u4e00\u4e2a\u961f\u5217\uff0c\u7528\u6765\u4fdd\u5b58\u8bf7\u6c42\uff0c\u53e6\u5916\u901a\u8fc7\u4e00\u4e2a\u7ebf\u7a0b\u6c60\uff08ScheduledExecutorService\uff09\u6765\u5b9a\u671f\u4ece\u961f\u5217\u4e2d\u83b7\u53d6\u8bf7\u6c42\u5e76\u6267\u884c\uff0c\u53ef\u4ee5\u4e00\u6b21\u6027\u83b7\u53d6\u591a\u4e2a\u5e76\u53d1\u6267\u884c\u3002<\/p>\n\n\n\n<p>\u8fd9\u79cd\u7b97\u6cd5\uff0c\u5728\u4f7f\u7528\u8fc7\u540e\u4e5f\u5b58\u5728\u5f0a\u7aef\uff1a\u65e0\u6cd5\u5e94\u5bf9\u77ed\u65f6\u95f4\u7684\u7a81\u53d1\u6d41\u91cf\u3002<\/p>\n\n\n\n<p><strong>\u4ee4\u724c\u6876\u7b97\u6cd5<\/strong><\/p>\n\n\n\n<p>\u4ece\u67d0\u79cd\u610f\u4e49\u4e0a\u8bb2\uff0c\u4ee4\u724c\u6876\u7b97\u6cd5\u662f\u5bf9\u6f0f\u6876\u7b97\u6cd5\u7684\u4e00\u79cd\u6539\u8fdb\uff0c\u6876\u7b97\u6cd5\u80fd\u591f\u9650\u5236\u8bf7\u6c42\u8c03\u7528\u7684\u901f\u7387\uff0c\u800c\u4ee4\u724c\u6876\u7b97\u6cd5\u80fd\u591f\u5728\u9650\u5236\u8c03\u7528\u7684\u5e73\u5747\u901f\u7387\u7684\u540c\u65f6\u8fd8\u5141\u8bb8\u4e00\u5b9a\u7a0b\u5ea6\u7684\u7a81\u53d1\u8c03\u7528\u3002\u5728\u4ee4\u724c\u6876\u7b97\u6cd5\u4e2d\uff0c\u5b58\u5728\u4e00\u4e2a\u6876\uff0c\u7528\u6765\u5b58\u653e\u56fa\u5b9a\u6570\u91cf\u7684\u4ee4\u724c\u3002\u7b97\u6cd5\u4e2d\u5b58\u5728\u4e00\u79cd\u673a\u5236\uff0c\u4ee5\u4e00\u5b9a\u7684\u901f\u7387\u5f80\u6876\u4e2d\u653e\u4ee4\u724c\u3002\u6bcf\u6b21\u8bf7\u6c42\u8c03\u7528\u9700\u8981\u5148\u83b7\u53d6\u4ee4\u724c\uff0c\u53ea\u6709\u62ff\u5230\u4ee4\u724c\uff0c\u624d\u6709\u673a\u4f1a\u7ee7\u7eed\u6267\u884c\uff0c\u5426\u5219\u9009\u62e9\u9009\u62e9\u7b49\u5f85\u53ef\u7528\u7684\u4ee4\u724c\u3001\u6216\u8005\u76f4\u63a5\u62d2\u7edd\u3002\u653e\u4ee4\u724c\u8fd9\u4e2a\u52a8\u4f5c\u662f\u6301\u7eed\u4e0d\u65ad\u7684\u8fdb\u884c\uff0c\u5982\u679c\u6876\u4e2d\u4ee4\u724c\u6570\u8fbe\u5230\u4e0a\u9650\uff0c\u5c31\u4e22\u5f03\u4ee4\u724c\uff0c\u6240\u4ee5\u5c31\u5b58\u5728\u8fd9\u79cd\u60c5\u51b5\uff0c\u6876\u4e2d\u4e00\u76f4\u6709\u5927\u91cf\u7684\u53ef\u7528\u4ee4\u724c\uff0c\u8fd9\u65f6\u8fdb\u6765\u7684\u8bf7\u6c42\u5c31\u53ef\u4ee5\u76f4\u63a5\u62ff\u5230\u4ee4\u724c\u6267\u884c\uff0c\u6bd4\u5982\u8bbe\u7f6eqps\u4e3a100\uff0c\u90a3\u4e48\u9650\u6d41\u5668\u521d\u59cb\u5316\u5b8c\u6210\u4e00\u79d2\u540e\uff0c\u6876\u4e2d\u5c31\u5df2\u7ecf\u6709100\u4e2a\u4ee4\u724c\u4e86\uff0c\u8fd9\u65f6\u670d\u52a1\u8fd8\u6ca1\u5b8c\u5168\u542f\u52a8\u597d\uff0c\u7b49\u542f\u52a8\u5b8c\u6210\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\u65f6\uff0c\u8be5\u9650\u6d41\u5668\u53ef\u4ee5\u62b5\u6321\u77ac\u65f6\u7684100\u4e2a\u8bf7\u6c42\u3002\u6240\u4ee5\uff0c\u53ea\u6709\u6876\u4e2d\u6ca1\u6709\u4ee4\u724c\u65f6\uff0c\u8bf7\u6c42\u624d\u4f1a\u8fdb\u884c\u7b49\u5f85\uff0c\u6700\u540e\u76f8\u5f53\u4e8e\u4ee5\u4e00\u5b9a\u7684\u901f\u7387\u6267\u884c\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/12\/image-237-794x1024.png\" alt=\"\" class=\"wp-image-4675\" width=\"411\" height=\"530\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-237-794x1024.png 794w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-237-233x300.png 233w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-237-768x991.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-237-830x1071.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-237-230x297.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-237-350x452.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-237-480x619.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-237.png 1020w\" sizes=\"(max-width: 411px) 100vw, 411px\" \/><\/figure><\/div>\n\n\n\n<p>\u5b9e\u73b0\u601d\u8def\uff1a\u53ef\u4ee5\u51c6\u5907\u4e00\u4e2a\u961f\u5217\uff0c\u7528\u6765\u4fdd\u5b58\u4ee4\u724c\uff0c\u53e6\u5916\u901a\u8fc7\u4e00\u4e2a\u7ebf\u7a0b\u6c60\u5b9a\u671f\u751f\u6210\u4ee4\u724c\u653e\u5230\u961f\u5217\u4e2d\uff0c\u6bcf\u6765\u4e00\u4e2a\u8bf7\u6c42\uff0c\u5c31\u4ece\u961f\u5217\u4e2d\u83b7\u53d6\u4e00\u4e2a\u4ee4\u724c\uff0c\u5e76\u7ee7\u7eed\u6267\u884c\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Spring Cloud Gateway\u9650\u6d41<\/h5>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5728Spring Cloud Gateway\u4e2d\uff0c\u6709Filter\u8fc7\u6ee4\u5668\uff0c\u56e0\u6b64\u53ef\u4ee5\u5728\u201cpre\u201d\u7c7b\u578b\u7684Filter\u4e2d\u81ea\u884c\u5b9e\u73b0\u4e0a\u8ff0\u4e09\u79cd\u8fc7\u6ee4\u5668\u3002\u4f46\u662f\u9650\u6d41\u4f5c\u4e3a\u7f51\u5173\u6700\u57fa\u672c\u7684\u529f\u80fd\uff0cSpring Cloud Gateway\u5b98\u65b9\u5c31\u63d0\u4f9b\u4e86RequestRateLimiterGatewayFilterFactory\u8fd9\u4e2a\u7c7b\uff0c\u9002\u7528Redis\u548clua\u811a\u672c\u5b9e\u73b0\u4e86\u4ee4\u724c\u6876\u7684\u65b9\u5f0f\u3002\u5177\u4f53\u5b9e\u73b0\u903b\u8f91\u5728RequestRateLimiterGatewayFilterFactory\u7c7b\u4e2d\uff0clua\u811a\u672c\u5728\u5982\u4e0b\u56fe\u6240\u793a\u7684\u6587\u4ef6\u5939\u4e2d\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/12\/image-238-1024x387.png\" alt=\"\" class=\"wp-image-4676\" width=\"621\" height=\"234\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-238-1024x387.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-238-300x113.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-238-768x290.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-238-830x313.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-238-230x87.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-238-350x132.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-238-480x181.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-238.png 1208w\" sizes=\"(max-width: 621px) 100vw, 621px\" \/><\/figure><\/div>\n\n\n\n<p>\u5177\u4f53\u6e90\u7801\u4e0d\u6253\u7b97\u5728\u8fd9\u91cc\u8bb2\u8ff0\uff0c\u8bfb\u8005\u53ef\u4ee5\u81ea\u884c\u67e5\u770b\uff0c\u4ee3\u7801\u91cf\u8f83\u5c11\uff0c\u5148\u4ee5\u6848\u4f8b\u7684\u5f62\u5f0f\u6765\u8bb2\u89e3\u5982\u4f55\u5728Spring Cloud Gateway\u4e2d\u4f7f\u7528\u5185\u7f6e\u7684\u9650\u6d41\u8fc7\u6ee4\u5668\u5de5\u5382\u6765\u5b9e\u73b0\u9650\u6d41\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u5728\u5de5\u7a0b\u7684pom\u6587\u4ef6\u4e2d\u5f15\u5165gateway\u7684\u8d77\u6b65\u4f9d\u8d56\u548credis\u7684reactive\u4f9d\u8d56\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\n &lt;dependency>\n    &lt;groupId>org.springframework.cloud&lt;\/groupId>\n    &lt;artifactId>spring-cloud-starter-gateway&lt;\/artifactId>\n&lt;\/dependency>\n\n&lt;dependency>\n    &lt;groupId>org.springframework.boot&lt;\/groupId>\n    &lt;artifatId>spring-boot-starter-data-redis-reactive&lt;\/artifactId>\n&lt;\/dependency>\n\n<\/pre>\n\n\n\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u505a\u4ee5\u4e0b\u7684\u914d\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">server:\n  port: 8081\nspring:\n  cloud:\n    gateway:\n      routes:\n      - id: limit_route\n        uri: http:\/\/httpbin.org:80\/get\n        predicates:\n        - After=2017-01-20T17:42:47.789-07:00[America\/Denver]\n        filters:\n        - name: RequestRateLimiter\n          args:\n            key-resolver: '#{@hostAddrKeyResolver}'\n            redis-rate-limiter.replenishRate: 1\n            redis-rate-limiter.burstCapacity: 3\n  application:\n    name: gateway-limiter\n  redis:\n    host: localhost\n    port: 6379\n    database: 0<\/pre>\n\n\n\n<p>\u5728\u4e0a\u9762\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u6307\u5b9a\u7a0b\u5e8f\u7684\u7aef\u53e3\u4e3a8081\uff0c\u914d\u7f6e\u4e86 redis\u7684\u4fe1\u606f\uff0c\u5e76\u914d\u7f6e\u4e86RequestRateLimiter\u7684\u9650\u6d41\u8fc7\u6ee4\u5668\uff0c\u8be5\u8fc7\u6ee4\u5668\u9700\u8981\u914d\u7f6e\u4e09\u4e2a\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul><li>burstCapacity\uff0c\u4ee4\u724c\u6876\u603b\u5bb9\u91cf\u3002<\/li><li>replenishRate\uff0c\u4ee4\u724c\u6876\u6bcf\u79d2\u586b\u5145\u5e73\u5747\u901f\u7387\u3002<\/li><li>key-resolver\uff0c\u7528\u4e8e\u9650\u6d41\u7684\u952e\u7684\u89e3\u6790\u5668\u7684 Bean \u5bf9\u8c61\u7684\u540d\u5b57\u3002\u5b83\u4f7f\u7528 SpEL \u8868\u8fbe\u5f0f\u6839\u636e#{@beanName}\u4ece Spring \u5bb9\u5668\u4e2d\u83b7\u53d6 Bean \u5bf9\u8c61\u3002<\/li><\/ul>\n\n\n\n<p>KeyResolver\u9700\u8981\u5b9e\u73b0resolve\u65b9\u6cd5\uff0c\u6bd4\u5982\u6839\u636eHostname\u8fdb\u884c\u9650\u6d41\uff0c\u5219\u9700\u8981\u7528hostAddress\u53bb\u5224\u65ad\u3002\u5b9e\u73b0\u5b8cKeyResolver\u4e4b\u540e\uff0c\u9700\u8981\u5c06\u8fd9\u4e2a\u7c7b\u7684Bean\u6ce8\u518c\u5230Ioc\u5bb9\u5668\u4e2d\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\npublic class HostAddrKeyResolver implements KeyResolver {\n\n    @Override\n    public Mono&lt;String> resolve(ServerWebExchange exchange) {\n        return Mono.just(exchange.getRequest().getRemoteAddress().getAddress().getHostAddress());\n    }\n\n}\n\n @Bean\n    public HostAddrKeyResolver hostAddrKeyResolver() {\n        return new HostAddrKeyResolver();\n    }\n<\/pre>\n\n\n\n<p>\u53ef\u4ee5\u6839\u636euri\u53bb\u9650\u6d41\uff0c\u8fd9\u65f6KeyResolver\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public class UriKeyResolver  implements KeyResolver {\n\n    @Override\n    public Mono&lt;String> resolve(ServerWebExchange exchange) {\n        return Mono.just(exchange.getRequest().getURI().getPath());\n    }\n\n}\n\n @Bean\n    public UriKeyResolver uriKeyResolver() {\n        return new UriKeyResolver();\n    }\n\n \n<\/pre>\n\n\n\n<p>\u4e5f\u53ef\u4ee5\u4ee5\u7528\u6237\u7684\u7ef4\u5ea6\u53bb\u9650\u6d41\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">  @Bean\n    KeyResolver userKeyResolver() {\n        return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst(\"user\"));\n    }\n\n<\/pre>\n\n\n\n<p>\u7528jmeter\u8fdb\u884c\u538b\u6d4b\uff0c\u914d\u7f6e10thread\u53bb\u5faa\u73af\u8bf7\u6c42lcoalhost:8081\uff0c\u5faa\u73af\u95f4\u96941s\u3002\u4ece\u538b\u6d4b\u7684\u7ed3\u679c\u4e0a\u770b\u5230\u6709\u90e8\u5206\u8bf7\u6c42\u901a\u8fc7\uff0c\u7531\u90e8\u5206\u8bf7\u6c42\u5931\u8d25\u3002\u901a\u8fc7redis\u5ba2\u6237\u7aef\u53bb\u67e5\u770bredis\u4e2d\u5b58\u5728\u7684key\u3002\u5982\u4e0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2021\/12\/image-239.png\" alt=\"\" class=\"wp-image-4677\" width=\"677\" height=\"164\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-239.png 934w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-239-300x73.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-239-768x186.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-239-830x201.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-239-230x56.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-239-350x85.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2021\/12\/image-239-480x116.png 480w\" sizes=\"(max-width: 677px) 100vw, 677px\" \/><\/figure><\/div>\n\n\n\n<p>\u53ef\u89c1\uff0cRequestRateLimiter\u662f\u4f7f\u7528Redis\u6765\u8fdb\u884c\u9650\u6d41\u7684\uff0c\u5e76\u5728redis\u4e2d\u5b58\u50a8\u4e862\u4e2akey\u3002\u5173\u6ce8\u8fd9\u4e24\u4e2akey\u542b\u4e49\u53ef\u4ee5\u770blua\u6e90\u4ee3\u7801\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u9ad8\u5e76\u53d1\u7684\u7cfb\u7edf\u4e2d\uff0c\u5f80\u5f80\u9700\u8981\u5728\u7cfb\u7edf\u4e2d\u505a\u9650\u6d41\uff0c\u4e00\u65b9\u9762\u662f\u4e3a\u4e86\u9632\u6b62\u5927\u91cf\u7684\u8bf7\u6c42\u4f7f\u670d\u52a1\u5668\u8fc7\u8f7d\uff0c\u5bfc\u81f4\u670d\u52a1\u4e0d\u53ef\u7528\uff0c\u53e6\u4e00\u65b9\u9762\u662f\u4e3a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4673"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4673"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4673\/revisions"}],"predecessor-version":[{"id":4678,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/4673\/revisions\/4678"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}