zoukankan      html  css  js  c++  java
  • 搭建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等等

  • 相关阅读:
    底部导航栏
    判断手机是否连接网络
    瀑布流(圆角,卡片效果)
    列表卡片效果
    使用Glide改变图片的圆角
    条形码EAN-13码和EAN-8码的原理
    自定义底部弹窗
    【代码笔记】Java常识性基础补充(一)——赋值运算符、逻辑运算符、三元运算符、Scanner类、键盘输入、Random类、随机数
    【Android】9.0活动的生命周期(二)——实际代码演示
    【Android】8.0活动的生命周期(一)——理论知识、活动的启动方式
  • 原文地址:https://www.cnblogs.com/chenmengmeng/p/12576284.html
Copyright © 2011-2022 走看看