rsocket - RSocket Net客户端请求流路由元数据到spring boot @MessageMapping路由
问题描述
类似于为 Spring Rsocket Server 使用 RSocket-Java 的 rsocket 路由元数据,但对于 RSocket Net Client,我们使用 spring boot @MessageMapping 用于端口 7000 上的 websocket 端点路由,这取决于路由返回 webfluxes。例如:
@MessageMapping(value = "helloWorld")
public Flux<String> getFluxSocket() {
log.traceEntry();
log.info("In hello world");
return Flux.just("{\"Hello\":\"World\"}");
}
当 Spring Boot 服务器在本地运行时,要获得此通量,您可以使用rsc 客户端
java -jar rsc.jar --debug --request --route helloWorld ws://localhost:7000
或者对于流
java -jar rsc.jar --debug --stream --route myStream ws://localhost:7000
要在 C# Net 中以编程方式执行此操作,它在此处表示 RSocket Net 尚不支持请求路由,但可以使用元数据有效负载。有没有人有这样的网络?
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());
谢谢
解决方案
在 .NET 库正式支持路由/复合元数据之前,您可以实现路由元数据。如果您不需要发送除路由元数据以外的任何元数据,则无需创建复合元数据。仅发送路由元数据非常简单。
从规范中可以看出,只需将路由名称的长度添加到第一个字节即可。 https://github.com/rsocket/rsocket/blob/master/Extensions/Routing.md
我对 .NET 一无所知,所以我将向您展示如何用 Java 和 JavaScript 来实现它。供参考。
static ByteBuffer routingMetadata(String tag) {
final byte[] bytes = tag.getBytes(StandardCharsets.UTF_8);
final ByteBuffer buffer = ByteBuffer.allocate(1 + bytes.length);
buffer.put((byte) bytes.length);
buffer.put(bytes);
buffer.flip();
return buffer;
}
https://github.com/making/demo-rsocket-jsug/blob/master/frontend/vanilla/src/index.js
const routingMetadata = (route) => {
return String.fromCharCode(route.length) + route;
};
推荐阅读
- javascript - 对一个反应做出反应以获得一个角色(Discord.js)
- angular - 使用 docker-compose 运行但不在 kubernetes 部署中的 Angular 应用程序映像
- wordpress - 自定义帖子类型 wordpress 的分页
- evaluation - 为什么我会为 arima 模型获得相同的评估指标?
- javascript - 在 Vue 中加载外部样式表和其他资源的最佳实践
- php - 找不到带有#符号的php文件
- sql - 如何在 MS Access 中将 mmmm-YYYY 模式字符串转换为日期?
- c# - OracleDataReader 将多个结果提取到 csv
- javascript - 检查数组javascript中的连续数字
- c# - 用于从 .NET Core 应用程序发送 cookie 并调用 WCF 服务的中间件