Webflux RSocket Server using RSocketRequestor sending message to Rsocket-js client .Responder not receiving

472 views Asked by At

My requirement is that as and when some event happens on server, it should push updates to client. Want to use RSocket and not SSE.
Will responder configured on the rsocket-js client respond to server request?
If yes then how should the rsocket-js responder be configured to accept message on a particular route? That part please clarify.
Not sure if my spring service is correct.

My Webflux Spring Boot RSocket server code-

@Service  
@RequiredArgsConstructor  
public class RsocketService {  
    private final RSocketRequester rSocketRequester;  

    public void serverToClientRequest(){  

        Mono.just("Your request  is completed at "+ LocalDateTime.now())
           .delayElement(Duration.ofSeconds(ThreadLocalRandom.current().nextInt(5, 10)))   
           .flatMap(m -> rSocketRequester.route("request.stream").data(m).send())  
           .subscribe();
    }  
}  

I have a Controller -

@MessageMapping("request.stream")  
public Flux<String> requestStream(@Payload String requestData) {  
}  

Client side I am using RSocketWebSocketClient from 'rsocket-websocket-client';

const client = new RSocketClient({   
  responder: new EchoResponder(),  
  transport: new RSocketWebSocketClient(  
    {
      url: 'ws://localhost:7000/rsocket',  
      wsCreator: (url: string) => new WebSocket(url),  
      debug: true,  
    }
  ),  
  setup: {  
    dataMimeType: "text/plain",
    metadataMimeType: 'message/x.rsocket.routing.v0',
    keepAlive: 600000,
    lifetime: 180000,
  }
});

My reactjs component-

async componentDidMount() {  
    const rsocket= await client.connect();  
    console.log('rsocket client connected');  
     rsocket
            .requestStream({
              data: "client message",
              metadata: String.fromCharCode('request.stream'.length) + 'request.stream'
            })
            .subscribe({
              onComplete: () => {
                console.log("request stream completed");

              },
              onNext: value => {
                console.log("on next-->got data from sever");
                console.log(value.data);
              },
              onError: (error: any) => {
                console.log("got error with requestResponse");
                console.error(error);
              },
              onSubscribe: sub => {
                console.log("subscribe request Stream!");
                sub.request(2147483647);
              }
            });
        }

EchoResponder is taken from https://github.com/rsocket/rsocket-js/blob/master/packages/rsocket-examples/src/LeaseClientExample.js. But the responder does not get any message. Any help is appreciated please.

0

There are 0 answers