Using RxNetty as proxy server without blocking the client
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);
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())));
Thank you @brharrington
@rotemfogel is there something else you wanted to talk about in this issue?
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));
I found that If I do not block the request, the server response is returned immediately
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.
@rotemfogel Can I close this issue?
yes. thank you