Monat: Juni 2020

Third Step – JEE Microservices with MicroProfile-Rest-Client

Blog

Third Step - JEE Microservices with MicroProfile-Rest-Client

...as JBoss modules. <dependency> ...
...JBoss modules. <dependency> ...
...modules. <dependency> ...
... ...
... ...
... ...
... ...
... ...
... <groupId>org.eclipse.microprofile.config</groupId> ...
... <groupId>org.eclipse.microprofile.config</groupId> ...
... <groupId>org.eclipse.microprofile.config</groupId> ...
... <groupId>org.eclipse.microprofile.config</groupId> ...
... <groupId>org.eclipse.microprofile.config</groupId> ...
...<groupId>org.eclipse.microprofile.config</groupId> ...
... ...
... ...
... ...
... ...
... ...
... <artifactId>microprofile-rest-client-api</artifactId> ...
... <artifactId>microprofile-rest-client-api</artifactId> ...
... <artifactId>microprofile-rest-client-api</artifactId> ...
... <artifactId>microprofile-rest-client-api</artifactId> ...
... <artifactId>microprofile-rest-client-api</artifactId> ...
...<artifactId>microprofile-rest-client-api</artifactId> ...
... ...
... ...
... ...
... ...
... ...
... <version>${version.microprofile.rest.client}</version> ...
... <version>${version.microprofile.rest.client}</version> ...
... <version>${version.microprofile.rest.client}</version> ...
... <version>${version.microprofile.rest.client}</version> ...
... <version>${version.microprofile.rest.client}</version> ...
...<version>${version.microprofile.rest.client}</version> ...
... ...
... ...
... ...
... ...
... ...
... <scope>provided</scope> ...
... <scope>provided</scope> ...
... <scope>provided</scope> ...
... <scope>provided</scope> ...
... <scope>provided</scope> ...
...<scope>provided</scope> ...
... ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
...</dependency> ...
... ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
...<dependency> ...
... ...
... ...
... ...
... ...
... ...
... <groupId>org.eclipse.microprofile.config</groupId> ...
... <groupId>org.eclipse.microprofile.config</groupId> ...
... <groupId>org.eclipse.microprofile.config</groupId> ...
... <groupId>org.eclipse.microprofile.config</groupId> ...
... <groupId>org.eclipse.microprofile.config</groupId> ...
...<groupId>org.eclipse.microprofile.config</groupId> ...
... ...
... ...
... ...
... ...
... ...
... <artifactId>microprofile-config-api</artifactId> ...
... <artifactId>microprofile-config-api</artifactId> ...
... <artifactId>microprofile-config-api</artifactId> ...
... <artifactId>microprofile-config-api</artifactId> ...
... <artifactId>microprofile-config-api</artifactId> ...
...<artifactId>microprofile-config-api</artifactId> ...
... ...
... ...
... ...
... ...
... ...
... <version>${version.microprofile.config}</version> ...
... <version>${version.microprofile.config}</version> ...
... <version>${version.microprofile.config}</version> ...
... <version>${version.microprofile.config}</version> ...
... <version>${version.microprofile.config}</version> ...
...<version>${version.microprofile.config}</version> ...
... ...
... ...
... ...
... ...
... ...
... <scope>provided</scope> ...
... <scope>provided</scope> ...
... <scope>provided</scope> ...
... <scope>provided</scope> ...
... <scope>provided</scope> ...
...<scope>provided</scope> ...
... ...
... </dependency> Integration ...
... </dependency> Integration with ...
... </dependency> Integration with Thorntail ...
...MicroProfile-Rest-Client and MicroProfile-Config. <dependencyManagement> ...
...and MicroProfile-Config. <dependencyManagement> ...
...MicroProfile-Config. <dependencyManagement> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <dependencies> ...
... <dependencies> ...
... <dependencies> ...
... <dependencies> ...
... <dependencies> ...
...<dependencies> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
...<dependency> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <groupId>io.thorntail</groupId> ...
... <groupId>io.thorntail</groupId> ...
... <groupId>io.thorntail</groupId> ...
... <groupId>io.thorntail</groupId> ...
... <groupId>io.thorntail</groupId> ...
...<groupId>io.thorntail</groupId> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <artifactId>bom</artifactId> ...
... <artifactId>bom</artifactId> ...
... <artifactId>bom</artifactId> ...
... <artifactId>bom</artifactId> ...
... <artifactId>bom</artifactId> ...
...<artifactId>bom</artifactId> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <version>${version.thorntail}</version> ...
... <version>${version.thorntail}</version> ...
... <version>${version.thorntail}</version> ...
... <version>${version.thorntail}</version> ...
... <version>${version.thorntail}</version> ...
...<version>${version.thorntail}</version> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <scope>import</scope> ...
... <scope>import</scope> ...
... <scope>import</scope> ...
... <scope>import</scope> ...
... <scope>import</scope> ...
...<scope>import</scope> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <type>pom</type> ...
... <type>pom</type> ...
... <type>pom</type> ...
... <type>pom</type> ...
... <type>pom</type> ...
...<type>pom</type> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
...</dependency> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... </dependencies> ...
... </dependencies> ...
... </dependencies> ...
... </dependencies> ...
... </dependencies> ...
...</dependencies> ...
... ...
... ...
... ...
... ...
... ...
... </dependencyManagement> ...
... </dependencyManagement> ...
... </dependencyManagement> ...
... </dependencyManagement> ...
... </dependencyManagement> ...
...</dependencyManagement> ...
... ...
... ...
... ...
... ...
... ...
... <dependencies> ...
... <dependencies> ...
... <dependencies> ...
... <dependencies> ...
... <dependencies> ...
...<dependencies> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
...<dependency> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <groupId>io.thorntail</groupId> ...
... <groupId>io.thorntail</groupId> ...
... <groupId>io.thorntail</groupId> ...
... <groupId>io.thorntail</groupId> ...
... <groupId>io.thorntail</groupId> ...
...<groupId>io.thorntail</groupId> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <artifactId>microprofile-config</artifactId> ...
... <artifactId>microprofile-config</artifactId> ...
... <artifactId>microprofile-config</artifactId> ...
... <artifactId>microprofile-config</artifactId> ...
... <artifactId>microprofile-config</artifactId> ...
...<artifactId>microprofile-config</artifactId> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
...</dependency> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
...<dependency> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <groupId>io.thorntail</groupId> ...
... <groupId>io.thorntail</groupId> ...
... <groupId>io.thorntail</groupId> ...
... <groupId>io.thorntail</groupId> ...
... <groupId>io.thorntail</groupId> ...
...<groupId>io.thorntail</groupId> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <artifactId>microprofile-restclient</artifactId> ...
... <artifactId>microprofile-restclient</artifactId> ...
... <artifactId>microprofile-restclient</artifactId> ...
... <artifactId>microprofile-restclient</artifactId> ...
... <artifactId>microprofile-restclient</artifactId> ...
...<artifactId>microprofile-restclient</artifactId> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
...</dependency> ...
... ...
... ...
... ...
... ...
... ...
... </dependencies> Integration ...
... </dependencies> Integration with ...
... </dependencies> Integration with Quarkus ...
...specific Quarkus version. <dependencyManagement> ...
...Quarkus version. <dependencyManagement> ...
...version. <dependencyManagement> ...
... ...
... <dependencies> ...
... <dependencies> ...
... <dependencies> ...
... <dependencies> ...
... <dependencies> ...
...<dependencies> ...
... ...
... ...
... ...
... ...
... ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
...<dependency> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <groupId>io.quarkus</groupId> ...
... <groupId>io.quarkus</groupId> ...
... <groupId>io.quarkus</groupId> ...
... <groupId>io.quarkus</groupId> ...
... <groupId>io.quarkus</groupId> ...
...<groupId>io.quarkus</groupId> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <artifactId>quarkus-bom</artifactId> ...
... <artifactId>quarkus-bom</artifactId> ...
... <artifactId>quarkus-bom</artifactId> ...
... <artifactId>quarkus-bom</artifactId> ...
... <artifactId>quarkus-bom</artifactId> ...
...<artifactId>quarkus-bom</artifactId> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <version>${quarkus.version}</version> ...
... <version>${quarkus.version}</version> ...
... <version>${quarkus.version}</version> ...
... <version>${quarkus.version}</version> ...
... <version>${quarkus.version}</version> ...
...<version>${quarkus.version}</version> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <type>pom</type> ...
... <type>pom</type> ...
... <type>pom</type> ...
... <type>pom</type> ...
... <type>pom</type> ...
...<type>pom</type> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <scope>import</scope> ...
... <scope>import</scope> ...
... <scope>import</scope> ...
... <scope>import</scope> ...
... <scope>import</scope> ...
...<scope>import</scope> ...
... ...
... ...
... ...
... ...
... ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
...</dependency> ...
... ...
... </dependencies> ...
... </dependencies> ...
... </dependencies> ...
... </dependencies> </dependencyManagement> ...
... </dependencies> </dependencyManagement> ...
...</dependencies> </dependencyManagement> ...
... </dependencyManagement> <dependencies> ...
... </dependencyManagement> <dependencies> ...
... <dependencies> ...
... <dependencies> <!-- ...
...<dependencies> <!-- MicroProfile-Config ...
... <!-- MicroProfile-Config is ...
...of configuring ...
...configuring ...
... ...
... ...
... ...
... ...
... Quarkus, ...
... Quarkus, so ...
... Quarkus, so there ...
...a dependency --> ...
...dependency --> ...
...--> ...
... ...
... ...
... ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <groupId>io.quarkus</groupId> ...
... <groupId>io.quarkus</groupId> ...
... <groupId>io.quarkus</groupId> ...
... <groupId>io.quarkus</groupId> ...
... <groupId>io.quarkus</groupId> ...
...<groupId>io.quarkus</groupId> ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... <artifactId>quarkus-rest-client</artifactId> ...
... <artifactId>quarkus-rest-client</artifactId> ...
... <artifactId>quarkus-rest-client</artifactId> ...
... <artifactId>quarkus-rest-client</artifactId> ...
... <artifactId>quarkus-rest-client</artifactId> ...
...<artifactId>quarkus-rest-client</artifactId> ...
... ...
... ...
... ...
... ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
... </dependency> </dependencies> How to ...
... </dependency> </dependencies> How to implement ...
...#################################################### @RegisterRestClient(configKey = "restClient") @RegisterClientHeaders(ClientHeaders.class) @RegisterProviders({ ...
...= "restClient") @RegisterClientHeaders(ClientHeaders.class) @RegisterProviders({ ...
..."restClient") @RegisterClientHeaders(ClientHeaders.class) @RegisterProviders({ ...
... ...
... @RegisterProvider(Provider.class) }) // ...
... @RegisterProvider(Provider.class) }) // #################################################### @Path("/") public ...
... @RegisterProvider(Provider.class) }) // #################################################### @Path("/") public interface ...
...interface ExternalRestResource { @Path("/get") ...
...ExternalRestResource { @Path("/get") ...
...{ @Path("/get") ...
... @Path("/get") @GET ...
... @Path("/get") @GET ...
...@Path("/get") @GET ...
... @GET @Produces(MediaType.APPLICATION_JSON) ...
... @GET @Produces(MediaType.APPLICATION_JSON) ...
...@GET @Produces(MediaType.APPLICATION_JSON) ...
... @Produces(MediaType.APPLICATION_JSON) String ...
... @Produces(MediaType.APPLICATION_JSON) String get(); } The ...
...@Produces(MediaType.APPLICATION_JSON) String get(); } The following ...
...implements ClientHeadersFactory { @Override ...
...ClientHeadersFactory { @Override ...
...{ @Override ...
... @Override public ...
... @Override public MultivaluedMap<String, ...
...@Override public MultivaluedMap<String, String> ...
...MultivaluedMap<String, String> ...
...String> ...
... ...
... update(MultivaluedMap<String, ...
... update(MultivaluedMap<String, String> ...
... update(MultivaluedMap<String, String> incomingHeaders, ...
...update(MultivaluedMap<String, String> incomingHeaders, ...
...String> incomingHeaders, ...
...incomingHeaders, ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... MultivaluedMap<String, ...
... MultivaluedMap<String, String> ...
... MultivaluedMap<String, String> clientOutgoingHeaders) ...
...String> clientOutgoingHeaders) { ...
...clientOutgoingHeaders) { ...
...{ ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... // ...
... // Will ...
... // Will be ...
...with outgoing headers ...
...outgoing headers ...
...headers ...
... ...
... return ...
... return new ...
... return new MultivaluedHashMap<>() ...
...new MultivaluedHashMap<>() {{ ...
...MultivaluedHashMap<>() {{ ...
...{{ ...
... ...
... ...
... ...
... ...
... ...
... put("X-Test", ...
... put("X-Test", Collections.singletonList("test ...
... put("X-Test", Collections.singletonList("test header")); ...
...put("X-Test", Collections.singletonList("test header")); ...
...Collections.singletonList("test header")); ...
...header")); ...
... ...
... }}; ...
... }}; ...
... }}; ...
... }}; } }   This ...
... }}; } }   This implementation ...
...}}; } }   This implementation has ...
...the @RegisterClientHeaders annotation. <dependencyManagement> <dependencies> ...
...annotation. <dependencyManagement> <dependencies> ...
... <dependencies> ...
...<dependencies> ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
... <dependency> ...
...<dependency> ...
... ...
... ...
... ...
... ...
... <groupId>io.quarkus</groupId> ...
... <groupId>io.quarkus</groupId> ...
... <groupId>io.quarkus</groupId> ...
... <groupId>io.quarkus</groupId> ...
... <groupId>io.quarkus</groupId> ...
...<groupId>io.quarkus</groupId> ...
... ...
... ...
... ...
... ...
... <artifactId>quarkus-bom</artifactId> ...
... <artifactId>quarkus-bom</artifactId> ...
... <artifactId>quarkus-bom</artifactId> ...
... <artifactId>quarkus-bom</artifactId> ...
... <artifactId>quarkus-bom</artifactId> ...
...<artifactId>quarkus-bom</artifactId> ...
... ...
... ...
... ...
... ...
... <version>${quarkus.version}</version> ...
... <version>${quarkus.version}</version> ...
... <version>${quarkus.version}</version> ...
... <version>${quarkus.version}</version> ...
... <version>${quarkus.version}</version> ...
...<version>${quarkus.version}</version> ...
... ...
... ...
... ...
... ...
... <type>pom</type> ...
... <type>pom</type> ...
... <type>pom</type> ...
... <type>pom</type> ...
... <type>pom</type> ...
...<type>pom</type> ...
... ...
... ...
... ...
... ...
... <scope>import</scope> ...
... <scope>import</scope> ...
... <scope>import</scope> ...
... <scope>import</scope> ...
... <scope>import</scope> ...
...<scope>import</scope> ...
... </dependency> ...
... </dependency> ...
... </dependency> ...
... </dependency> </dependencies> ...
... </dependency> </dependencies> </dependencyManagement> ...
... </dependencies> </dependencyManagement> <dependencies> ...
...</dependencies> </dependencyManagement> <dependencies> ...
...</dependencyManagement> <dependencies> ...
... <dependencies> ...
...<dependencies> ...
... ...
... <!-- ...
... <!-- Does ...
... <!-- Does not ...
...dependency defined. ...
...defined. ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... It ...
... It uses ...
... It uses Smallrye ...
...implementation of ...
...of ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... the ...
... the MicroProfile-Config ...
... the MicroProfile-Config as ...
...as default ...
...default ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... for ...
... for configurations ...
... for configurations --> ...
...for configurations --> </dependencies> ExceptionMapping MicroProfile-Rest-Client provides the ...
...RestClientExceptionMapper implements ...
...implements ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ResponseExceptionMapper<RuntimeException> ...
... ResponseExceptionMapper<RuntimeException> { ...
... ResponseExceptionMapper<RuntimeException> { ...
... ResponseExceptionMapper<RuntimeException> { @Override ...
...ResponseExceptionMapper<RuntimeException> { @Override ...
...{ @Override ...
... @Override public ...
... @Override public RuntimeException ...
...@Override public RuntimeException toThrowable(Response ...
...toThrowable(Response response) { ...
...response) { ...
...{ ...
... ...
... return ...
... return new ...
... return new RuntimeException(“Error ...
...occurred ” ...
...” ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... ...
... + ...
... + response.getStatus()); ...
... + response.getStatus()); ...
... + response.getStatus()); } } There ...
...+ response.getStatus()); } } There are ...
...response.getStatus()); } } There are two ...
...interface ExternalRestResource { ... } @RequestScoped public ...
...ExternalRestResource { ... } @RequestScoped public class ...
...{ ... } @RequestScoped public class CDIBean ...
...class CDIBean { @Inject ...
...CDIBean { @Inject ...
...{ @Inject ...
... @Inject @RestClient ...
... @Inject @RestClient ...
...@Inject @RestClient ...
... @RestClient ExternalRestResource ...
... @RestClient ExternalRestResource externalRestResource; } RestClientBuilder If ...
...@RestClient ExternalRestResource externalRestResource; } RestClientBuilder If dynamic ...
...CDI Producer method. RestClientBuilder.newBuilder() ...
...Producer method. RestClientBuilder.newBuilder() ...
...method. RestClientBuilder.newBuilder() ...
... ...
... ...
... ...
... .baseUri(new ...
... .baseUri(new URI(baseUrl)) ...
... .baseUri(new URI(baseUrl)) ...
... .baseUri(new URI(baseUrl)) ...
....baseUri(new URI(baseUrl)) ...
...URI(baseUrl)) ...
... ...
... ...
... ...
... .readTimeout(connectTimeout, ...
... .readTimeout(connectTimeout, TimeUnit.SECONDS) ...
... .readTimeout(connectTimeout, TimeUnit.SECONDS) ...
... .readTimeout(connectTimeout, TimeUnit.SECONDS) ...
....readTimeout(connectTimeout, TimeUnit.SECONDS) ...
...TimeUnit.SECONDS) ...
... ...
... ...
... ...
... .connectTimeout(connectTimeout, ...
... .connectTimeout(connectTimeout, TimeUnit.SECONDS) ...
... .connectTimeout(connectTimeout, TimeUnit.SECONDS) ...
... .connectTimeout(connectTimeout, TimeUnit.SECONDS) ...
....connectTimeout(connectTimeout, TimeUnit.SECONDS) ...
...TimeUnit.SECONDS) ...
... ...
... ...
... ...
... .register(ClientTracingFeature.class) ...
... .register(ClientTracingFeature.class) ...
... .register(ClientTracingFeature.class) ...
... .register(ClientTracingFeature.class) ...
... .register(ClientTracingFeature.class) ...
....register(ClientTracingFeature.class) ...
... ...
... ...
... ...
... .build(ExternalRestResource.class); It ...
... .build(ExternalRestResource.class); It is ...
... .build(ExternalRestResource.class); It is fairly ...

Anzeigen