Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
190 views
in Technique[技术] by (71.8m points)

typescript - Unable to read the payload of a requestResponse call at the server side

Consider the following TS client code snippet below :

this.rSocketClient.connect().subscribe({
      onComplete: socket => {
        const endpoint = ?accesscode’;
        socket.requestResponse({
          data: clientId, //the clientId is a non-empty string
          metadata: String.fromCharCode(endpoint.length) + endpoint
        }).subscribe({
            onComplete: () => console.log(’Done’),
            onError: error => {
              console.log('Connection has been closed due to:: ' + error);
            },
          });
      },
      onError: error => console.error(error),
      onSubscribe: cancel => {}
    });

I would like to know how the signature of my server accesscode endpoint should look like. In fact I tried the following solution, but it didn't workout as expected. In fact when I put a breakpoint within getAccessCode, the call gets caught but clientId cannot be resolved:

@MessageMapping("accesscode")
public Mono<String> getAccessCode(@Payload String clientId) {
  log.info("requested clientId:"+clientId);
  //Server side processing to read the corresponding 'accesscode' from the DB
  return Mono.just(DefaultPayload.create(accesscode));
}

Any help will be more than appreciated.

question from:https://stackoverflow.com/questions/65931835/unable-to-read-the-payload-of-a-requestresponse-call-at-the-server-side

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your client needs to send the routing information that spring-boot makes it decisions off. See https://domenicosibilio.medium.com/rsocket-with-spring-boot-js-zero-to-hero-ef63128f973d

Specifically look at the mime type in setting up the client, and the route which should match the @MessageMapping your your code.

  // Create an instance of a client
  client = new RSocketClient({
    serializers: {
      data: JsonSerializer,
      metadata: IdentitySerializer
    },
    setup: {
      // ms btw sending keepalive to server
      keepAlive: 60000,
      // ms timeout if no keepalive response
      lifetime: 180000,
      // format of `data`
      dataMimeType: 'application/json',
      // format of `metadata`
      metadataMimeType: 'message/x.rsocket.routing.v0',
    },
    transport: new RSocketWebSocketClient({
      url: 'ws://localhost:8080/tweetsocket'
    }),
  });

  // Open the connection
  client.connect().subscribe({
    onComplete: socket => {
      // socket provides the rsocket interactions fire/forget, request/response,
      // request/stream, etc as well as methods to close the socket.
      socket.requestStream({
        data: {
          'author': document.getElementById("author-filter").value
        },
        metadata: String.fromCharCode('tweets.by.author'.length) + 'tweets.by.author',
      }).subscribe({
        onComplete: () => console.log('complete'),
        onError: error => {
          console.log(error);
          addErrorMessage("Connection has been closed due to ", error);
        },
        onNext: payload => {
          console.log(payload.data);
          addMessage(payload.data);
        },
        onSubscribe: subscription => {
          subscription.request(2147483647);
        },
      });
    },
    onError: error => {
      console.log(error);
      addErrorMessage("Connection has been refused due to ", error);
    },
    onSubscribe: cancel => {
      /* call cancel() to abort */
    }
  });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...