Java RSocket 客户端与 Spring RSocket 通道连接

问题描述

我有简单的 Spring Boot RSocket 服务

    @MessageMapping("msend")
    public Flux<String> msend(String message) {
        log.info("msend channel publish " + message);
        return Flux.just(message," "+System.currentTimeMillis());
    }

很容易连接2个Spring服务,但是我的客户端应用没有spring,我的客户端应该是RSocket java

我很难理解如何向该特定通道发送(路由,如 Spring RsocketRequester)消息。

客户端代码应该是:

 Mono<RSocket> rsocket = RSocketConnector.create()               
            .MetadataMimeType(WellKNownMimeType.MESSAGE_RSOCKET_COMPOSITE_MetaDATA.getString())               
            .connect(TcpClientTransport.create(2050));


 ///real path "http://gateway:2022/producer/toProducerRsocket",2050)
 ///toProducerRsocket redirect to producer/rsocket

是否可以订阅 Spring 频道?

解决方法

这对于定义元数据类型来说看起来是正确的。但是您需要为请求流设置它。此处的频道听起来不正确,因为您只有一个输入值消息。

https://stackoverflow.com/a/62776146/1542667

CompositeByteBuf metadata = ByteBufAllocator.DEFAULT.compositeBuffer();
RoutingMetadata routingMetadata = TaggingMetadataCodec.createRoutingMetadata(ByteBufAllocator.DEFAULT,List.of("/route"));
CompositeMetadataCodec.encodeAndAddMetadata(metadata,ByteBufAllocator.DEFAULT,WellKnownMimeType.MESSAGE_RSOCKET_ROUTING,routingMetadata.getContent());