MicroServices are multiple services to accomplish one thing together, then "consistent with the external" is very necessary, like we go to buy bread, it is impossible to find farmers to buy wheat, then ....
Theft map
Spring Cloud introduces a Zuul approach to this feature
Add dependency
< Dependency > < groupId >org.springframework.cloud</groupId> < Artifactid>spring-cloud-starter-zuul</artifactid> </ Dependency >
Configuration file
Simple URL Forwarding
#这里的配置表示, Access/app/** Direct redirect to (after the URL path is the same, Zuul just did the forwarding)http://127.0.0.1: 8090/** Zuul.routes.baidu.path=/app/**zuul.routes.baidu.url=http://127.0.0.1: 8090/
To implement forwarding by registering
#当请求/api/** will be delivered directly to the listofservers configured server processing # When Stripprefix=true ( http://127.0.0.1 Span style= "COLOR: #008000" >:8181/ API /user/list, http://192.168.1.100 :8080/user/list) # When Stripprefix=false ( http://127.0.0.1 Span style= "COLOR: #008000" >:8181/api/user/list http://192.168.1.100 :8080/api/user/list) zuul.routes.api.path=/api/** Zuul.routes.api.stripprefix=false api.ribbon.listofservers=192.168.1.100:8080,192.168.1.101:8080,192.168.1.102:8080
#zuul.routes.api-a.path=/producer/**#zuul.routes.api-a.serviceId=spring-cloud-producer
serviceId服务的id
3. Startup class
@SpringBootApplication @enablezuulproxy Public class gatewayservicezuulapplication { publicstaticvoid main (string[] args) { springapplication.run (gatewayservicezuulapplication. class , args);} }
Spring Cloud Learning Note-Gateway Zuul learning