zoukankan      html  css  js  c++  java
  • getway网关路由配置的两种方式

    1. yml

    server:
      port: 9527
    spring:
      application:
        name: cloud-gateway
      cloud:
        gateway:
          discovery:
            locator:
              enabled: true  #开启注册中心路由功能
          #          lower-case-service-id: true
          routes:
            - id: payment_routh
              #          uri: http://localhost:8001  #单机
              uri: lb://cloud-payment-service #此处如果有问题,请注意依赖spring-cloud-starter-netflix-eureka-client依赖不能错
              predicates:
                - Path=/payment/get/**
            - id: payment_routh2
              #          uri: http://localhost:8001
              uri: lb://cloud-payment-service
              predicates:
                - Path=/payment/lb/**
    eureka:
      instance:
        hostname: cloud-gateway-service
      client:
        service-url:
          register-with-eureka: true
          fetch-registry: true
          defaultZone: http://eureka7001.com:7001/eureka #,http://eureka7002.com:7002/eureka
    #logging:
    #  level:
    #    root: debug
    

    2.代码中注入RouteLocator的Bean

    @Configuration
    public class GateWayConfig {
        @Bean
        public RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder){
    
            RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
            routes.route("path_route"
                    , r->r.path("/guonei").uri("http://news.baidu.com/guonei"))
                    .build();
            routes.route("path_route2",r->r.path("/guoji").uri("http://news.baidu.com/guonei")).build();
            return routes.build();
        }
    }
    不经一番彻骨寒,哪有梅花扑鼻香?
  • 相关阅读:
    Python 面向对象
    pymysql增删改查
    pymysql简单链接示例
    mysql权限管理
    mysql五补充部分:SQL逻辑查询语句执行顺序
    mysql安装与基本管理
    mysql索引原理与慢查询优化2
    ftp 服务
    Linux 并发链接数
    Linux
  • 原文地址:https://www.cnblogs.com/zongyao/p/13831108.html
Copyright © 2011-2022 走看看