0
点赞
收藏
分享

微信扫一扫

SpringCloud-Gateway配置动态路由(Day8)

穿裙子的程序员 2022-04-27 阅读 54
java后端

配置动态路由

配置动态路由,即我们使用服务注册的功能绑定微服务的服务名,这样不论支付模块的拓展还是消减都不会影响消费端的代码代码。

  • 第一种:websocket方式 :
    uri: ws://localhost:8001/
  • 第二种:http方式 :
    uri: http://localhost:8001/
  • 第三种:lb(注册中心中服务名字)方式 :
    uri: lb://cloud-payment-service

设置服务网关的yml

server:
  port: 9527

spring:
  application:
    name: cloud-gateway-service
  cloud:
    gateway:
      routes:
        - id: getPaymentById
          uri: lb://CLOUD-PAYMENT-SERVICE
          predicates:
            - Path=/payment/get/**

eureka:
  client: #服务提供者provider注册进eureka服务列表内
    service-url:
      register-with-eureka: true
      fetch-registry: true
      defaultZone: http://127.0.0.1:7001/eureka

运行截图

在这里插入图片描述

举报

相关推荐

0 条评论