Tolerance with MicroProfile config

As we saw in the previous sections, Fault Tolerance policies are applied by using annotations. For most use cases, this is enough, but for others, this approach may not be satisfactory because configuration is done at the source code level.

That's the reason why the parameters of MicroProfile Fault Tolerance annotations can be overridden using MicroProfile Config.

The annotation parameters can be overwritten via config properties using the following naming convention: <classname>/<methodname>/<annotation>/<parameter>.

To override maxDuration for @Retry on the doSomething method in the MyService class, set the config property like this:

org.example.microservice.MyService/doSomething/Retry/maxDuration=3000

If the parameters for a particular annotation need to be configured with the same value for a particular class, use the <classname>/<annotation>/<parameter> config property for configuration.

For instance, use the following config property to override all maxRetries for @Retry specified on the MyService class to 100:

org.example.microservice.MyService/Retry/maxRetries=100

Sometimes, the parameters need to be configured with the same value for the whole microservice (that is, all occurrences of the annotation in the deployment).

In this circumstance, the <annotation>/<parameter> config property overrides the corresponding parameter value for the specified annotation. For instance, to override all maxRetries for all of @Retry to be 30, specify the following config property:

Retry/maxRetries=30

This brings us to the end of discussion on Fault Tolerance in MicroProfile.