首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >springboot-rsocket如何接收多个参数?

springboot-rsocket如何接收多个参数?
EN

Stack Overflow用户
提问于 2019-11-21 13:49:59
回答 1查看 332关注 0票数 1
代码语言:javascript
复制
private final RSocketRequester rSocketRequester;

@RequestMapping(path = "/**")
public Publisher<ServerResponse> mockController(ServerWebExchange serverWebExchange) {
    String path = serverWebExchange.getRequest().getPath().toString();
    String method = serverWebExchange.getRequest().getMethodValue();
    return rSocketRequester.route("/mock").data(path).data(method).retrieveMono(ServerResponse.class);
}


@MessageMapping(value = "/mock")
public Mono<ServerResponse> mockService(String path, String method) {
    return Mono.just(new ServerResponse<>(0, "success", path+method));
}

如果我给Rsocket设置了更多的参数,当我请求控制器时,Rsocket会报告一个错误

代码语言:javascript
复制
java.lang.NullPointerException: null
at io.rsocket.util.ByteBufPayload.sliceData(ByteBufPayload.java:149) ~[rsocket-core-1.0.0-RC5.jar:na]
at org.springframework.messaging.rsocket.PayloadUtils.retainDataAndReleasePayload(PayloadUtils.java:54) ~[spring-messaging-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.messaging.rsocket.annotation.support.MessagingRSocket.retainDataAndReleasePayload(MessagingRSocket.java:186) ~[spring-messaging-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:107) ~[reactor-core-3.3.0.RELEASE.jar:3.3.0.RELEASE]
at reactor.core.publisher.FluxJust$WeakScalarSubscription.request(FluxJust.java:99) ~[reactor-core-3.3.0.RELEASE.jar:3.3.0.RELEASE]
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:162) ~[reactor-core-3.3.0.RELEASE.jar:3.3.0.RELEASE]
at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.request(FluxPeekFuseable.java:137) ~[reactor-core-3.3.0.RELEASE.jar:3.3.0.RELEASE]

如何重塑它?这是我的rsocket-controller配置,会不会是配置问题?

代码语言:javascript
复制
@Bean
RSocket rSocket() {
    return RSocketFactory
            .connect()
            .dataMimeType(MimeTypeUtils.ALL_VALUE)
            .frameDecoder(PayloadDecoder.ZERO_COPY)
            .transport(TcpClientTransport.create(7003))
            .start()
            .block();
}

@Bean
RSocketRequester rSocketRequester(RSocketStrategies rSocketStrategies) {
    return RSocketRequester.builder()
            .rsocketFactory(factory -> factory
                    .dataMimeType(MimeTypeUtils.ALL_VALUE)
                    .frameDecoder(PayloadDecoder.ZERO_COPY))
            .rsocketStrategies(rSocketStrategies)
            .connect(TcpClientTransport.create(7003))
            .retry().block();
}
EN

回答 1

Stack Overflow用户

发布于 2019-11-22 17:27:57

作为explained in the reference documentation for RSocket,带@MessageMapping注释的处理程序方法只能绑定传入消息中的几个内容:

将实际的消息body

  • headers

  • some变量从目标路由
  • 或请求程序发送到client

在您的示例中,不能绑定String path, String method参数。

不支持在RSocketRequester请求中设置多个数据有效负载(我认为只会发送最后一个)。相反,您应该创建单个对象并将其作为有效负载发送。

在设置RSocket时,使用数据MIME类型的MimeTypeUtils.ALL_VALUE将不起作用。您需要使用实际的、具体的MIME类型,否则框架将不知道如何序列化数据。

通常,您应该避免手动创建RSocket,而应使用rely on the Spring infrastructure for that

更新

同时,Spring Framework团队的improved the API to avoid calling data on the requester multiple times

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58968085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档