rsocket / rsocket-js

JavaScript implementation of RSocket

Home Page:https://github.com/rsocket/rsocket-js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spring messaging `@ConnectMapping` not called for routes

bseber opened this issue Β· comments

hey o/

not sure if I'm right here 😊
(Just thought so since it works in a plain Java App. see here )

I've got a java (spring) controller with a ConnectMapping for a custom route:

@Controller
public class WsController {

    @ConnectMapping("setup")
    public Mono connect() {
        System.out.println("Never called :-(");
        return Mono.empty();
    }
}

The JavaScript RSocketClient sends the setup frame with the custom route:

const client = new RSocketClient({
    serializers: {
        data: JsonSerializer,
        metadata: JsonSerializer,
    },
    setup: {
        keepAlive: 999999,
        lifetime: 999999,
        dataMimeType: "application/json",
        metadataMimeType: "message/x.rsocket.routing.v0",
        payload: {
            metadata: String.fromCharCode("setup".length) + "setup"
        }
    },
    transport: new RSocketWebSocketClient(
        {
            debug: true,
            url: `ws://${window.location.host}/rsocket`,
        }
    ),
});

client.connect().then(...)

But WsController#connect is never called.
It works, however, with a default @ConnectMapping and not sending a payload within the setup frame.

I've added a sample project that can be found here: https://github.com/bseber/spring-boot-rsocket-example

Should it work with the custom route? Do I have to configure the RSocketClient somehow?

I"m getting the same issue when I use composite metadata

url: `ws://${window.location.host}/rsocket`,

url: ws://${window.location.host}:{port}/rsocket,
i think that you need insert ws's port to url

I use wss so I don't think thats the issue

I use wss so I don't think thats the issue

i'm getting same issue when using composite metadata but no problem with Seber's issue

@baudiachatb indeed, window.location.host includes the port. in my example app that would be 8080. however using the hard coded "ws://localhost:7000/rsocket" url still doesn't work.

did you checkout my example project? or do you have a working example? would be nice if this "just works" and I just have a stupid error on my side :-)

I use wss so I don't think thats the issue

i'm getting same issue when using composite metadata but no problem with Seber's issue

Did you use the code from @bseber exactly as he posted it? If not can you post your code here? Maybe we were missing a little piece.

commented

Any news about this problem? Maybe it must be opened on the spring project?

Hi all,

The issue here is a few things:

  • It's best to use composite metadata when defining a route
  • When using composite metadata, it's important to use IdentitySerializer for metadata

IdentitySerializer will pass the value of metadata through as-is, without any modification. This is important as the value for metadata is already encoded as it should be from encodeCompositeMetadata(...).

Please see https://github.com/bseber/spring-boot-rsocket-example/pull/1/files for example changes, and please let me know if this clears up any confusion and addresses the issues you were experiencing.

import {
    BufferEncoders,
    JsonSerializer,
    RSocketClient,
    APPLICATION_JSON,
    MESSAGE_RSOCKET_COMPOSITE_METADATA,
    encodeRoute, MESSAGE_RSOCKET_ROUTING, encodeCompositeMetadata, IdentitySerializer
} from "rsocket-core";
import RSocketWebSocketClient from "rsocket-websocket-client";

const client = new RSocketClient({
    serializers: {
        data: JsonSerializer,
        metadata: IdentitySerializer,
    },
    setup: {
        keepAlive: 999999,
        lifetime: 999999,
        dataMimeType: APPLICATION_JSON.string,
        metadataMimeType: MESSAGE_RSOCKET_COMPOSITE_METADATA.string,
        payload: {
            metadata: encodeCompositeMetadata([
                [MESSAGE_RSOCKET_ROUTING, encodeRoute("setup")],
            ])
        }
    },
    transport: new RSocketWebSocketClient(
        {
            debug: true,
            url: "ws://localhost:7000/rsocket",
        },
        BufferEncoders,
    ),
});

nice, thanks @viglucci!