Set up eureka,gateway,admin,redis,docker series of gateways

1. overview

Spring Cloud gateway is an official gateway developed by spring based on Spring 5.0, Spring Boot2.0, Project Reactor and other technologies. Spring Cloud gateway aims to provide a simple, effective and unified API route management method for microservice architecture. As a gateway in Spring Cloud health system, Spring Cloud gateway aims to replace Netflix Zuul, which not only provides a unified routing mode, but also provides the basic functions of the gateway based on the Filer chain, such as: security, monitoring / burying point, current limiting, etc.
Create an empty module project

Add pom dependency

<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>

Create a startup class

@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);
    }
}

configuration file

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:
  

The simple gateway is set up. At this time, start eureka first. When you start the gateway, you can see that the gateway appears in the registration center. The Nginx request is proxied to the gateway. The gateway is separated by instances, such as xxapi,xxyapi, etc

Tags: Java Spring log4j Maven Nginx

Posted on Thu, 26 Mar 2020 10:14:27 -0400 by texmansru47