• gateway 集成 nacos 实现动态路由


    gateway 集成 nacos 实现动态路由,前几篇单独分析gateway网关时,仅介绍了静态路由的原理和使用,今天我们先分析动态路由,然后介绍一下两者的区别和优缺点。

    一、动态路由实战分析:

    1、构建一个springboot 服务,去掉web相关的jar:

    1. <dependency>
    2. <groupId>org.springframework.boot</groupId>
    3. <artifactId>spring-boot-starter-web</artifactId>
    4. </dependency>

    加上:

    1. <dependency>
    2. <groupId>org.springframework.boot</groupId>
    3. <artifactId>spring-boot-starter-webflux</artifactId>
    4. </dependency>

     引入相关核心jar

    1. artifactId>common-gateway</artifactId>
    2. <packaging>jar</packaging>
    3. <version>1.0-SNAPSHOT</version>
    4. <name>common-gateway</name>
    5. <description>网关服务</description>
    6. <properties>
    7. <java.version>1.8</java.version>
    8. </properties>
    9. <dependencies>
    10. <dependency>
    11. <groupId>org.springframework.cloud</groupId>
    12. <artifactId>spring-cloud-starter-gateway</artifactId>
    13. </dependency>
    14. <!-- springboot web -->
    15. <dependency>
    16. <groupId>org.springframework.boot</groupId>
    17. <artifactId>spring-boot-starter-webflux</artifactId>
    18. </dependency>
    19. <dependency>
    20. <groupId>com.alibaba.cloud</groupId>
    21. <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    22. </dependency>
    23. <dependency>
    24. <groupId>com.alibaba.cloud</groupId>
    25. <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
    26. </dependency>
    27. <dependency>
    28. <groupId>org.springframework.cloud</groupId>
    29. <artifactId>spring-cloud-starter-openfeign</artifactId>
    30. </dependency>
    31. <dependency>
    32. <groupId>org.springframework.cloud</groupId>
    33. <artifactId>spring-cloud-loadbalancer</artifactId>
    34. </dependency>
    35. <dependency>
    36. <groupId>ch.qos.logback</groupId>
    37. <artifactId>logback-core</artifactId>
    38. </dependency>
    39. <dependency>
    40. <groupId>ch.qos.logback</groupId>
    41. <artifactId>logback-classic</artifactId>
    42. </dependency>
    43. </dependencies>

    2、项目中yaml配置:

    1. spring:
    2. main:
    3. web-application-type: reactive
    4. application:
    5. name: @project.artifactId@
    6. version: @project.version@
    7. cloud:
    8. nacos:
    9. config:
    10. namespace: common
    11. file-extension: yaml
    12. shared-configs:
    13. - data-id: common-shared-config.yaml
    14. group: common
    15. refresh: true
    16. loggingRoot: logs

    3、idea中nacos环境配置:

  • 相关阅读:
    各类索引-尚
    Python编程 集合
    TOP-K问题
    接口(interface)
    Nacos 注册中心、配置文件中心的常用配置(springcloud)
    jpa 连接sqlserver 发布tomcat报错 SunJSSE
    【分类网络】AlexNet
    javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection
    【前端】CSS:border
    system V共享内存【Linux】
  • 原文地址:https://blog.csdn.net/nandao158/article/details/126748032