0
 setInterval(() => {
        let that = this;
        this.socket && this.socket.requestResponse({
            data: '' + (++index),
            metadata: 'org.mvnsearch.account.AccountService.findById',
        }).subscribe({
            onComplete(payload) {
                let account = JSON.parse(payload.data);
                that.setState({
                    nick: account.nick
                })
            },
            onError: (e) => {
                console.log('onError', e)
            }
        });
    }, 2000)

enter image description here

enter image description here

trying to connect to spring rsocket using reactjs. getting an error before subscribe in the javascript code shown below.

**this.socket.requestResponse({
                data: '' + (++index),
                metadata: 'org.mvnsearch.account.AccountService.findById',
            })**

enter image description here

How to resolve the above issue?

Robert Ravikumar
  • 912
  • 2
  • 11
  • 29

1 Answers1

0

If you are using rsocket routing on the backend, it is length prefixed. See https://github.com/rsocket/rsocket-demo/blob/master/src/main/js/app.js#L22-L36

  // Create an instance of a client
  const client = new RSocketClient({
    setup: {
      keepAlive: 60000,
      lifetime: 180000,
      dataMimeType: 'application/json',
      metadataMimeType: 'message/x.rsocket.routing.v0',
    },
    transport: new RSocketWebSocketClient({url: url}),
  });

  const stream = Flowable.just({
    data: '{"join": {"name": "Web"}}',
    metadata: String.fromCharCode('chat/web'.length) + 'chat/web',
  });

The routing specification allows multiple routes, so the encoding of a single route is unfortunately complicated by this. https://github.com/rsocket/rsocket/blob/master/Extensions/Routing.md

Yuri Schimke
  • 12,435
  • 3
  • 35
  • 69
  • Thanks it worked . this.socket.requestResponse({ data: '' + (++index), metadata: String.fromCharCode('org.mvnsearch.account.AccountService.findById'.length) +'org.mvnsearch.account.AccountService.findById' }) – Robert Ravikumar Apr 17 '21 at 13:28
  • Can you explain me why we need to add the length at the start of the metadata? – Robert Ravikumar Apr 17 '21 at 13:29
  • See the definition of the routing spec https://github.com/rsocket/rsocket/blob/master/Extensions/Routing.md – Yuri Schimke Apr 17 '21 at 14:12