1

Spring Rsocket Server に RSocket-Java を使用する rsocket ルーティング メタデータと同様ですが、RSocket Net Client には、ルートに応じて webfluxes を返すポート 7000 の Websocket エンドポイント ルートに Spring Boot @MessageMapping を使用します。例えば:

@MessageMapping(value = "helloWorld")
public Flux<String> getFluxSocket() {
    log.traceEntry();
    log.info("In hello world");
    
    return Flux.just("{\"Hello\":\"World\"}");
}

スプリング ブート サーバーがローカルで実行されている場合、このフラックスを取得するには、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());

ありがとう

4

2 に答える 2

2

You can implement routing metadata until the .NET library officially supports routing / compsite metadata. If you don't need to send any metadata other than routing metadata, you don't need to create composite metadata. Sending only routing metadata is pretty simple.

As you can see from the spec, just add the length of the route name to the first byte. https://github.com/rsocket/rsocket/blob/master/Extensions/Routing.md

I have no knowledge of .NET, so I'll show you how to implement it in Java and JavaScript instead. FYI.

https://github.com/making/demo-rsocket/blob/master/vanilla-rsocket-client/src/main/java/com/example/vanillarsocketclient/VanillaRsocketClientApplication.java

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;
};
于 2021-02-04T04:31:29.707 に答える