rsocket-js icon indicating copy to clipboard operation
rsocket-js copied to clipboard

RequestResponse (as client) ignores complete

Open freelancer1845 opened this issue 5 years ago • 1 comments

Hey,

I'm trying to use RequestResponse with Spring Boot as RSocketServer.

I have a Controller Method like this:

@MessageMapping
public Mono<Void> request() {
    return Mono.empty();
}

My Request in ts looks like this (the socket actually comes from another subject... but it is the reactivesocket received from the "connect" method):

public requestResponse<T>(route: string, payload: any = {}): Observable<T> {
      let disposer;

      return new Observable<T>((subscribe) => {
        try {
          socket.requestResponse({
            data: payload,
            metadata: String.fromCharCode(route.length) + route
          }).subscribe(
            {
              onComplete: (payload) => {
                console.log("Request Complete. Payload: " + payload)
                // if (payload) {
                //   subscribe.next(payload.data);
                // }
                subscribe.complete();
              },
              onError: (error) => {
                console.log("Error: " + error);
              },
              onSubscribe: (disposer) => {
                console.log("Subscribing")
                disposer = disposer;
              }
            }
          )
          return () => {
            if (disposer) {
              disposer();
            }
          }
        } catch (err) {
          subscribe.error(err);
        }
      });
    }));
}

The Message reaches the controller method and no errors are logged inside spring boot. I guess the problem is, that the returned Frame is a Payload frame without the "next" flag but with the "complete" flag. Because of that "RSocketMachine.js:717" never calls onNext(...) which would complete the requestResponse interaction. In "RSocketMachine.js:316" "onComplete" is set to an emptyfunction.

Is that correct?

My fix is to change RSocketMachine.js:315-319 to this

let value = null;
this._receivers.set(streamId, {
    onComplete: () => subscriber.onComplete(value),
    onError: error => subscriber.onError(error),
    onNext: data => value = data,
});

of course this now emits null as value in the single which is probably not wanted^^

freelancer1845 avatar Mar 18 '20 14:03 freelancer1845

@OlegDokuka Is there any plan to fix this? May be make Single subscriber have an onNext is better way, but may cause breaking change.

kevinat avatar Jul 08 '21 01:07 kevinat