use*_*576 3 spring-boot rsocket spring-rsocket
如何设置路由元数据(在服务器使用 Spring Boot Rsocket 时仅使用 RSocket-Java 的有效负载。
Flux<Payload> s = connection.flatMapMany(requester -> requester.requestStream(DefaultPayload.create("Some Message")))
服务器正在使用@MessageMapping("/route")
小智 7
使用 SpringBoot 上的 RSocket 交互类型@MessageMapping是根据带注释的方法的签名决定的(更多信息在spring 文档中)
让我们假设它有签名:
@MessageMapping("/route")
Flux<String> getStreamOfStrings(String message) {...}
Run Code Online (Sandbox Code Playgroud)
基于 spring docs 交互类型的基数表是请求流。
RSocket java客户端需要为元数据指定mime-type:
RSocket rsocketClient = RSocketConnector.create()
//metadata header needs to be specified
.metadataMimeType(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString())
// value of spring.rsocket.server.port eg 7000
.connect(TcpClientTransport.create(7000))
.block();
Run Code Online (Sandbox Code Playgroud)
数据将是简单的字符串:
ByteBuf data = ByteBufAllocator.DEFAULT.buffer().writeBytes("request msg".getBytes());
Run Code Online (Sandbox Code Playgroud)
RSocket 中的路由定义为元数据扩展,需要与数据一起发送以指定路由。这是如何创建它的示例(请参阅包io.rsocket.metadata 中的其他类)
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());
Run Code Online (Sandbox Code Playgroud)
创建数据和元数据,以便您可以requestSteam使用:
rsocketClient.requestStream(DefaultPayload.create(data, metadata))
.map(Payload::getDataUtf8)
.toIterable()
.forEach(System.out::println);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1103 次 |
| 最近记录: |