zoukankan      html  css  js  c++  java
  • springcloud-gateway网关(动态路由以及负载均衡转发配置)

    1.依赖

            <!--引入gateway网关依赖-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-gateway</artifactId>
            </dependency>
    
            <!--consul 依赖-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-consul-discovery</artifactId>
            </dependency>
    
            <!--监控检查依赖-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
    

     2.启动注解

    @SpringBootApplication
    @EnableDiscoveryClient
    public class GatewayApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(GatewayApplication.class, args);
        }
    
    }
    

     3.配置文件

    server:
      port: 8888
    
    spring:
      application:
        name: gateway
      cloud:
        consul:
          port: 8500
          host: localhost
          discovery:
            service-name: ${spring.application.name}
        gateway:
          routes:
            - id: user_route
              uri: lb://userservices    # lb: 使用负载均衡策略   userservices代表注册中心的具体服务名
              predicates:
                - Path=/user/**
            - id: product_route
              uri: lb://productservices    # lb: 使用负载均衡策略   productservices代表注册中心的具体服务名
              predicates:
                - Path=/product/**
          discovery:
            locator:
              enabled: true   #开启根据服务名动态获取路由地址
    
  • 相关阅读:
    Python3.x和Python2.x的区别
    python 列表 元组 字典
    Wireshark TCP报文到达确认(ACK)机制
    Wireshark Tcp三次握手
    Python Vim配置 Win7x64
    Workstation guest fails to restart or resume
    python 枚举目录下所有子目录和文件,输出列表
    Python按行读文件 高级
    python 注释
    十一、设备初始化(ADK4.0)
  • 原文地址:https://www.cnblogs.com/taohaijun/p/13489669.html
Copyright © 2011-2022 走看看