1、getway.yml配置
server: port: 9527 spring: application: name: cloud-gateway cloud: gateway: routes: - id: payment_routh #payment_route #路由的ID,没有固定规则但要求唯一,建议配合服务名 #uri: http://localhost:8001 #匹配后提供服务的路由地址 uri: lb://springcloud-product-providers predicates: - Path=/product/provider/get/** # 断言,路径相匹配的进行路由 #- After=2021-05-31T10:02:46.918+08:00[Asia/Shanghai] # 断言,路径相匹配的进行路由 #- Before=2020-02-05T15:10:03.685+08:00[Asia/Shanghai] # 断言,路径相匹配的进行路由 #- Between=2020-02-02T17:45:06.206+08:00[Asia/Shanghai],2020-03-25T18:59:06.206+08:00[Asia/Shanghai] - Cookie=username,zzyy - Header=X-Request-Id, \d+ # 请求头要有X-Request-Id属性并且值为整数的正则表达式 - Host=**wen.com #- Method=GET - Query=id, \d+ # 要有参数名username并且值还要是整数才能路由 - id: payment_routh2 #payment_route #路由的ID,没有固定规则但要求唯一,建议配合服务名 #uri: http://localhost:8001 #匹配后提供服务的路由地址 uri: lb://springcloud-product-providers predicates: - Path=/provider/discovery/** # 断言,路径相匹配的进行路由 eureka: instance: hostname: cloud-gateway-service client: #服务提供者provider注册进eureka服务列表内 service-url: register-with-eureka: true fetch-registry: true defaultZone: http://eureka7001.com:7001/eureka
2、curl的拼接
curl http://localhost:9527/product/provider/get/1?id=2 -H "X-Request-Id:1" -H "Host:xiangwen.com" --cookie "username=zzyy"
3、结果