网关的路径解析和负载均衡

路径解析

1.指定路径
server:
  port: 8088

spring:
  application:
    name: GATEWAY
  cloud:
    consul:
      host: localhost
      port: 8500
    gateway:
      routes:
        - id: category_route							# 指定路由唯一标识
          uri: http://localhost:8085 # 指定路由服务的地址
          predicates:
            - Path=/category,/list				  # 指定路由规则

        - id: product_route
          uri: http://localhost:8084
          predicates:
            - Path=/product,/list

2.通配符
server:
  port: 8088

spring:
  application:
    name: GATEWAY
  cloud:
    consul:
      host: localhost
      port: 8500
    gateway:
      routes:
        - id: category_route							# 指定路由唯一标识
          uri: http://localhost:8085 # 指定路由服务的地址
          predicates:
            - Path=/category/**					  # 指定路由规则

        - id: product_route
          uri: http://localhost:8084
          predicates:
            - Path=/product/**

负载均衡

server:
  port: 8088

spring:
  application:
    name: GATEWAY
  cloud:
    consul:
      host: localhost
      port: 8500
    gateway:
      routes:
        - id: category_route		# 指定路由唯一标识
          uri: lb://CATEGORY   # 指定路由服务的地址
          predicates:
            - Path=/category		 # 指定路由规则

        - id: product_route
          uri: lb://PRODUCT    #默认轮询的方式  lb => loadbalance  格式: lb://服务名
          predicates:
            - Path=/product

posted @ 2021-10-01 21:27  code-G  阅读(199)  评论(0编辑  收藏  举报