打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
搭建eureka,gateway,admin,redis,docker系列一gateway

1.概述

Spring cloud gateway是spring官方基于Spring 5.0、Spring Boot2.0和Project Reactor等技术开发的网关,Spring Cloud Gateway旨在为微服务架构提供简单、有效和统一的API路由管理方式,Spring Cloud Gateway作为Spring Cloud生态系统中的网关,目标是替代Netflix Zuul,其不仅提供统一的路由方式,并且还基于Filer链的方式提供了网关基本的功能,例如:安全、监控/埋点、限流等。
创建一个空的module项目

添加pom依赖

<dependencies>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>            <exclusions>                <exclusion>                    <groupId>org.slf4j</groupId>                    <artifactId>log4j-over-slf4j</artifactId>                </exclusion>            </exclusions>        </dependency>         <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>            <version>2.1.2.RELEASE</version>        </dependency>        <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>            <version>2.1.2.RELEASE</version>        </dependency>    </dependencies>    <build>        <plugins>            <plugin>                <groupId>org.springframework.boot</groupId>                <artifactId>spring-boot-maven-plugin</artifactId>            </plugin>        </plugins>    </build>

创建一个启动类

@SpringBootApplication@ServletComponentScan@EnableZuulProxypublic class GatewayApplication extends SpringBootServletInitializer {    public static void main(String[] args) {        SpringApplication.run(GatewayApplication.class, args);    }    @Override    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {        return application.sources(GatewayApplication.class);    }}

配置文件

server:  port: 8888spring:  application:    name: dxtgateway  cloud:    gateway:      discovery:        locator:          enabled: true          lowerCaseServiceId: trueribbon:  ReadTimeout: 60000  ConnectTimeout: 60000#  cloud:#    config:#      profile: dev#      label: master#      discovery:#        enabled: true#        service-id: spring-cloud-configeureka:  client:    service-url:      defaultZone: http://127.0.0.1:8761/eureka  instance:    status-page-url-path: /actuator/info    metadata-map.management:      context-path: /actuator    health-check-url-path: /actuator/healthmanagement:  endpoints:    web:      exposure:        include: '*'    health:      show-details: ALWAYSzuul:  routes:    xxapi:      path: /xxapi/**      serviceId: xxapi    xxyapi:      path: /xxyapi/**      serviceId:xxyapi   ignored-patterns:  

简单的gateway就搭建好了,这时候先启动eureka,在启动gateway就可以看到 gateway在注册中心出现了,Nginx请求代理到gateway上,gateway通过实例分开, xxapi,xxyapi等等

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
SpringCloud微服务部署
SpringCloud之Zuul
IntelliJ IDEA创建多服务模块的Spring Cloud微服务项目
使用Spring Cloud Eureka实现服务注册与发现
springcloud(第三篇)springcloud eureka 服务注册与发现
史上最简单的SpringCloud教程 | 第十三篇: 断路器聚合监控(Hystrix Turbine)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服