RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.
@RequestMapping(method = RequestMethod.POST, value = "/pushData", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Single<String> pushData(@RequestBody String json)
How I can slowdown a pressure on the logic inside this method? Is it a right way of thinking or I should slow it down the level of Undertow/Jetty/Netty by applying some strategy on it.
Single
implies a single result so backpressure is not really at play there. If you want to reduce the call frequency to pushData
itself, there are ways for it, such as using concatMap
or flatMap
with concurrency limit, spanning out the source events over time, etc. You could also research Retrofit use cases similar to your problem.
public Single<String> pushJsonDataAsync(String json) {
return Single.create(source -> {
try {
PushCrawlerDataRequest.Builder request = PushCrawlerDataRequest.newBuilder();
JsonFormat.parser().merge(json, request);
PushCrawlerDataResponse.Builder builder = pushData(request.build());
source.onSuccess(JsonFormat.printer().print(builder));
} catch (Exception ex) {
source.onError(ex);
}
});
}
this is how I'm trying to use it right now