Spring Cloud Learning Notes-Gateway Zuul Learning

Source: Internet
Author: User
Tags url forwarding

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.