Chapter 2. Understand Eclipse MicroProfile
2.1. Eclipse MicroProfile Config
2.1.1. Eclipse MicroProfile Config in JBoss EAP
Configuration data can change dynamically and applications need to be able to access the latest configuration information without restarting the server.
Eclipse MicroProfile Config provides portable externalization of configuration data. This means, you can configure applications and microservices to run in multiple environments without modification or repackaging.
Eclipse MicroProfile Config functionality is implemented in JBoss EAP using the SmallRye Config component and is provided by the
microprofile-config-smallrye subsystem. This subsystem is included in the default JBoss EAP 7.3 configuration.
2.1.2. Eclipse MicroProfile Config sources supported in Eclipse MicroProfile Config
Eclipse MicroProfile Config configuration properties can come from different locations and can be in different formats. These properties are provided by ConfigSources. ConfigSources are implementations of the
The Eclipse MicroProfile Config specification provides the following default
ConfigSource implementations for retrieving configuration values:
META-INF/microprofile-config.propertiesfiles on the class path.
microprofile-config-smallrye subsystem supports additional types of
ConfigSource resources for retrieving configuration values. You can also retrieve the configuration values from the following resources:
Properties in a
- Files in a directory
2.2. Eclipse MicroProfile Fault Tolerance
2.2.1. About Eclipse MicroProfile Fault Tolerance specification
The Eclipse MicroProfile Fault Tolerance specification defines strategies to deal with errors inherent in distributed microservices.
The Eclipse MicroProfile Fault Tolerance specification defines the following strategies to handle errors:
- Define the amount of time within which an execution must finish. Defining a timeout prevents waiting for an execution indefinitely.
- Define the criteria for retrying a failed execution.
- Provide an alternative in the case of a failed execution.
- Define the number of failed execution attempts before temporarily stopping. You can define the length of the delay before resuming execution.
- Isolate failures in part of the system so that the rest of the system can still function.
- Execute client request in a separate thread.
2.2.2. Eclipse MicroProfile Fault Tolerance in JBoss EAP
microprofile-fault-tolerance-smallrye subsystem provides support for Eclipse MicroProfile Fault Tolerance in JBoss EAP. The subsystem is available only in the JBoss EAP XP stream.
microprofile-fault-tolerance-smallrye subsystem provides the following annotations for interceptor bindings:
You can bind these annotations at the class level or at the method level. An annotation bound to a class applies to all of the business methods of that class.
The following rules apply to binding interceptors:
If a component class declares or inherits a class-level interceptor binding, the following restrictions apply:
- The class must not be declared final.
- The class must not contain any static, private, or final methods.
- If a non-static, non-private method of a component class declares a method level interceptor binding, neither the method nor the component class may be declared final.
Fault tolerance operations have the following restrictions:
- Fault tolerance interceptor bindings must be applied to a bean class or bean class method.
- When invoked, the invocation must be the business method invocation as defined in CDI specification.
An operation is not considered fault tolerant if both of the following conditions are true:
- The method itself is not bound to any fault tolerance interceptor.
- The class containing the method is not bound to any fault tolerance interceptor.
microprofile-fault-tolerance-smallrye subsystem provides the following configuration options, in addition to the configuration options provided by Eclipse MicroProfile Fault Tolerance:
2.3. Eclipse MicroProfile Health
2.3.1. Eclipse MicroProfile Health in JBoss EAP
JBoss EAP includes the SmallRye Health component, which you can use to determine whether the JBoss EAP instance is responding as expected. This capability is enabled by default.
Eclipse MicroProfile Health is only available when running JBoss EAP as a standalone server.
The Eclipse MicroProfile Health specification defines the following health checks:
Determines whether an application is ready to process requests. The annotation
@Readinessprovides this health check.
Determines whether an application is running. The annotation
@Livenessprovides this health check.
@Health annotation defined in previous versions of Eclipse MicroProfile Health specification is deprecated.
By default, the
microprofile-health-smallrye subsystem only examines whether the server is running. The
:empty-liveness-checks-status management attributes specify the global status when no
liveness probes are defined.
2.4. Eclipse MicroProfile JWT
2.4.1. Eclipse MicroProfile JWT integration in JBoss EAP
microprofile-jwt-smallrye provides Eclipse MicroProfile JWT integration in JBoss EAP.
The following functionalities are provided by the
- Detecting deployments that use Eclipse MicroProfile JWT security.
- Activating support for Eclipse MicroProfile JWT.
The subsystem contains no configurable attributes or resources.
In addition to the
microprofile-jwt-smallrye subsystem, the
org.eclipse.microprofile.jwt.auth.api module provides Eclipse MicroProfile JWT integration in JBoss EAP.
2.4.2. Differences between a traditional deployment and an Eclipse MicroProfile JWT deployment
Eclipse MicroProfile JWT deployments do not depend on managed SecurityDomain resources like traditional JBoss EAP deployments. Instead, a virtual SecurityDomain is created and used across the Eclipse MicroProfile JWT deployment.
As the Eclipse MicroProfile JWT deployment is configured entirely within the Eclipse MicroProfile Config properties and the
microprofile-jwt-smallrye subsystem, the virtual SecurityDomain does not need any other managed configuration for the deployment.
2.4.3. Eclipse MicroProfile JWT activation in JBoss EAP
Eclipse MicroProfile JWT is activated for applications based on the presence of an
auth-method in the application.
The Eclipse MicroProfile JWT integration is activated for an application in the following way:
As part of the deployment process, JBoss EAP scans the application archive for the presence of an
auth-methodis present and defined as
MP-JWT, the Eclipse MicroProfile JWT integration is activated.
auth-method can be specified in either or both of the following files:
the file containing the class that extends
javax.ws.rs.core.Application, annotated with the
auth-method is defined both in a class, using annotation, and in the web.xml configuration file, the definition in
web.xml configuration file is used.
2.4.4. Limitations of Eclipse MicroProfile JWT in JBoss EAP
The Eclipse MicroProfile JWT implementation in JBoss EAP has certain limitations.
The following limitations of Eclipse MicroProfile JWT implementation exist in JBoss EAP:
The Eclipse MicroProfile JWT implementation parses only the first key from the JSON Web Key Set (JWKS) supplied in the
mp.jwt.verify.publickeyproperty. Therefore, if a token claims to be signed by the second key or any key after the second key, the token fails verification and the request containing the token is not authorized.
- Base64 encoding of JWKS is not supported.
In both cases, a clear text JWKS can be referenced instead of using the
mp.jwt.verify.publickey.location config property.
2.5. Eclipse MicroProfile Metrics
2.5.1. Eclipse MicroProfile Metrics in JBoss EAP
JBoss EAP includes the SmallRye Metrics component. The SmallRye Metrics component provides the Eclipse MicroProfile Metrics functionality using the
microprofile-metrics-smallrye subsystem provides monitoring data for the JBoss EAP instance. The subsystem is enabled by default.
microprofile-metrics-smallrye subsystem is only enabled in standalone configurations.
2.6. Eclipse MicroProfile OpenAPI
2.6.1. Eclipse MicroProfile OpenAPI in JBoss EAP
Eclipse MicroProfile OpenAPI is integrated in JBoss EAP using the
The Eclipse MicroProfile OpenAPI specification defines an HTTP endpoint that serves an OpenAPI 3.0 document. The OpenAPI 3.0 document describes the REST services for the host. The OpenAPI endpoint is registered using the configured path, for example http://localhost:8080/openapi, local to the root of the host associated with a deployment.
Currently, the OpenAPI endpoint for a virtual host can only document a single deployment. To use OpenAPI with multiple deployments registered with different context paths on the same virtual host, each deployment must use a distinct endpoint path.
The OpenAPI endpoint returns a YAML document by default. You can also request a JSON document using an Accept HTTP header, or a format query parameter.
If the Undertow server or host of a given application defines an HTTPS listener then the OpenAPI document is also available using HTTPS. For example, an endpoint for HTTPS is https://localhost:8443/openapi.
2.7. Eclipse MicroProfile OpenTracing
2.7.1. Eclipse MicroProfile OpenTracing
The ability to trace requests across service boundaries is important, especially in a microservices environment where a request can flow through multiple services during its life cycle.
The Eclipse MicroProfile OpenTracing specification defines behaviors and an API for accessing an OpenTracing compliant
Tracer interface within a CDI-bean application. The
Tracer interface automatically traces JAX-RS applications.
The behaviors specify how OpenTracing Spans are created automatically for incoming and outgoing requests. The API defines how to explicitly disable or enable tracing for given endpoints.
2.7.2. Eclipse MicroProfile OpenTracing in EAP
You can use the
microprofile-opentracing-smallrye subsystem to specify environment variables that trace Jakarta EE applications. This subsystem uses the SmallRye OpenTracing component to provide the Eclipse MicroProfile OpenTracing functionality for JBoss EAP.
MicroProfile 1.3.0 supports tracing requests for applications. You can configure the default Jaeger Java Client tracer, plus a set of instrumentation libraries for components commonly used in Jakarta EE, to set system properties or environment variables.
Each individual WAR deployed to the JBoss EAP server automatically has its own
Tracer instance. Each WAR within an EAR is treated as an individual WAR, and each has its own
Tracer instance. By default, the service name used with the Jaeger Client is derived from the deployment’s name, which is usually the WAR file name.
microprofile-opentracing-smallrye subsystem, you can configure the Jaeger Java Client by setting system properties or environment variables.
Configuring the Jeager Client tracer using system properties and environment variables is provided as a Technology Preview. The system properties and environment variables affiliated with the Jeager Client tracer might change and become incompatible with each other in future releases.
By default, the probabilistic sampling strategy of the Jaeger Client for Java is set to
0.001, meaning that only approximately one in one thousand traces are sampled. To sample every request, set the system properties
- For more information about SmallRye OpenTracing functionality, see the SmallRye OpenTracing component.
- For more information about the default tracer, see the Jaeger Java Client.
For more information about the
- For more information about overriding the default tracer and tracing CDI beans, see Using Eclipse MicroProfile OpenTracing to Trace Requests in the Development Guide.
- For more information about configuring the Jaeger Client, see the Jaeger documentation.
- For more information about valid system properties, see Configuration via Environment in the Jaeger documentation.
2.8. Eclipse MicroProfile REST Client
2.8.1. MicroProfile REST client
JBoss EAP XP 1.0.0 supports the MicroProfile REST client 1.4.x that builds on JAX-RS 2.1 client APIs to provide a type-safe approach to invoke RESTful services over HTTP. The MicroProfile Type Safe REST clients are defined as Java interfaces. With the MicroProfile REST clients, you can write client applications with executable code.
Use the MicroProfile REST client to avail the following capabilities:
- An intuitive syntax
- Programmatic registration of providers
- Declarative registration of providers
- Declarative specification of headers
- Propagation of headers on the server
- CDI integration
- A comparison between MicroProfile REST client and JAX-RS syntaxes
- Programmatic registration of providers in MicroProfile REST client
- Declarative registration of providers in MicroProfile REST client
- Declarative specification of headers in MicroProfile REST client
- Propagation of headers on the server in MicroProfile REST client
- ResponseExceptionMapper in MicroProfile REST client
- Context dependency injection with MicroProfile REST client