In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "the methods and steps of building spring cloud alibaba micro-service GetWay". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the methods and steps of building spring cloud alibaba microservice GetWay".
What is 1.GateWay?
Overview
A very important component in the Cloud family bucket is the gateway, which is the Zuul gateway used in version 1.x
But in the 2.x version, the upgrade of zuul has been skipping tickets, and SpringCloud finally developed a gateway to replace Zuul, that is, SpringCloud Gateway- sentence: gateway is a replacement for the original zuul1.x version.
Gateway is an API gateway service built on top of the Spring ecosystem, based on technologies such as Spring 5je Spring Boot 2 and Project Reactor.
Gateway aims to provide a simple and effective way to route API, as well as some powerful filter functions, such as circuit breaker, current limit, retry, etc.
SpringCloud Gateway is a new project of SpringCloud, which is a gateway based on Spring 5.0+Spring Boot 2.0 and Project Reactor. It aims to provide a simple and effective unified API route management method for micro-service architecture.
SpringCloud Gateway, as a gateway in the SpringCloud ecosystem, aims to replace Zuul. In versions above SpringCloud 2.0, there is no integration with the latest high-performance version of Zul 2.0, and it is still the old version of Zuul 1.x non-Reactor mode. In order to improve the performance of the gateway, SpringCloud Gateway is implemented based on the WebFlux framework, while the bottom layer of the WebFlux framework uses the high-performance Reactor mode communication framework Netty.
The goal of Spring Cloud Gateway provides unified routing and the Filter chain-based approach provides the basic functions of the gateway, such as security, monitoring / metrics, and flow restriction.
Action
Directional agent
Authentication
Flow control
Fuse break
Log monitoring
The location of the gateway in the microservice architecture
two。 Configure Getway to create a subproject: cloud-getway-getway9527
The 3.pom file is added as follows:
Org.springframework.cloud spring-cloud-starter-gateway com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery com.yxw.springcloud cloud-api-commons ${project.version} org.springframework.boot spring-boot-devtools runtime true org.projectlombok lombok True org.springframework.boot spring-boot-starter-test test
The 4.yml file is added as follows:
Server: port: 9527spring: application:name: cloud-gateway cloud:nacos: discovery:server-addr: localhost:8848gateway: discovery:locator: enabled: true # enables the function of dynamically creating routes from the registry, using micro-service names to route routes:-id: payment_routh # payment_routh # routing ID, which has no fixed rules but requires unique Easy matching service name uri: http://localhost:8001 # matching service routing address # uri: lb://cloud-provider-service # matching service routing address predicates:-Path=/payment/get/** # asserting, path matching routing-id: payment_routh3 # payment_routh # routing ID There are no fixed rules but are required to be unique. It is easy to match with the service name uri: http://localhost:8001 # after matching the routing address of the service # uri: lb://cloud-provider-service # the routing address of the service provided after matching predicates:-Path=/payment/lb/** # asserts that the route will be routed if the path matches
5. Startup class:
@ SpringBootApplication@EnableDiscoveryClientpublic class GetwayApplication {public static void main (String [] args) {SpringApplication.run (GetwayApplication.class,args);}}
6. Start the service and visit: http://localhost:9527/payment/get/1
Configure dynamic routin
In yml, the modification is as follows:
Server: port: 9527spring: application:name: cloud-gateway cloud:nacos: discovery:server-addr: localhost:8848gateway: discovery:locator: enabled: true # enables the function of dynamically creating routes from the registry, using micro-service names to route routes:-id: payment_routh # payment_routh # routing ID, which has no fixed rules but requires unique Easy matching service name # uri: http://localhost:8001 # matching service routing address uri: lb://cloud-provider-service # matching service routing address predicates:-Path=/payment/get/** # asserting that the route-id: payment_routh3 # payment_routh # routing is performed with a path match There are no fixed rules but are required to be unique, easy to match with the service name # uri: http://localhost:8001 # matching the routing address of the service uri: lb://cloud-provider-service # matching the routing address of the service predicates:-Path=/payment/lb/** # asserts that the route will be routed if the path matches
Visit again: http://localhost:9527/payment/get/1
It should be noted that the protocol of uri is lb, which means that the load balancing feature of Gateway is enabled.
Lb://serviceName is a load balancer uri that spring cloud gateway automatically creates for us in the micro-service.
At this point, I believe you have a deeper understanding of "the methods and steps of building spring cloud alibaba micro-service GetWay". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.