GET请求Only one connection receive subscriber allowed.
时间: 2023-05-23 07:00:57 浏览: 313
这个错误通常是因为使用了同一个连接的多个订阅者,因此只能有一个订阅者接受连接。为了解决这个问题,您需要确保在连接中只使用一个订阅者,或者使用多个连接以便每个订阅者都有一个独立的连接。如果您需要更详细的信息或解决方案,请提供更多的上下文和详细信息。
相关问题
java.lang.IllegalStateException: Only one connection receive subscriber allowed. at reactor.netty.channel.FluxReceive.startReceiver(FluxReceive.java:182) Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: Error has been observed at the following site(s): *__checkpoint ⇢ springfox.boot.starter.autoconfigure.SwaggerUiWebFluxConfiguration$CustomWebFilter [DefaultWebFilterChain] *__checkpoint ⇢ com.texeasy.miniProgram.config.auth.ReactiveRequestContextFilter$1 [DefaultWebFilterChain] *__checkpoint ⇢ com.texeasy.miniProgram.config.auth.ReactiveRequestContextFilter$$EnhancerBySpringCGLIB$$100afa79 [DefaultWebFilterChain] *__checkpoint ⇢ com.alibaba.csp.sentinel.adapter.spring.webflux.SentinelWebFluxFilter [DefaultWebFilterChain] *__checkpoint ⇢ cn.dev33.satoken.reactor.filter.SaReactorFilter [DefaultWebFilterChain] *__checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain] *__checkpoint ⇢ HTTP POST "/miniProgram/pay/createOrderV3" [ExceptionHandlingWebHandler]
这是一个关于 FluxReceive 的错误,可能是由于同时只允许一个连接接收订阅者所导致的。这个错误在多个地方被观察到,包括 springfox.boot.starter.autoconfigure.SwaggerUiWebFluxConfiguration$CustomWebFilter, com.texeasy.miniProgram.config.auth.ReactiveRequestContextFilter$1, com.texeasy.miniProgram.config.auth.ReactiveRequestContextFilter$$EnhancerBySpringCGLIB$$100afa79, com.alibaba.csp.sentinel.adapter.spring.webflux.SentinelWebFluxFilter, cn.dev33.satoken.reactor.filter.SaReactorFilter, org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter 和 HTTP POST "/miniProgram/pay/createOrderV3",可能是由于在多个环节中同时出现了此错误所致。
package com.bolt.gateway.config; import com.bolt.gateway.handler.HystrixFallbackHandler; import com.bolt.gateway.props.AuthProperties; import com.bolt.gateway.props.RouteProperties; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.web.cors.reactive.CorsUtils; import org.springframework.web.filter.reactive.HiddenHttpMethodFilter; import org.springframework.web.reactive.function.server.RequestPredicates; import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebFilter; import org.springframework.web.server.WebFilterChain; import reactor.core.publisher.Mono; /** * 路由配置信息 * * @author arch_group */ @Slf4j @Configuration @AllArgsConstructor @EnableConfigurationProperties({RouteProperties.class, AuthProperties.class}) public class RouterFunctionConfiguration { /** * 这里为支持的请求头,如果有自定义的header字段请自己添加 */ private static final String ALLOWED_HEADERS = "x-requested-with, zkpt-ks-auth, Content-Type, Authorization, credential, X-XSRF-TOKEN, token, username, client"; private static final String ALLOWED_METHODS = "*"; private static final String ALLOWED_ORIGIN = "*"; private static final String ALLOWED_EXPOSE = "*"; private static final String MAX_AGE = "18000L"; private final HystrixFallbackHandler hystrixFallbackHandler; @Bean public WebFilter corsFilter() { return (ServerWebExchange ctx, WebFilterChain chain) -> { ServerHttpRequest request = ctx.getRequest(); if (CorsUtils.isCorsRequest(request)) { ServerHttpResponse response = ctx.getResponse(); HttpHeaders headers = response.getHeaders(); headers.add("Access-Control-Allow-Headers", ALLOWED_HEADERS); headers.add("Access-Control-Allow-Methods", ALLOWED_METHODS); headers.add("Access-Control-Allow-Origin", ALLOWED_ORIGIN); headers.add("Access-Control-Expose-Headers", ALLOWED_EXPOSE); headers.add("Access-Control-Max-Age", MAX_AGE); headers.add("Access-Control-Allow-Credentials", "true"); if (request.getMethod() == HttpMethod.OPTIONS) { response.setStatusCode(HttpStatus.OK); return Mono.empty(); } } return chain.filter(ctx); }; } @Bean public RouterFunction routerFunction() { return RouterFunctions.route( RequestPredicates.path("/fallback") .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), hystrixFallbackHandler); } /** * 解决springboot2.0.5版本出现的 Only one connection receive subscriber allowed. * 参考:https://github.com/spring-cloud/spring-cloud-gateway/issues/541 */ @Bean public HiddenHttpMethodFilter hiddenHttpMethodFilter() { return new HiddenHttpMethodFilter() { @Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { return chain.filter(exchange); } }; } }
这是一个Spring Cloud Gateway的路由配置类。它使用了函数式编程风格来定义路由规则。
在这个类中,主要做了以下几件事情:
1. 配置跨域请求的过滤器(corsFilter):当请求的Origin与服务端的地址不一致时,浏览器会发送跨域请求。跨域请求需要服务端设置特殊的响应头来允许跨域访问。在这个过滤器中,我们判断当前请求是否为跨域请求,如果是,就设置相关的响应头。
2. 配置fallback路由:当其他路由都无法匹配时,将请求转发给hystrixFallbackHandler来处理。这个处理器是一个自定义的降级处理器,用于处理服务熔断、降级等情况。
3. 解决Spring Boot 2.0.5版本出现的"Only one connection receive subscriber allowed"问题:这个问题是由于WebFlux框架在处理请求时,只允许一个订阅者消费数据。为了解决这个问题,我们需要配置一个HiddenHttpMethodFilter过滤器。
以上就是这个类的主要功能和作用。如果你还有其他问题,请继续提问。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)