SpringCloudGateway Nacos配置中心与注册中心,动态路由

SpringCloudGateway+Nacos 集成应用
1. 应用集成(配置中心+应用中心)

参见(SpringCloud+Nacos 配置中心与注册中心应用)

2. 启动服务

在这里插入图片描述

3. API文档访问
4. 动态路由

只需要修改对应的配置文件即可,nacos会发起刷新

附录
  • 网关配置

    TIMEOUT.IN.MILLISECONDS: 60000
    hystrix:
    command:
    fallbackcmd:
    execution:
    isolation:
    thread:
    timeoutInMilliseconds: ${TIMEOUT.IN.MILLISECONDS}
    strategy: SEMAPHORE
    semaphore:
    maxConcurrentRequests: 1000
    default:
    execution:
    isolation:
    thread:
    timeoutInMilliseconds: ${TIMEOUT.IN.MILLISECONDS}
    strategy: SEMAPHORE
    semaphore:
    maxConcurrentRequests: 1000
    spring:
    profiles: dev

    链路追踪

    zipkin:
    # 可使用服务名称
    base-url: http://localhost:9411/
    # 没有注册到注册中心,不需要开启
    discovery-client-enabled: false
    service:
    name: ${spring.application.name}
    sender:
    type: web
    sleuth:
    sampler:
    probability: 1.0
    redis:
    password: ****
    sentinel:
    master: mymaster
    nodes: ip:26379,ip:26380
    lettuce:
    pool:
    max-active: 8
    max-idle: 8
    max-wait: -1ms
    min-idle: 0
    cloud:
    gateway:
    discovery:
    locator:
    enabled: true
    lower-case-service-id: true
    routes:
    - id: nacos-demo-test
    uri: lb://nacos-demo-test
    predicates:
    - Path= /api/t/**
    filters:
    - StripPrefix= 2
    - id: nacos-demo-local
    uri: lb://nacos-demo-local
    predicates:
    - Path= /api/local/**
    filters:
    - StripPrefix= 2
    - id: nacos-demo-non
    uri: lb://nacos-demo-non
    predicates:
    - Path= /api/non/**
    filters:
    - StripPrefix= 2

    sonic:
    platform:
    mybatis:
    mapper-locations: classpath:/mappers/Mapper.xml
    datasource:
    jdbc-url: jdbc:mysql://
    ***:3306/zipkin?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false&allowMultiQueries=true
    username: ****
    password: ****
    driver-class: com.mysql.cj.jdbc.Driver
    min-idle: 5
    max-active: 10
    initial-size: 5
    gateway:
    services:
    nacos-demo-local: Nacos_Local服务
    nacos-demo-test: Nacos_Test服务
    nacos-demo-non: Nacos_不存在的服务

  • 应用中配置

    此处为自定义,配置中心和注册中心共同属性,下文引入即可

    nacos:
    group: demo

    配置中心地址

    server-addr: http://127.0.0.1:9948

    命名空间

    namespace: dev
    service.port: 9999

    spring:
    profiles:
    active: dev
    application:
    name: nacos-demo-gateway
    cloud:
    nacos:
    server-addr: ${nacos.server-addr}
    config:
    # nacos 配置中心服务地址 nginx 代理的地址
    # 默认 ${spring.cloud.nacos.server-addr}
    # server-addr:
    file-extension: yaml
    prefix: ${spring.application.name}
    # dataID p r e f i x − {prefix}- prefix{spring.profiles.active}.${file-extension}
    # 命名空间 默认 public
    namespace: ${nacos.namespace}
    # 配置组 默认 DEFAULT_GROUP
    group: ${nacos.group}
    # 共享配置(公共配置)
    shared-configs:
    - data-id: nacos-demo.yaml
    # 可自定义
    group: ${nacos.group}
    refresh: true

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值