In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "Integrated Analysis of spring cloud apigateway and consul". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Spring cloud gateway integrated consul
Engineering pom.xml introduces dependencies
Org.springframework.cloud spring-cloud-starter-gateway org.springframework.cloud spring-cloud-starter-consul-discovery org.springframework.boot spring-boot-starter-actuator
Add the annotation @ EnableDiscoveryClient to the startup class
Add gateway configuration to the configuration
# tomcat configuration server: port: 500 clients service name spring: application: name: api-gatewaycloud: # consul server address consul: host: localhost port: 8500 discovery: # Health check must be configured with spring-boot-starter-actuator to use health-check-path: / actuator/health health-check-interval: 10s# gateway configuration gateway: filter: remove-non-proxy-headers: Headers:-dummy discovery: locator: enabled: true routes:-id: orderApi # consul lb-> load balance uri: lb://order-server predicates:-Path=/api/order/** # filter the service name lb-> load balance uri obtained by / orderApi filters:-StripPrefix=1-id: commodityApi # consul in the path Lb://commodity-server predicates:-Path=/api/commodity/** # filter to remove / api filters:-StripPrefix=1 from the path
Gateway comes with current-limiting function and needs redis dependency support.
Org.springframework.boot spring-boot-starter-data-redis-reactive
Configuration needs to be modified synchronously
The service name obtained by routes:- id: payApi# consul lb-> load balance uri: lb://pay-server predicates:-Path=/api/pay/**# filtering removes the / orderApi filters:-StripPrefix=1# flow limit operation in the path-name: RequestRateLimiter args: # how many requests per second are allowed to be processed by the user redis-rate-limiter.replenishRate: 10 # capacity of token bucket Maximum number of requests allowed to be completed in one second redis-rate-limiter.burstCapacity: 20 # ip current limit bean key-resolver: "# {@ ipKeyResolver}"
Injection of custom current limiting types (for ip current limiting)
@ Beanpublic KeyResolver ipKeyResolver () {return new KeyResolver () {@ Override public Mono resolve (final ServerWebExchange exchange) {return Mono.just (exchange.getRequest (). GetRemoteAddress (). GetHostName ());};}
In the process of integration, there is a deep pit, that is, when the current limit operation is configured, the local redis is not started, resulting in the helath check of consul being down all the time.
To solve the health check problem, you need to open the detailed return of health check, and calling the / actuator/health interface again will return the details.
This is the end of management: endpoint: health: show-details: always "spring cloud apigateway and consul Integration Analysis". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.