SpringCloud微服务小白也能搭(Hoxton.SR8)(七)Gateway|服务网关

SpringCloud组件之网关Spring Cloud Gateway(Hoxton版本) 1.Spring Cloud Gateway简介 Spring Cloud Gateway 为 SpringBoot 应用提供了API网关支持,具有强大的智能路由与过滤器功能,本文将对其用法进行详细介绍。   Spring Cloud Gateway是SpringCloud新推出的网关框架,比较于上一代Zuul,功能和性能有很大的提升。Zuul1.x采用的是阻塞多线程方式,也就是一个线程处理一个连接请求,高并发情况下性能较差,即使是Zuul2.x虽然做到了非阻塞,但是面对连续跳票,看起来Zuul要被抛弃了 阅读详情

简单上手,直接照搬,就可搭建微服务(Hoxton.SR8) 2020.8.28发布,SpringCloud搭建的文章正在整理,干货不要错过哦

摘要

Spring Cloud Gateway 为 SpringBoot 应用提供了API网关支持,具有强大的智能路由与过滤器功能。Gateway是在Spring生态系统之上构建的API网关服务,基于Spring 5,Spring Boot 2和 Project Reactor等技术。Gateway旨在提供一种简单而有效的方式来对API进行路由,以及提供一些强大的过滤器功能, 例如:熔断、限流、重试等。

Spring Cloud Gateway 具有如下特性:

  • 基于Spring Framework 5, Project Reactor 和 Spring Boot 2.0 进行构建;
  • 动态路由:能够匹配任何请求属性;
  • 可以对路由指定 Predicate(断言)和 Filter(过滤器);
  • 集成Hystrix的断路器功能;
  • 集成 Spring Cloud 服务发现功能;
  • 易于编写的 Predicate(断言)和 Filter(过滤器);
  • 请求限流功能;
  • 支持路径重写。

配置组成

  • Route(路由):路由是构建网关的基本模块,它由ID,目标URI,一系列的断言和过滤器组成,如果断言为true则匹配该路由;
  • Predicate(断言):指的是Java 8 的 Function Predicate。 输入类型是Spring框架中的ServerWebExchange。 这使开发人员可以匹配HTTP请求中的所有内容,例如请求头或请求参数。如果请求与断言相匹配,则进行路由;
  • Filter(过滤器):指的是Spring框架中GatewayFilter的实例,使用过滤器,可以在请求被路由前后对请求进行修改。

1.创建一个api-gateway模块

 

  

2 单独使用gateway

2.1 pom.xml新增 gateway 依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>cloud-hoxton-sr8</artifactId>
        <groupId>com.zqh.www</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>api-gateway</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis-reactive</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

2.2 启动类

package com.zqh.www;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;

@SpringBootApplication
public class ApiGatewayApplication {

    private final static Logger logger = LoggerFactory.getLogger(ApiGatewayApplication.class);

    public static void main(String[] args) {
        Environment env = SpringApplication.run(ApiGatewayApplication.class, args).getEnvironment();
        logger.info(
                "\n----------------------------------------------------------\n\t"
                        + "Application '{}' is running! Access URLs:\n\t"
                        + "Local: \t\thttp://localhost:{}{}"
                        + "\n----------------------------------------------------------",
                env.getProperty("spring.application.name"), env.getProperty("server.port"),
                env.getProperty("server.servlet.context-path") != null ? env.getProperty("server.servlet.context-path") : "");
    }
}

2.3 yml配置

server:
  port: 8093

service-url:
  user-service: http://localhost:8084

