配置动态路由
配置动态路由,即我们使用服务注册的功能绑定微服务的服务名,这样不论支付模块的拓展还是消减都不会影响消费端的代码代码。
- 第一种: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