zoukankan      html  css  js  c++  java
  • spring cloud 学习笔记--网关zuul学习

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

    盗图

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

    添加依赖

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

    配置文件

    单纯的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/

    通过注册来实现转发

    #当请求/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
     

    3、启动类

    @SpringBootApplication
    @EnableZuulProxy
    public class GatewayServiceZuulApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(GatewayServiceZuulApplication.class, args);
        }
    }
    学习的时间不一定要特定安排
  • 相关阅读:
    c19---指针和字符串
    c18---数组和指针
    c17---指针
    c16---字符串
    c15--二位数组
    Android -- Properties使用
    四种更新UI的方法
    Android 使用开源库StickyGridHeaders来实现带sections和headers的GridView显示本地图片效果
    Android 性能优化之使用MAT分析内存泄露
    android中PopupMenu的使用
  • 原文地址:https://www.cnblogs.com/zhongzheng123/p/8394767.html
Copyright © 2011-2022 走看看