spring:
  application:
    name: api-gateway
  cloud:
    gateway:
      routes:
        # 路由的ID
        - id: user-service
          # 匹配后路由地址
          uri: ${service-url.user-service}
          predicates:
            # 发送指定路径的请求会匹配该路由。
            - Path=/api/user/*
#            # 发送指定方法的请求会匹配该路由。
#            - Method=GET
#            # 在指定时间之后的请求会匹配该路由。
#            - After=2020-10-20T12:00:00+08:00[Asia/Shanghai]
#            # 在指定时间之前的请求会匹配该路由。
#            - Before=2020-10-20T12:00:00+08:00[Asia/Shanghai]
#            # 在指定时间区间内的请求会匹配该路由。
#            - Between=2020-10-20T12:00:00+08:00[Asia/Shanghai], 2020-10-30T12:00:00+08:00[Asia/Shanghai]
#            # 带有指定Cookie的请求会匹配该路由
#            - Cookie=username,jourwon
#            # 带有指定请求头的请求会匹配该路由。
#            - Header=auth
#            #带有指定Host的请求会匹配该路由。
#            - Host=www.zqh.com
#            # 从指定远程地址发起的请求可以匹配该路由。
#            - RemoteAddr=192.168.1.1/24
          filters:
#            - AddRequestParameter=username,z
#            - StripPrefix=1
#            - PrefixPath=/api

logging:
  level:
    org.springframework.cloud.gateway: debug

2.4 predicates - 测试用例

注意:如果存在多个条件,则需要所有条件满足才会匹配到相关的路由

2.4.1 predicates - Path

描述:发送匹配路径或的请求会匹配该路由。
yml配置:- Path=/api/user/*
接口请求:http://localhost:8093/api/user/getUserList
相当于:http://localhost:8084/api/user/getUserList

2.4.2 predicates - Method

描述:发送指定方法的请求会匹配该路由。
接口请求:http://localhost:8093/api/user/getUserList

  

2.4.3 predicates - After

描述:在指定时间之后的请求会匹配该路由。
接口请求:http://localhost:8093/api/user/getUserList

  

2.4.4 predicates - Before

描述:在指定时间之前的请求会匹配该路由。

2.4.5 predicates - Between

描述:在指定时间区间内的请求会匹配该路由。

2.4.6 predicates - Cookie

描述:带有指定Cookie的请求会匹配该路由。
配置:

predicates:
    # 带有指定Cookie的请求会匹配该路由
    - Cookie=username,z

接口请求:

2.4.7 predicates - Header

描述:带有指定请求头的请求会匹配该路由。
设置:

predicates:
    # 带有指定请求头的请求会匹配该路由。
    - Header=auth

接口请求:
 

2.4.8 predicates - Host

描述:带有指定Host的请求会匹配该路由。
设置:

predicates:
    #带有指定Host的请求会匹配该路由。
    - Host=www.zqh.com

2.4.9 predicates - RemoteAddr

描述:从指定路径的请求会匹配该路由。
设置:

predicates:
    #从指定远程地址发起的请求可以匹配该路由。
    - RemoteAddr=192.168.0.100

2.5 filters - 测试用例

2.5.1 filters - AddRequestParameter

描述:会对GET请求添加请求参数
配置:

service-url:
  user-service: http://localhost:8084
spring:
  application:
    name: api-gateway
  cloud:
    gateway:
      routes:
        # 路由的ID
        - id: user-service
          # 匹配后路由地址
          uri: ${service-url.user-service}
          predicates:
            # 发送指定路径的请求会匹配该路由。
            - Path=/api/user/*
          filters:
            - AddRequestParameter=username,z

请求:http://localhost:8093/api/user/getUserList
相当于:http://localhost:8084/api/user/getUserList?username=z

2.5.2 filters - StripPrefix

描述:会把开头的请求的路径去除指定位数
配置:

service-url:
  user-service: http://localhost:8084
spring:
  application:
    name: api-gateway
  cloud:
    gateway:
      routes:
        # 路由的ID
        - id: user-service
          # 匹配后路由地址
          uri: ${service-url.user-service}
          predicates:
            # 发送指定路径的请求会匹配该路由。
            - Path=/api/user/*
          filters:
            - StripPrefix=1

请求:http://localhost:8093/api/user/getUserList
相当于:http://localhost:8084/user/getUserList

2.5.3 filters - PrefixPath

描述:会对所有GET请求添加指定路径前缀
配置:

service-url:
  user-service: http://localhost:8084
spring:
  application:
    name: api-gateway
  cloud:
    gateway:
      routes:
        # 路由的ID
        - id: user-service
          # 匹配后路由地址
          uri: ${service-url.user-service}
          predicates:
            # 发送指定路径的请求会匹配该路由。
            - Path=/user/*
          filters:
            - PrefixPath=/api

请求:http://localhost:8093/user/getUserList
相当于:http://localhost:8084/api/user/getUserList

2.5.3 filters - hystrix

描述:Hystrix 过滤器允许你将断路器功能添加到网关路由中,使你的服务免受级联故障的影响,并提供服务降级处理。
pom.xml:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>

 yml:

service-url:
  user-service: http://localhost:8084
spring:
  application:
    name: api-gateway
  cloud:
    gateway:
      routes:
        # 路由的ID
        - id: user-service
          # 匹配后路由地址
          uri: ${service-url.user-service}
          predicates:
            # 发送指定路径的请求会匹配该路由。
            - Path=/api/user/*
          filters:
            - name: Hystrix
              args:
                name: fallbackcmd
                #转发路径
                fallback-uri: forward:/fallback

controller:

package com.zqh.www.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class FallbackController {

    @GetMapping("/fallback")
    public Object fallback() {
        Map<String, Object> result = new HashMap<>();
        result.put("data", null);
        result.put("message", "Get request fallback!");
        result.put("code", 500);
        return result;
    }
}

 测试:
正常情况:                                                       服务异常:(关闭user-service服务模拟服务断开)

     

2.5.3 filters - RequestRateLimiter

描述:RequestRateLimiter 过滤器可以用于限流,使用RateLimiter实现来确定是否允许当前请求继续进行,如果请求太大默认会返回HTTP 429-状态。
pom.xml:

 <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis-reactive</artifactId>
</dependency>

yml:

service-url:
  user-service: http://localhost:8084

spring:
  application:
    name: api-gateway
  cloud:
    gateway:
      routes:
        # 路由的ID
        - id: user-service
          # 匹配后路由地址
          uri: ${service-url.user-service}
          predicates:
            # 发送指定路径的请求会匹配该路由。
            - Path=/api/user/*
          filters:
            - name: RequestRateLimiter
              args:
                # 每秒允许处理的请求数量
                redis-rate-limiter.replenishRate: 1
                # 每秒最大处理的请求数量
                redis-rate-limiter.burstCapacity: 2
                # 限流策略,对应策略的Bean
                key-resolver: "#{@ipKeyResolver}"

config:

package com.zqh.www.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

import java.util.Objects;

@Configuration
public class RedisRateLimiterConfig {

    // 如果你是采用第二个的策略,那么第一个策略的@Bean记得要注释掉,否则他会报找到2个参数
    //    @Bean
    public KeyResolver userKeyResolver() {
        return exchange -> Mono.just(Objects.requireNonNull(exchange.getRequest().getQueryParams().getFirst("username")));
    }

    @Bean
    public KeyResolver ipKeyResolver() {
        return exchange -> Mono.just(Objects.requireNonNull(exchange.getRequest().getRemoteAddress()).getHostName());
    }
}

测试:
正常情况:                                                         异常情况:在快速请求的情况下返回429
  

2.5.4 filters - Retry

描述:对路由请求进行重试的过滤器,可以根据路由请求返回的HTTP状态码来确定是否进行重试。

yml:

service-url:
  user-service: http://localhost:8084
spring:
  application:
    name: api-gateway
  cloud:
    gateway:
      routes:
        # 路由的ID
        - id: user-service
          # 匹配后路由地址
          uri: ${service-url.user-service}
          predicates:
            # 发送指定路径的请求会匹配该路由。
            - Path=/api/user/*
          filters:
            - name: Retry
              args:
                #需要进行重试的次数
                retries: 1
                #返回哪个状态码需要进行重试,返回状态码为5XX进行重试
                statuses: BAD_GATEWAY 
                backoff:
                  firstBackoff: 10ms
                  maxBackoff: 50ms
                  factor: 2
                  basedOnPreviousValue: false

测试:
正常:                                                                       异常:(在提供服务的增加一个null指针),会输出2次错误,表示重试了1次
   

3.微服务使用gateway

3.1 pom.xm依赖

<dependencies>
        <!-- 配合注册中心使用 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis-reactive</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis-reactive</artifactId>
        </dependency>
    </dependencies>

3.2 启动类

package com.zqh.www;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.core.env.Environment;

/**
 * 开启服务发现客户端
 *
 * @EnableEurekaClient只适用于Eureka作为注册中心,@EnableDiscoveryClient 可以是其他注册中心。
 */
