0%

Spring系列之SpringGateway

TodoItem

如果统一通过网关来控制请求的话,其他业务服务提供者要怎么关闭外部请求权限? todo

Basic Knowledge

两种实现过滤器方式的区别

  1. 通过继承AbstractGatewayFilterFactory工厂类
  2. 通过实现GlobalFilter和Ordered

简单来说就是:前者需要通过spring.cloud.routes.filters配置作用在指定的路由上,或者通过spring.cloud.default-filters配置,作用在全局路由上;后者无需配置,系统初始化的时候自动加载,作用在每个路由上。

Problem Solution

(No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.

HikariCP maxLifetime 参数设置太小了,或者太大,跟进HikariCP源码会发现:

1
2
3
4
5
6
if (maxLifetime != 0 && maxLifetime < SECONDS.toMillis(30)) {
LOGGER.warn("{} - maxLifetime is less than 30000ms, setting to default {}ms.", poolName, MAX_LIFETIME);
maxLifetime = MAX_LIFETIME;
}

private static final long MAX_LIFETIME = MINUTES.toMillis(30);

时间默认是30秒
这个要和MySQL的wait_timeout的值对应,建议略小于这个值即可,不能大于wait_timeout。

Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=webFluxConversionService)}

参考

记录一次SpringGateway转发请求失败的问题定位过程

HookRegisteringBeanDefinitionRegistryPostProcessor.setupHooks(BeanFactory) (org.springframework.cloud.sleuth.instrument.reactor)

springGateway集成feign、hystrix和SpringSecurity之后,底层通过ReactorProject再到netty的NioEventLoop,实现微服务之间的内部调用NioEventLoop的run,run方法会一直循环做一些调用逻辑???

跟了几天代码,最后发现和postman的tab删除,完了将另外一个微服务可以调通的duplicate一份就ok了。。。

{@org.springframework.beans.factory.annotation.Qualifier(value=webFluxConversionService)}

某次重构代码之后报这个错:

1
No qualifying bean of type 'org.springframework.core.convert.ConversionService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=webFluxConversionService)}

谷歌了一番,发现是因为pom同时引入了spring-cloud-starter-gateway 和 spring-boot-starter-web,把spring-boot-starter-web去掉即可。