{"id":678,"date":"2018-06-27T03:02:02","date_gmt":"2018-06-27T01:02:02","guid":{"rendered":"http:\/\/itblog.inginea.eu\/?p=678"},"modified":"2021-11-07T04:37:42","modified_gmt":"2021-11-07T03:37:42","slug":"speed-up-services-with-reactive-api-in-java-ee-8","status":"publish","type":"post","link":"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/","title":{"rendered":"Speed Up Services With Reactive API in Java EE 8"},"content":{"rendered":"<div class=\"seriesmeta\">This entry is part 1 of 1 in the series <a href=\"https:\/\/ondro.inginea.eu\/index.php\/series\/java-ee-8-microservices\/\" class=\"series-175\" title=\"Java EE 8 Microservices\">Java EE 8 Microservices<\/a><\/div>\n<p>Services can often be optimized with asynchronous processing even without changing their behavior towards the outside world. The reason why some services aren&#8217;t efficient is that they need to wait for other services to provide a result to continue further. Let&#8217;s look how to call external REST services without waiting for them and also do multiple parallel calls independently and combine their results later with a reactive pipeline in Java EE 8.<\/p>\n\n\n\n<!--more-->\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>This topic and much more will be described in more detail in my upcoming book <a rel=\"noopener\" href=\"https:\/\/www.amazon.com\/Java-EE-Microservices-Mert-%C3%87aliskan\/dp\/1788475143\/ref=sr_1_1?ie=UTF8&amp;qid=1524472047&amp;sr=8-1&amp;keywords=Java+EE+8+Microservices\" target=\"_blank\">Java EE 8 Microservices<\/a>, which I co-author with Mert \u00c7aliskan and Pavel Pscheidl<\/p><\/blockquote>\n\n\n\n<p>If our service calls multiple microservices and waits for each call to finish and return results before doing another call, it&#8217;s a good candidate to refactor using reactive API. In order to make the service more efficient, it could do all the calls to external services&nbsp;in parallel if they don&#8217;t depend on each other. This would decrease the time spent waiting and thus speed up the microservice.<\/p>\n\n\n\n<p>In order to call REST services in parallel, we&#8217;ll use the new reactive client API in JAX-RS. We&#8217;ll combine it with the RxJava library to combine their results when available. This combination will allow us to write clean and efficient code. And with an additional benefit that the current thread can be released for further processing while waiting for results from remote calls.<\/p>\n\n\n\n<p>We&#8217;ll build a pipeline which processes the results as they arrive and finally merges them into a single response. The first part of the pipeline will call each remote service. Instead of waiting for the results, we&#8217;ll specify what to do with each received result and continue with calling other services. Using the rx() method on the JAX-RS client request builder allows us to call a version of the <code>get()<\/code> method, which immediately returns instead of waiting for the result. In order to process results when they arrive, we can chain method handlers onto a <code>CompletionStage<\/code> returned from the <code>rx<\/code> version of the <code>get()&nbsp;<\/code> method:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\">CompletionStage<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Forecast<\/span>&gt;<\/span> stage = temperatureServiceTarget\n  .request()\n  .rx()\n  .get(Temperature.class)\n  .thenApply(temperature -&gt; new Forecast(temperature));<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p id=\"block-46df34cf-9a60-4ae2-b3f9-bcc3f0c56c9a\">The above code will call a temperature service and then register a lambda expression to process the resulting temperature when it arrives. This maps the temperature to a forecast object, which can be accessed with the stage&nbsp; variable later.<\/p>\n\n\n\n<p>However, we want to use another variant of the <code>get()<\/code>&nbsp; method together with an RxJava Flowable Invoker from the Jersey project to get a <code>Flowable<\/code>&nbsp; from RxJava instead of a <code>CompletionStage<\/code>. The <a rel=\"noreferrer noopener\" href=\"http:\/\/reactivex.io\/RxJava\/2.x\/javadoc\/io\/reactivex\/Flowable.html\" target=\"_blank\">Flowable<\/a> interface makes it easier to combine multiple asynchronous results with much simpler code than <code>CompletionStage<\/code> and also more efficiently.<\/p>\n\n\n\n<p>With the following code, we will call an external service and return a Flowable:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\">Flowable<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Forecast<\/span>&gt;<\/span> flowable = temperatureServiceTarget\n  .register(RxFlowableInvokerProvider.class)\n  .request()\n  .rx(RxFlowableInvoker.class)\n  .get(Temperature.class)\n  .map(temperature -&gt; new Forecast(temperature);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>We register additional <code>RxFlowableInvokerProvider<\/code>, which allows to request <code>RxFlowableInvoker<\/code>&nbsp; later. This invoker then gives us the <code>Flowable<\/code>&nbsp; return type from RxJava. These classes are not in the JAX-RS API and we must add them with the Jersey RxJava2 library:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">dependency<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">groupId<\/span>&gt;<\/span>org.glassfish.jersey.ext.rx<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">groupId<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">artifactId<\/span>&gt;<\/span>jersey-rx-client-rxjava2<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">artifactId<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">version<\/span>&gt;<\/span>2.26<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">version<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">dependency<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>On the first sight it seems we made the code more complicated while doing the same thing. But a <code>Flowable<\/code> instance allows us to combine multiple calls easily:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">Flowable.concat(flowable1, flowable2)\n  .doOnNext(forecast -&gt; {\n    forecasts.add(forecast);\n  })\n  .doOnComplete(() -&gt; {\n    asyncResponse.resume(Response.ok(forecasts).build());\n  })\n  .doOnError(asyncResponse::resume)\n  .subscribe();\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>For each forecast received from any flowable, we add it to a list of forecasts. Finally, we send the list of forecasts as a response or send an error response. The final call to <code>subscribe()<\/code>&nbsp; is necessary to register the listeners, otherwise they would be ignored.<\/p>\n\n\n\n<p>You may have also noticed the <code>asyncResponse<\/code>&nbsp; variable used to send the final response or signal an error. This is a JAX-RS asynchronous response instance, which is used to complete a REST response at later time, when the data is available, without blocking the initial processing thread. Using the asynchronous response helps us save thread resources while waiting for results from external REST services. In order to turn on asynchronous processing in our REST endpoint, we will inject <a rel=\"noreferrer noopener\" href=\"https:\/\/javaee.github.io\/javaee-spec\/javadocs\/javax\/ws\/rs\/container\/AsyncResponse.html\" target=\"_blank\">javax.ws.rs.container.AsyncResponse<\/a> as the REST method argument, together with the <a rel=\"noreferrer noopener\" href=\"https:\/\/javaee.github.io\/javaee-spec\/javadocs\/javax\/ws\/rs\/container\/Suspended.html\" target=\"_blank\">@Suspended<\/a> annotation. We will also change the return type to <code>void<\/code> because we&#8217;ll be building the response using the <code>AsyncResponse<\/code> instance:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-keyword\">@GET<\/span>\n@Produces(MediaType.APPLICATION_JSON)\npublic void getForecasts(@Suspended AsyncResponse asyncResponse) {\n  <span class=\"hljs-comment\">\/* ...here come some asynchronous calls to REST services... *\/<\/span>\n  <span class=\"hljs-selector-tag\">asyncResponse<\/span><span class=\"hljs-selector-class\">.resume<\/span>(...)\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Final code example<\/h2>\n\n\n\n<p>The following code will:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>turn on asynchronous processing of REST requests in the <code>getForecasts<\/code> method<\/li><li>set 5 minute timeout on the asynchronous response<\/li><li>execute the temperature service twice, for London and Beijing, without waiting for results<\/li><li>combine the results into a sequence of forecasts<\/li><li>add every forecast in the sequence into a list<\/li><li>send the complete list when all results processed<\/li><li>send an error result in case of an exception<\/li><li>register the handlers with the <code>subscribe<\/code> method<\/li><\/ul>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">private Flowable&lt;Forecast&gt; getTemperature(<span class=\"hljs-built_in\">String<\/span> location) {\n  <span class=\"hljs-keyword\">return<\/span> temperatureTarget\n    .register(RxFlowableInvokerProvider.class)\n    .resolveTemplate(<span class=\"hljs-string\">\"city\"<\/span>, location)\n    .request()\n    .rx(RxFlowableInvoker.class)\n    .get(Temperature.class)\n    .map(temperature -&gt; <span class=\"hljs-keyword\">new<\/span> Forecast(location, temperature));\n}\n\n@GET\n@Produces(MediaType.APPLICATION_JSON)\npublic <span class=\"hljs-keyword\">void<\/span> getForecasts(@Suspended AsyncResponse asyncResponse) {\n  List&lt;Forecast&gt; forecasts = <span class=\"hljs-keyword\">new<\/span> ArrayList&lt;&gt;();\n  asyncResponse.setTimeout(<span class=\"hljs-number\">5<\/span>, TimeUnit.MINUTES);\n  Flowable.concat(getTemperature(<span class=\"hljs-string\">\"London\"<\/span>), getTemperature(<span class=\"hljs-string\">\"Beijing\"<\/span>))\n    .doOnNext(forecast -&gt; {\n      forecasts.add(forecast);\n    })\n  .doOnComplete(() -&gt; {\n    asyncResponse.resume(Response.ok(forecasts).build());\n  })\n  .doOnError(asyncResponse::resume)\n  .subscribe();\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Republished at<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/dzone.com\/articles\/speed-up-services-with-reactive-api-in-java-ee-8\">DZone.com<\/a><\/li><li><a href=\"https:\/\/www.javacodegeeks.com\/2018\/06\/speed-services-reactive-api.html\">JavaCodeGeeks.com<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<div class=\"seriesmeta\">This entry is part 1 of 1 in the series <a href=\"https:\/\/ondro.inginea.eu\/index.php\/series\/java-ee-8-microservices\/\" class=\"series-175\" title=\"Java EE 8 Microservices\">Java EE 8 Microservices<\/a><\/div><p>Services can often be optimized with asynchronous processing even without changing their behavior towards the outside world. The reason why some services aren&#8217;t efficient is that they need to wait for other services to provide a result to continue further. Let&#8217;s look how to call external REST services without waiting for them and also do [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[196],"tags":[176,118,178],"series":[175],"class_list":["post-678","post","type-post","status-publish","format-standard","hentry","category-ee-rest","tag-microservices","tag-reactive","tag-rest","series-java-ee-8-microservices"],"jetpack_publicize_connections":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Speed Up Services With Reactive API in Java EE 8 - .Lost in Coding<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Speed Up Services With Reactive API in Java EE 8 - .Lost in Coding\" \/>\n<meta property=\"og:description\" content=\"Services can often be optimized with asynchronous processing even without changing their behavior towards the outside world. The reason why some services aren&#8217;t efficient is that they need to wait for other services to provide a result to continue further. Let&#8217;s look how to call external REST services without waiting for them and also do [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/\" \/>\n<meta property=\"og:site_name\" content=\".Lost in Coding\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ondrej.mihalyi\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/ondrej.mihalyi\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-27T01:02:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-11-07T03:37:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/ondro.inginea.eu\/wp-content\/uploads\/2021\/09\/duke-CloudSurf-small-e1637277171314.png?fit=300%2C202&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"202\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ondro Mih\u00e1lyi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/OndroMih\" \/>\n<meta name=\"twitter:site\" content=\"@OndroMih\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ondro Mih\u00e1lyi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/\"},\"author\":{\"name\":\"Ondro Mih\u00e1lyi\",\"@id\":\"https:\/\/ondro.inginea.eu\/#\/schema\/person\/07ac1158ec74720744f7146572215616\"},\"headline\":\"Speed Up Services With Reactive API in Java EE 8\",\"datePublished\":\"2018-06-27T01:02:02+00:00\",\"dateModified\":\"2021-11-07T03:37:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/\"},\"wordCount\":757,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/ondro.inginea.eu\/#\/schema\/person\/07ac1158ec74720744f7146572215616\"},\"keywords\":[\"microservices\",\"reactive\",\"REST\"],\"articleSection\":[\"REST\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/\",\"url\":\"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/\",\"name\":\"Speed Up Services With Reactive API in Java EE 8 - .Lost in Coding\",\"isPartOf\":{\"@id\":\"https:\/\/ondro.inginea.eu\/#website\"},\"datePublished\":\"2018-06-27T01:02:02+00:00\",\"dateModified\":\"2021-11-07T03:37:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ondro.inginea.eu\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Speed Up Services With Reactive API in Java EE 8\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ondro.inginea.eu\/#website\",\"url\":\"https:\/\/ondro.inginea.eu\/\",\"name\":\".Lost in Coding\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/ondro.inginea.eu\/#\/schema\/person\/07ac1158ec74720744f7146572215616\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ondro.inginea.eu\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/ondro.inginea.eu\/#\/schema\/person\/07ac1158ec74720744f7146572215616\",\"name\":\"Ondro Mih\u00e1lyi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ondro.inginea.eu\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/i2.wp.com\/ondro.inginea.eu\/wp-content\/uploads\/2017\/08\/fotoOMsquare3x300.jpg?fit=300%2C300&ssl=1\",\"contentUrl\":\"https:\/\/i2.wp.com\/ondro.inginea.eu\/wp-content\/uploads\/2017\/08\/fotoOMsquare3x300.jpg?fit=300%2C300&ssl=1\",\"width\":300,\"height\":300,\"caption\":\"Ondro Mih\u00e1lyi\"},\"logo\":{\"@id\":\"https:\/\/ondro.inginea.eu\/#\/schema\/person\/image\/\"},\"description\":\"Ondro is a software developer and consultant specializing in combining standard and proven tools to solve new and challenging problems. He's been developing in Java for over 10 years. He\u2019s worked for clients like Payara, LottoLand, Uniqa and others. He has co-founded OmniFish, where he works as a director and Jakarta EE expert. He\u2019s passionate about helping his clients and the wider Java community with their projects based on Jakarta EE and similar technologies. As an experienced Java developer and instructor, he's helped companies build and educate their development teams and improve their development processes. He's a core member of several opensource projects and Jakarta EE specification projects. He\u2019s a frequent conference speaker, leader of the Czech JUG and a Java Champion. Ondro is a regular conference speaker at international conferences. Since 2016, he's presented at the following conferences: \u2022 FOSDEM, Brussels, Belgium 2023) \u2022 JChampionsConf, Online (year 2023) \u2022 EclipseCon, Germany (year 2022) \u2022 GeeCon, Prague, Czechia (years 2016, 2019, 2022) \u2022 JavaLand, Bruehl, Germany (years 2018, 2021) \u2022 JFokus, Stockholm, Sweden (year 2019) \u2022 Devops Con, Munich, Germany (year 2019) \u2022 Oracle CodeOne, San Francisco, USA (years 2018, 2019) \u2022 Devoxx, Antwerp, Belgium (year 2018) \u2022 JPrime, Sofia, Bulgaria (years 2017, 2018) \u2022 Java2Days, Sofia, Bulgaria (years 2016, 2018) \u2022 EclipseCon, France (year 2018) \u2022 JavaOne, San Francisco, USA (years 2016, 2017) \u2022 Oracle Code, Prague, Czechia (year 2017) \u2022 Devoxx, London, UK (year 2017) \u2022 GeeCon, Krakow, Poland (year 2017) \u2022 W-JAX, Munich, Germany (years 2016, 2017) \u2022 Bed-Con, Berlin, Germany (year 2017) \u2022 Oredev, Malmo, Sweden (year 2017) \u2022 Devoxx, Casablanca, Morocco (year 2017) \u2022 Java Developer Days, Krakow, Poland (year 2016)\",\"sameAs\":[\"https:\/\/www.facebook.com\/ondrej.mihalyi\",\"https:\/\/cz.linkedin.com\/in\/mihalyiondrej\",\"https:\/\/twitter.com\/https:\/\/twitter.com\/OndroMih\"],\"url\":\"https:\/\/ondro.inginea.eu\/index.php\/author\/ondrejm\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Speed Up Services With Reactive API in Java EE 8 - .Lost in Coding","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/","og_locale":"en_US","og_type":"article","og_title":"Speed Up Services With Reactive API in Java EE 8 - .Lost in Coding","og_description":"Services can often be optimized with asynchronous processing even without changing their behavior towards the outside world. The reason why some services aren&#8217;t efficient is that they need to wait for other services to provide a result to continue further. Let&#8217;s look how to call external REST services without waiting for them and also do [&hellip;]","og_url":"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/","og_site_name":".Lost in Coding","article_publisher":"https:\/\/www.facebook.com\/ondrej.mihalyi","article_author":"https:\/\/www.facebook.com\/ondrej.mihalyi","article_published_time":"2018-06-27T01:02:02+00:00","article_modified_time":"2021-11-07T03:37:42+00:00","og_image":[{"width":300,"height":202,"url":"https:\/\/i0.wp.com\/ondro.inginea.eu\/wp-content\/uploads\/2021\/09\/duke-CloudSurf-small-e1637277171314.png?fit=300%2C202&ssl=1","type":"image\/png"}],"author":"Ondro Mih\u00e1lyi","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/OndroMih","twitter_site":"@OndroMih","twitter_misc":{"Written by":"Ondro Mih\u00e1lyi","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/#article","isPartOf":{"@id":"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/"},"author":{"name":"Ondro Mih\u00e1lyi","@id":"https:\/\/ondro.inginea.eu\/#\/schema\/person\/07ac1158ec74720744f7146572215616"},"headline":"Speed Up Services With Reactive API in Java EE 8","datePublished":"2018-06-27T01:02:02+00:00","dateModified":"2021-11-07T03:37:42+00:00","mainEntityOfPage":{"@id":"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/"},"wordCount":757,"commentCount":0,"publisher":{"@id":"https:\/\/ondro.inginea.eu\/#\/schema\/person\/07ac1158ec74720744f7146572215616"},"keywords":["microservices","reactive","REST"],"articleSection":["REST"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/","url":"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/","name":"Speed Up Services With Reactive API in Java EE 8 - .Lost in Coding","isPartOf":{"@id":"https:\/\/ondro.inginea.eu\/#website"},"datePublished":"2018-06-27T01:02:02+00:00","dateModified":"2021-11-07T03:37:42+00:00","breadcrumb":{"@id":"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/ondro.inginea.eu\/index.php\/speed-up-services-with-reactive-api-in-java-ee-8\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ondro.inginea.eu\/"},{"@type":"ListItem","position":2,"name":"Speed Up Services With Reactive API in Java EE 8"}]},{"@type":"WebSite","@id":"https:\/\/ondro.inginea.eu\/#website","url":"https:\/\/ondro.inginea.eu\/","name":".Lost in Coding","description":"","publisher":{"@id":"https:\/\/ondro.inginea.eu\/#\/schema\/person\/07ac1158ec74720744f7146572215616"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ondro.inginea.eu\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/ondro.inginea.eu\/#\/schema\/person\/07ac1158ec74720744f7146572215616","name":"Ondro Mih\u00e1lyi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ondro.inginea.eu\/#\/schema\/person\/image\/","url":"https:\/\/i2.wp.com\/ondro.inginea.eu\/wp-content\/uploads\/2017\/08\/fotoOMsquare3x300.jpg?fit=300%2C300&ssl=1","contentUrl":"https:\/\/i2.wp.com\/ondro.inginea.eu\/wp-content\/uploads\/2017\/08\/fotoOMsquare3x300.jpg?fit=300%2C300&ssl=1","width":300,"height":300,"caption":"Ondro Mih\u00e1lyi"},"logo":{"@id":"https:\/\/ondro.inginea.eu\/#\/schema\/person\/image\/"},"description":"Ondro is a software developer and consultant specializing in combining standard and proven tools to solve new and challenging problems. He's been developing in Java for over 10 years. He\u2019s worked for clients like Payara, LottoLand, Uniqa and others. He has co-founded OmniFish, where he works as a director and Jakarta EE expert. He\u2019s passionate about helping his clients and the wider Java community with their projects based on Jakarta EE and similar technologies. As an experienced Java developer and instructor, he's helped companies build and educate their development teams and improve their development processes. He's a core member of several opensource projects and Jakarta EE specification projects. He\u2019s a frequent conference speaker, leader of the Czech JUG and a Java Champion. Ondro is a regular conference speaker at international conferences. Since 2016, he's presented at the following conferences: \u2022 FOSDEM, Brussels, Belgium 2023) \u2022 JChampionsConf, Online (year 2023) \u2022 EclipseCon, Germany (year 2022) \u2022 GeeCon, Prague, Czechia (years 2016, 2019, 2022) \u2022 JavaLand, Bruehl, Germany (years 2018, 2021) \u2022 JFokus, Stockholm, Sweden (year 2019) \u2022 Devops Con, Munich, Germany (year 2019) \u2022 Oracle CodeOne, San Francisco, USA (years 2018, 2019) \u2022 Devoxx, Antwerp, Belgium (year 2018) \u2022 JPrime, Sofia, Bulgaria (years 2017, 2018) \u2022 Java2Days, Sofia, Bulgaria (years 2016, 2018) \u2022 EclipseCon, France (year 2018) \u2022 JavaOne, San Francisco, USA (years 2016, 2017) \u2022 Oracle Code, Prague, Czechia (year 2017) \u2022 Devoxx, London, UK (year 2017) \u2022 GeeCon, Krakow, Poland (year 2017) \u2022 W-JAX, Munich, Germany (years 2016, 2017) \u2022 Bed-Con, Berlin, Germany (year 2017) \u2022 Oredev, Malmo, Sweden (year 2017) \u2022 Devoxx, Casablanca, Morocco (year 2017) \u2022 Java Developer Days, Krakow, Poland (year 2016)","sameAs":["https:\/\/www.facebook.com\/ondrej.mihalyi","https:\/\/cz.linkedin.com\/in\/mihalyiondrej","https:\/\/twitter.com\/https:\/\/twitter.com\/OndroMih"],"url":"https:\/\/ondro.inginea.eu\/index.php\/author\/ondrejm\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6wlb6-aW","jetpack-related-posts":[{"id":13,"url":"https:\/\/ondro.inginea.eu\/index.php\/impressions-from-geecon-in-prague-day-2\/","url_meta":{"origin":678,"position":0},"title":"Impressions from Geecon in Prague &#8211; Day 2","author":"Ondro Mih\u00e1lyi","date":"15 November, 2014","format":false,"excerpt":"The day 2 started earlier than the day before. A bit too early for me. While hurrying to catch the beginning of the first presentation, however, a stranger with a big suitcase passed by me in an even greater hurry, a bit confused about which way to take. I grinned\u2026","rel":"","context":"In &quot;Events &amp; Conferences&quot;","block_context":{"text":"Events &amp; Conferences","link":"https:\/\/ondro.inginea.eu\/index.php\/category\/events-conferences\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":476,"url":"https:\/\/ondro.inginea.eu\/index.php\/what-people-expect-to-see-at-the-conferences\/","url_meta":{"origin":678,"position":1},"title":"What people expect to see at the conferences","author":"Ondro Mih\u00e1lyi","date":"24 January, 2017","format":false,"excerpt":"As a public presenter, I always wonder what kind of presentation should I submit for tech conferences. Knowing what people want to hear about is always important to submit a good talk, and to give a good presentation once the talk is accepted by the conference. Here are some insights\u2026","rel":"","context":"In &quot;Events &amp; Conferences&quot;","block_context":{"text":"Events &amp; Conferences","link":"https:\/\/ondro.inginea.eu\/index.php\/category\/events-conferences\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":365,"url":"https:\/\/ondro.inginea.eu\/index.php\/my-recent-talks-at-jug-in-prague\/","url_meta":{"origin":678,"position":2},"title":"My recent talks at JUG in Prague","author":"Ondro Mih\u00e1lyi","date":"29 July, 2016","format":false,"excerpt":"In June, I had a public presentation at a Java User Group in Prague. It was the first time I gave my new talk about building reactive applications with Java EE. And as a bonus, I wanted to introduce Payara project and how it relates to the GlassFish project.I was\u2026","rel":"","context":"In &quot;Events &amp; Conferences&quot;","block_context":{"text":"Events &amp; Conferences","link":"https:\/\/ondro.inginea.eu\/index.php\/category\/events-conferences\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/img.youtube.com\/vi\/ZdhGuoTYOIE\/0.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":286,"url":"https:\/\/ondro.inginea.eu\/index.php\/building-a-new-productive-team-around-java-ee-7\/","url_meta":{"origin":678,"position":3},"title":"Building a new productive team around Java&nbsp;EE&nbsp;7","author":"Ondro Mih\u00e1lyi","date":"18 April, 2016","format":false,"excerpt":"Anton Smutn\u00fd is a software engineering manager at Muehlbauer Group, an international industrial company specializing in wide array of technologies. At the technology center located in Nitra, Slovakia, they are building a new agile Java team to fulfil growing internal needs for innovation and automation. Their team approached me to\u2026","rel":"","context":"In &quot;Interviews&quot;","block_context":{"text":"Interviews","link":"https:\/\/ondro.inginea.eu\/index.php\/category\/interviews\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":157,"url":"https:\/\/ondro.inginea.eu\/index.php\/structure-of-modern-java-ee-application-in-slovak-language\/","url_meta":{"origin":678,"position":4},"title":"[Slovak language] \u0160trukt\u00fara modernej Java EE aplik\u00e1cie","author":"Ondro Mih\u00e1lyi","date":"4 October, 2015","format":false,"excerpt":"Read in Slovak language: \u0160trukt\u00fara modernej Java EE aplik\u00e1cie (Structure of modern Java EE application). \u00a0","rel":"","context":"In &quot;Slovak&quot;","block_context":{"text":"Slovak","link":"https:\/\/ondro.inginea.eu\/index.php\/category\/slovak\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":513,"url":"https:\/\/ondro.inginea.eu\/index.php\/oracle-to-open-javaee-what-to-expect\/","url_meta":{"origin":678,"position":5},"title":"Oracle announced to open JavaEE &#8211; what to expect in the future?","author":"Ondro Mih\u00e1lyi","date":"26 August, 2017","format":false,"excerpt":"Last week, Oracle announced their intentions to open Java EE and transfer it to an open source foundation to continue its development in a more open way. I've been involved in some email discussions (here and here) and in a conference call organized by Oracle and\u00a0I want to summarize what\u2026","rel":"","context":"In &quot;Opinions&quot;","block_context":{"text":"Opinions","link":"https:\/\/ondro.inginea.eu\/index.php\/category\/opinion\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/ondro.inginea.eu\/index.php\/wp-json\/wp\/v2\/posts\/678"}],"collection":[{"href":"https:\/\/ondro.inginea.eu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ondro.inginea.eu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ondro.inginea.eu\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ondro.inginea.eu\/index.php\/wp-json\/wp\/v2\/comments?post=678"}],"version-history":[{"count":8,"href":"https:\/\/ondro.inginea.eu\/index.php\/wp-json\/wp\/v2\/posts\/678\/revisions"}],"predecessor-version":[{"id":930,"href":"https:\/\/ondro.inginea.eu\/index.php\/wp-json\/wp\/v2\/posts\/678\/revisions\/930"}],"wp:attachment":[{"href":"https:\/\/ondro.inginea.eu\/index.php\/wp-json\/wp\/v2\/media?parent=678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ondro.inginea.eu\/index.php\/wp-json\/wp\/v2\/categories?post=678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ondro.inginea.eu\/index.php\/wp-json\/wp\/v2\/tags?post=678"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/ondro.inginea.eu\/index.php\/wp-json\/wp\/v2\/series?post=678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}