RxNetty icon indicating copy to clipboard operation
RxNetty copied to clipboard

Using RxNetty as proxy server without blocking the client

Open rotemfogel opened this issue 10 years ago • 8 comments

I have an RxNetty server which is transforming the requests and sending it via HTTP to another service. I did not find a way to perform a non-blocking request with the HttpClient. I want to fail the request on timeout. The only way I found to be working is:

client.submit(request)
    .flatMap(response -> response.getContent().
        map(byteBuf -> byteBuf.toString(Charset.defaultCharset())))
    .toBlocking().toFuture().get(timeout, TimeUnit.MILLISECONDS);

rotemfogel avatar Dec 17 '15 12:12 rotemfogel

You should be able to call timeout on the response observable, e.g.:

client.submit(request)
    .timeout(timeout, TimeUnit.MILLISECONDS)
    .flatMap(response -> response.getContent().
        map(byteBuf -> byteBuf.toString(Charset.defaultCharset())));

brharrington avatar Dec 17 '15 14:12 brharrington

Thank you @brharrington

rotemfogel avatar Dec 18 '15 09:12 rotemfogel

@rotemfogel is there something else you wanted to talk about in this issue?

NiteshKant avatar Dec 22 '15 06:12 NiteshKant

Yes. Thank you @NiteshKant. When using timeout without blocking, when does the timeout occur? on the client.submit? on the observable itself?

client.submit(request)
        .timeout(timeout, TimeUnit.MILLISECONDS)
        .onErrorReturn(t -> null)
        .filter(res -> res != null)
        .flatMap(response -> response.getContent())
        .map(data -> data.toString(Charset.defaultCharset()))
        .forEach(s -> resStr.append(s));

rotemfogel avatar Dec 22 '15 08:12 rotemfogel

I found that If I do not block the request, the server response is returned immediately

rotemfogel avatar Dec 22 '15 11:12 rotemfogel

timeout is applied on the Obersvable it is applied on, in this case the Observable returned by client.submit.

I found that If I do not block the request, the server response is returned immediately

Client will send the request to the server when the Observable returned by client.submit() is subscribed to.

NiteshKant avatar Dec 23 '15 17:12 NiteshKant

@rotemfogel Can I close this issue?

NiteshKant avatar Mar 29 '16 20:03 NiteshKant

yes. thank you

rotemfogel avatar Mar 30 '16 17:03 rotemfogel