// 如果你是启动的是alone的配置,请注释@EnableDiscoveryClient,并且注释 pom.xml 里面的 eureka-client 依赖,不然会出现链接错误
@EnableDiscoveryClient
@SpringBootApplication
public class ApiGatewayApplication {

    private final static Logger logger = LoggerFactory.getLogger(ApiGatewayApplication.class);

    public static void main(String[] args) {
        Environment env = SpringApplication.run(ApiGatewayApplication.class, args).getEnvironment();
        logger.info(
                "\n----------------------------------------------------------\n\t"
                        + "Application '{}' is running! Access URLs:\n\t"
                        + "Local: \t\thttp://localhost:{}{}"
                        + "\n----------------------------------------------------------",
                env.getProperty("spring.application.name"), env.getProperty("server.port"),
                env.getProperty("server.servlet.context-path") != null ? env.getProperty("server.servlet.context-path") : "");
    }
}

3.3 yml配置

server:
  port: 8093

eureka:
  client:
    service-url:
      #注册地址
      defaultZone: http://root:root@localhost:8081/eureka/
  #显示服务器IP加端口
  instance:
    hostname: localhost
    prefer-ip-address: true
    instance-id: ${spring.cloud.client.ip-address}:${server.port}

spring:
  application:
    name: api-gateway
  cloud:
    gateway:
      discovery:
        locator:
          #开启从注册中心动态创建路由的功能
          enabled: true
          #使用小写服务名
          lower-case-service-id: true
      routes:
        # 路由的ID
        - id: user-service
          # 在结合注册中心使用过滤器的时候,uri的协议为lb,这样才能启用Gateway的负载均衡功能。
          uri: lb://user-service
          predicates:
            # 发送指定路径的请求会匹配该路由。
            - Path=/api/user/*
#            # 发送指定方法的请求会匹配该路由。
#            - Method=GET
#            # 在指定时间之后的请求会匹配该路由。
#            - After=2020-10-20T18:00:00+08:00[Asia/Shanghai]
#            # 在指定时间之前的请求会匹配该路由。
#            - Before=2020-10-20T12:00:00+08:00[Asia/Shanghai]
#            # 在指定时间区间内的请求会匹配该路由。
#            - Between=2020-10-20T12:00:00+08:00[Asia/Shanghai], 2020-10-30T12:00:00+08:00[Asia/Shanghai]
#            # 带有指定Cookie的请求会匹配该路由
#            - Cookie=username,z
#            # 带有指定请求头的请求会匹配该路由。
#            - Header=auth
#            #带有指定Host的请求会匹配该路由。
#            - Host=www.zqh.com
#            # 从指定远程地址发起的请求可以匹配该路由。
#            - RemoteAddr=192.168.1.1/24
          filters:
            - name: Retry
              args:
                #需要进行重试的次数
                retries: 3
                #返回哪个状态码需要进行重试,返回状态码为5XX进行重试
                statuses: BAD_GATEWAY
                backoff:
                  firstBackoff: 10ms
                  maxBackoff: 50ms
                  factor: 2
                  basedOnPreviousValue: false
#            - name: RequestRateLimiter
#              args:
#                # 每秒允许处理的请求数量
#                redis-rate-limiter.replenishRate: 1
#                # 每秒最大处理的请求数量
#                redis-rate-limiter.burstCapacity: 2
#                # 限流策略,对应策略的Bean
#                key-resolver: "#{@ipKeyResolver}"
#            - name: Hystrix
#              args:
#                name: fallbackcmd
#                #转发路径
#                fallback-uri: forward:/fallback
#            - AddRequestParameter=username,z
#            - StripPrefix=1
#            - PrefixPath=/api

logging:
  level:
    org.springframework.cloud.gateway: debug

3.4 测试

4.gitee地址

源码参考

SpringCloud+Gateway+Security 搭建微服务统一认证授权(附源码) 1 概述 SpringCloud Gateway Security oauth2.0 搭建微服务统一认证授权。 项目概述: common:公用代码,实体、工具类等等… gateway:网关 uaa:用户登录认证服务 school:微服务 环境概述: SpringBoot 版本:2.3.1.RELEASE SpringCloud版本:Hoxton.SR6 SpringCloudAlibaba:2.2.1.RELEASE MybatisPlus:3.3.2 技能要求: 需要掌握SpringClou 阅读详情

相关推荐

SpringCloud系列之API Gateway开发手册(Hoxton版本)

1 什么是API网关? API网关是所有请求的入口,承载了所有的流量,API Gateway是一个门户一样,也可以说是进入系统的唯一节点。这跟面向对象设计模式中的Facet模式很像。API Gateway封装内部系统的架构,并且提供API给各个客户端。它还可能有其他功能,如授权、监控、负载均衡、缓存、请求分片和管理、静态响应处理等

Nicky's blog 6238

SpringCloud Hoxton SR8最新版,博文有点长耐心看完不说精通,至少从零搭建没问题了

SpringCloudNetflix 简介 Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems (e.g. configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, control bus, one-t

吴杰 7300

大模型面试题52:LLM如果在训练过程中loss值出现spike应该怎么办?

小白急救:停更→回滚→降LR→裁剪梯度,先保住训练不崩溃;进阶排查:查数据→查优化器→查硬件,找到spike的根因并解决;深层预防:预处理保守配置+训练中实时监控,从源头规避spike。先止损,再溯源,最后预防。

叫好与叫座虽然不是对立面,但想在同一个作品中达到双重效果很难。 1168

SpringCloud微服务小白也能搭(Hoxton.SR8)(一)Eureka|服务的注册与发现

简单上手,直接照搬,就可搭建微服务(Hoxton.SR8) 2020.8.28发布,SpringCloud搭建的文章正在整理,干货不要错过哦https://spring.io/blog/2020/08/28/spring-cloud-hoxton-sr8-has-been-released 开发工具:ideaj社区版 jar管理:maven 聚合构建 1.创建父pom项目 注意: Spring Assistant是一个插件,需要自己安装,安装教程参考 第三幅图,以前是不用强制选择的组件的,应.

itjavaee的博客 4567

UE5高斯泼溅落地全链路:从PLY导入到实时渲染的工程实践

3D高斯泼溅(3D Gaussian Splatting)正从NeRF后处理技术演进为新一代隐式几何渲染范式,其核心在于以可微椭球体替代传统三角面片,通过协方差矩阵与球谐系数实现高质量体素化渲染。该技术突破点云精度瓶颈,但与UE5现有资产管线存在根本性不兼容——静态网格导入器无法解析scale/rot/sh系数等非标顶点语义,标准光栅化管线亦无法执行高斯核采样计算。XV3DGS-UEPlugin通过自定义资产类型、StructuredBuffer GPU数据流与专用材质节点,将高斯泼溅重构为可编辑、可LOD

weixin_33692177的博客 356

F5高可用HA配置详情

F5 HA详细配置

weixin_45843944的博客 3022

SpringCloud微服务搭建(Hoxton.SR8)(二)-- springcloud gateway以及其动态路由搭建

SpringCloud微服务搭建(二)-- springcloud gateway以及其动态路由搭建一、基本的gateway项目搭建1、项目说明2、代码实现3、测试二、gateway进阶之动态路由配置1、代码实现2、测试三、源码 一、基本的gateway项目搭建 1、项目说明 这里我们不讲什么是springcloud gateway,网上类似的文章一大堆,我们直接上代码实践,这里需要用到三个项目,分别是eureka注册中心、gateway网关项目、consumer项目。 其中eureka注册中心不必说,管理

书生灬今天不吃饭的博客 773

新手网工别慌!手把手带你搞定华为OLT开局配置(从登录到业务下发全流程)

本文为新手网络工程师提供华为OLT设备开局配置的详细指南,涵盖从设备登录、基础配置到业务部署的全流程。通过实战案例和常见问题排查,帮助读者快速掌握华为OLT配置技巧,确保业务顺利开通。

weixin_33721344的博客 481

【SpringCloud+】Spring Cloud Hoxton.SR8升级到Spring Cloud 2020

由于近期项目做安全扫描,原项目中引用的Spring Cloud Hoxton.SR8,存在一些漏洞问题。也是因为Spring Cloud新组件的发布。所以打算升级到Spring Cloud 2020版本,在此记录一下一路的坎坷。Spring Cloud组件的使用,是有依赖关系。若不进行相关组件升级,会报一系列的问题。非常让人EMO。 示例在使用Spring Cloud 2020之后,官方文档介绍新版spring cloud关闭了bootstrap.xml读取。所以需要增加引用。 2.@EnableOAuth

诸葛小二的博客 1661

二阶系统的带宽(频域分析)

下面以典型I型系统为例,计算系统的开环截止频率和闭环截止频率。设I型系统为: 1:系统的开环截止频率为 2:系统的闭环截止频率 其实我们在工程整定时,把ζ = 0.707,也把系统的带宽近视看成自然震荡角频率即 (wb≈wc≈wnw_{b}\approx w_{c}\approx w_{n}wb​≈wc​≈wn​)对于二阶系统。 ...

wanrenqi的博客 2万+

AGX Orin 部署PyTorch与Torchvision 2026避坑指南

本文提供了2026年在AGX Orin开发板上部署PyTorch与Torchvision的详细避坑指南。针对ARM64架构和JetPack 6.2系统,重点解决了Python 3.10环境配置、官方wheel包安装、torchvision源码编译等关键步骤,并分享了常见问题解决方案和性能优化技巧,确保深度学习环境稳定运行。

sky77的博客 752

SpringCloud微服务小白也能搭(Hoxton.SR8)(二)Ribbon|服务消费者

Spring Cloud Netflix Ribbon 是Spring Cloud Netflix 子项目的核心组件之一,主要给服务间调用及API网关转发提供负载均衡的功能,在微服务架构中,很多服务都会部署多个,其他服务去调用该服务的时候,如何保证负载均衡是个不得不去考虑的问题。负载均衡可以增加系统的可用性和扩展性,当我们使用RestTemplate来调用其他服务时,Ribbon可以很方便的实现负载均衡功能。本文将对其用法进行详细介绍。 SpringCloud微服务小白也能搭(Hoxton.SR8)(.

itjavaee的博客 1008

从矩阵理论角度理解偏最小二乘回归,以及在脑科学中(脑影像与行为、基因表达的关系)的应用举例

偏最小二乘法 (PLS) 是一种多元数据驱动的统计技术,旨在提取表示最大大脑行为关联的潜在变量(或潜在成分 latent components [LC])。

从事脑科学核磁共振方法学研究,在Nature communications等权威期刊发表研究论文,熟练掌握磁共振处理方法和统计学方法,欢迎大家和我交流。 975

SpringCloud(Hoxton SR6)微服务工具集学习笔记

版本: Hoxton SR6

weixin_43711204的博客 2467

CDR插件开发之CPG插件004 - 认识VGCore并编译生成你的第一个CPG文件

上篇文章中,讲到了使用VS2019编译CDR类型库 VGCoreAuto.tlb,编译后得到了vgcoreauto.tlh和vgcoreauto.tli两个文件。本文将对这两个文件说明,并演示通过标准的libid形式来导入CDR类型库,在这个过程中,穿插一些VS2019的使用技巧(删除目录、复制工程、打开项目或解决方案、修改解决方案名称、修改项目名称等),使读者循序渐进,逐步提高对VS2019工具的熟练程度,最后通过修改项目属性配置,生成第一个CPG文件。

Zebe 2984

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

SpringCloud微服务小白也能搭(Hoxton.SR8)(六)Zuul|服务网关

简单上手,直接照搬,就可搭建微服务(Hoxton.SR8) 2020.8.28发布,SpringCloud搭建的文章正在整理,干货不要错过哦 SpringCloud微服务小白也能搭(Hoxton.SR8)(一)Eureka|服务的注册与发现 SpringCloud微服务小白也能搭(Hoxton.SR8)(二)Ribbon|服务消费者 SpringCloud微服务小白也能搭(Hoxton.SR8)(三)Feign|服务消费者 SpringCloud微服务小白也能搭(Ho.

itjavaee的博客 852

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Spring Cloud入门-Gateway服务网关(Hoxton版本)

文章目录摘要Gateway 简介相关概念创建 api-gateway模块在pom.xml中添加相关依赖两种不同的配置路由方式使用yml配置使用Java Bean配置Route Predicate 的使用After Route PredicateBefore Route PredicateBetween Route PredicateCookie Route PredicateHeader Rout...

ThinkWon的博客 1万+

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

SpringCloud Hoxton——Gateway服务网关

SpringCloud Hoxton——Gateway服务网关

贝尔摩德苦艾酒 7100

【SpringCloud】【Hoxton】Gateway全面解析

1 GateWay简介 Spring Cloud Gateway是 Spring Cloud的个全新项目,基于 Spring5.0+ Spring Boot2.0和 Project Reactor等技术开发的网关,它旨在为微服务架构提供一种简单有效的统一的API路由管理方式。 Spring Cloud Gateway作为 Spring Cloud生态系统中的网关,目标是替代Zuul,在 Sprin...

qq_34125999的博客 4437

SpringCloud中使用服务网关( spring cloud gateway)

0. 本篇实战所使用Spring有关版本 SpringCloudGateway 与 Nacos 整合踩坑 (Hoxton.SR1 版本) 原版本: SpringBoot 版本:2.2.4RELEASE SpringCloud 版本:Hoxton.SR1 SpringCloudAlibabaCloud 版本:2.1.1RELEASE 出现的问题: Gateway 启动后,配置 routers,可以进行跳转百度页面,但是无法转发在 Nacos 已经注册的服务,该服务运行正常可以再 Nacos

andrew_dear的博客 1711

【SpringCloud】【Hoxton】基础环境准备

1 引言 记2020年3月8日 SpringCloud 最新版为Hoxton SR3。 2 创建父工程 (1) spring-cloud (2) pom文件 <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.comp...

qq_34125999的博客 2336

Spring Cloud Hoxton.SR1 gateway 与reactor-netty 0.9.3.RELEASE不兼容

问题现象 在启动Spring Cloud Hoxton.SR1 gateway 服务的时候无法启动,错误现象如下: *************************** APPLICATION FAILED TO START *************************** Description: An attempt was made to call a method th...

5irm的专栏 5560

SpringCloud系列教程(四)之SpringCloud Gateway【Hoxton版】

**阅读提醒: 本文面向的是有一定springboot基础者 本次教程使用的Spring Cloud Hoxton RELEASE版本 本文依赖上一篇的工程,请查看上一篇文章以做到无缝衔接,或者直接下载源码:**https://github.com/WinterChenS/spring-cloud-hoxton-study 前情概要 SpringCloud系列教程(一)开篇 SpringCloud系列教程(二)之Nacos # SpringCloud系列教程(三)之Open Feign 本文概览.

LuisChen的博客 1194

SpringCloud Hoxton版 + SpringCloud alibaba学习笔记(5)-- Gateway新一代网关

设计模式 设计模式的征途 https://www.cnblogs.com/edisonchou/default.html?page=8 大战设计模式 https://www.cnblogs.com/linkstar/category/1087887.html Java设计模式:23种设计模式全面解析(超级详细) http://c.biancheng.net/design_pattern/ 常用的设计模式汇总,超详细! https://mp.weixin.qq.com/s/CdMMlYY8A5nVnKL1V8

exodus3的博客 1万+

SpringCloud+SpringCloudAlibaba+SOA架构搭建,使用nacos注册中心,gateway网关配置

版本说明 代码仓库地址点击这里 SpringCloud版本采用目前第二排的 Hoxton.SR10 版本: SpringBoot版本采用 Hoxton.SR10 版本的SpringCloud所支持的 2.3.8.RELEASE : JDKheMaven采用 SpringBoot2.3.8.RELEASE 所推荐的 JDK8和Maven3.5.4(3.3+) 附赠 SpringCloud-Hoxton.SR10 和 SpringBoot2.3.8.RELEASE 官方PDF文档 本人博客当

XiaoHH的博客 1513

<七>spring-cloud Hoxton.SR2 网关组件gateway搭建使用

spring-cloud Hoxton.SR2 网关组件zuul搭建使用 文章目录spring-cloud Hoxton.SR2 网关组件zuul搭建使用1、gateway简介1.1、简介1.2、词汇表1.3、工作原理1.4、详细参考2、项目搭建2.1、搭建新的项目`badger-spring-cloud-gateway`,pom文件如下2.2、主启动类,加eureka的注解`@EnableEurekaClient`2.3、yaml的配置文件3、项目启动,测试使用3.1、启动步骤3.2、测试3、负载均衡

鸭鸭的博客 766
上一篇: SpringCloud微服务小白也能搭(Hoxton.SR8)(六)Zuul|服务网关
下一篇: Flutter 学习(一)环境搭建以及开发工具配置
97牛肉面
博客等级 码龄9年 54粉丝 75原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值