搭建eureka,gateway,admin,redis,docker系列一ga…

2020-03-26 16:15:45来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

搭建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
@EnableZuulProxy
public 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: 8888

spring:
  application:
    name: dxtgateway
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
          lowerCaseServiceId: true
ribbon:
  ReadTimeout: 60000
  ConnectTimeout: 60000
#  cloud:
#    config:
#      profile: dev
#      label: master
#      discovery:
#        enabled: true
#        service-id: spring-cloud-config
eureka:
  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/health
management:
  endpoints:
    web:
      exposure:
        include: '*'
    health:
      show-details: ALWAYS
zuul:
  routes:
    xxapi:
      path: /xxapi/**
      serviceId: xxapi
    xxyapi:
      path: /xxyapi/**
      serviceId:xxyapi 
  ignored-patterns:
  

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


原文链接:https://www.cnblogs.com/chenmengmeng/p/12576284.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:面试刷题14:介绍一下你工作中用到的设计模式?

下一篇:SpringBoot自动装配原理