简体   繁体   English

仅一个连接允许接收订户

[英]Only one connection receive subscriber allowed

Can someone help me with Only one connection receive subscriber allowed. 有人可以帮助我吗? Only one connection receive subscriber allowed. error? 错误?

I looked at Oleh Dokuka's answer but it did not help me. 我看着Oleh Dokuka的回答,但没有帮助我。

I have simplified the code for demonstration purpose. 我已经简化了代码以进行演示。 In my actual code I am getting a bulk Json request, I need to query two different tables taking two different parameters from the request body, call another service using both the results and send the result in the response. 在我的实际代码中,我收到一个批量Json请求,我需要查询两个不同的表,这些表从请求主体中获取两个不同的参数,使用这两个结果调用另一个服务,并将结果发送到响应中。

Router function 路由器功能

@Bean
    public RouterFunction<ServerResponse> myRoute(MyRequestHandler myRequestHandler) {

        return route(RequestPredicates.POST("/api/something"), myRequestHandler::myHandlerFunction);
    }

Handler function 处理函数

public Mono<ServerResponse> myHandlerFunction(ServerRequest serverRequest) {
        Mono<Integer> just = Mono.just(22);

//For simplification I've added String body here. In actual code I have proper json body 
        Mono<String> stringMono = serverRequest.bodyToMono(String.class);

        Mono<String> mono = stringMono.zipWith(stringMono).map(t -> t.getT2() + t.getT1());

        return ok().body(mono, String.class);
    }

The code is working fine if I replace stringMono with just in both the places in 如果我just在以下两个位置替换stringMono ,则代码工作正常

Mono<String> mono = stringMono.zipWith(stringMono).map(t -> t.getT2() + t.getT1());

Why is it working with Mono<String> mono = just.zipWith(just).map(t -> t.getT2() + t.getT1()); 为什么与Mono<String> mono = just.zipWith(just).map(t -> t.getT2() + t.getT1());

Thanks in advance. 提前致谢。

It looks like the stringMono.zipWith(stringMono) will cause Spring to attempt to subscribe to the body of the request twice which is likely your problem since the ServerRequest is unicast and can have only one subscriber. 看起来stringMono.zipWith(stringMono)会使Spring尝试两次订阅请求的主体,这很可能是您的问题,因为ServerRequest是单播的,只能有一个订阅者。

Try this: 尝试这个:

Mono<String> stringMono = serverRequest.bodyToMono(String.class).publish(body -> body.zipWith(body).map(t -> t.getT2() + t.getT1()));

publish() will not cause multiple subscriptions to the body. publish()不会导致对正文的多个订阅。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Webflux post 请求:只允许一个连接接收订阅者 - Webflux post request: Only one connection receive subscriber allowed 当响应不包含媒体类型头时,Spring WebClient抛出“仅允许一个连接接收订阅者” - Spring webclient throws “Only one connection receive subscriber allowed” when response does not contain media type header 响应正文为空时,“IllegalStateException:仅允许一个连接接收订阅者” - "IllegalStateException: Only one connection receive subscriber allowed" when response body is empty 当响应具有HTTP错误状态代码时,为什么会出现“只允许一个连接接收订户”? - Why do I get `Only one connection receive subscriber allowed` when the response has an HTTP error status code? RxJava:“java.lang.IllegalStateException:只允许一个订阅者!” - RxJava: “java.lang.IllegalStateException: Only one subscriber allowed!” 尝试制作group.toList(),但看起来有问题。 但得到:只允许一个用户! 如何修复代码? - Try to make group.toList() but looks questionably. But got: Only one subscriber allowed! How to fix the code? Spring TomEE 中的持久 JMS 订阅者(不允许在使用的连接上设置 clientID) - Spring Durable JMS Subscriber in TomEE (Setting clientID on a used Connection is not allowed) 在Java 9上发布数据以只有一个订阅者将使用它的方式流向订阅者 - Publishing data on java 9 Flow to subscribers in a way that only one subscriber will consume it 为什么永久订阅一次只能有一个活动订阅者 - Why durable subscription can have only one active subscriber at a time 规定JAXB中仅允许元素的一个实例? - Stipulate that only one instance of an element is allowed in JAXB?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM