spring cloud 学习笔记--网关zuul学习

  微服务是多个服务共同完成一件事情,那么“一致对外”就颇有必要,就像咱们去买面包,不可能先去找农民买小麦,再。。。。spring

盗图api

spring cloud 引入zuul方式来实现这一功能服务器

添加依赖app

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>

 

配置文件微服务

单纯的url转发url

#这里的配置表示,访问/app/** 直接重定向到(url路径后面是相同的,zuul只是作了转发)
http://127.0.0.1:8090/**
zuul.routes.baidu.path=/app/**
zuul.routes.baidu.url=http://127.0.0.1:8090/

经过注册来实现转发spa

#当请求/api/**会直接交给listOfServers配置的服务器处理  
#当stripPrefix=true的时候 (http://127.0.0.1:8181/api/user/list -> http://192.168.1.100:8080/user/list)  
#当stripPrefix=false的时候(http://127.0.0.1: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
 

三、启动类code

@SpringBootApplication
@EnableZuulProxy
public class GatewayServiceZuulApplication {

    public static void main(String[] args) {
        SpringApplication.run(GatewayServiceZuulApplication.class, args);
    }
}
相关文章
相关标签/搜索