2

The case is the following:

After as clients A and B established connections with a server via RSocket protocol, each of the clients could be notified with their own event(s) (event A or event B) to trigger some action on a client (event X -> action on client X).

Thanks

Serhii Povísenko
  • 3,352
  • 1
  • 30
  • 48

1 Answers1

3

You could achieve it with setup payload.

Server:

@Controller
public class ServerController {
    private static final Map<String, RSocketRequester> REQUESTER_MAP = new HashMap<>();

    @ConnectMapping("client-id")
    void onConnect(RSocketRequester rSocketRequester, @Payload String clientId) {
        rSocketRequester.rsocket()
                .onClose()
                .subscribe(null, null,
                        () -> REQUESTER_MAP.remove(clientId, rSocketRequester));
        REQUESTER_MAP.put(clientId, rSocketRequester);
    }
}

Client:

Mono<RSocketRequester> rSocketRequesterMono(
        RSocketRequester.Builder rSocketRequesterBuilder, // preconfigured bean
        RSocketMessageHandler rSocketMessageHandler, // preconfigured bean
        URI webSocket, String clientId) {
    return rSocketRequesterBuilder
            .rsocketFactory(rsocketFactory -> rsocketFactory
                    .addSocketAcceptorPlugin(socketAcceptor ->
                            rSocketMessageHandler.responder()))
            .setupRoute("client-id")
            .setupData(clientId)
            .connectWebSocket(webSocket);
}

Now you can get RSocketRequester by client on the server side and call specific client.

Alexander Pankin
  • 3,787
  • 1
  • 13
  • 23