[[MicroProfile-Fault-Tolerance-SmallRye]]
= MicroProfile Fault Tolerance Subsystem Configuration

Support for https://microprofile.io/project/eclipse/microprofile-fault-tolerance[Eclipse MicroProfile Fault Tolerance] is
provided as by the `microprofile-fault-tolerance-smallrye` subsystem.

[[required-extension-microprofile-fault-tolerance-smallrye]]
== Required Extension

This extension is not included by default in the standard configurations in the WildFly distribution.

You can add the extension to a configuration without it either by adding an
`<extension module="org.wildfly.extension.microprofile.fault-tolerance-smallrye"/>`
element to the XML or by using the following CLI operation:

[source,options="nowrap"]
----
[standalone@localhost:9990 /] /extension=org.wildfly.extension.microprofile.fault-tolerance-smallrye:add
{"outcome" => "success"}

[standalone@localhost:9990 /] /subsystem=microprofile-fault-tolerance-smallrye:add
{
    "outcome" => "success",
    "response-headers" => {
        "operation-requires-reload" => true,
        "process-state" => "reload-required"
    }
}
----

The subsystem does not have any configurable elements.
Configuration of the Hystrix library is done using MicroProfile Config specification.

== Specification

WildFly's MicroProfile Fault Tolerance subsystem implements MicroProfile 2.0.

This MicroProfile specification introduces the following interceptor bindings:

* `@Timeout`
* `@Retry`
* `@Fallback`
* `@CircuitBreaker`
* `@Bulkhead`
* `@Asynchronous`

For usage please refer to MicroProfile Fault Tolerance 2.0 https://download.eclipse.org/microprofile/microprofile-fault-tolerance-2.0/microprofile-fault-tolerance-spec.html[specification].

== Hystrix Configuration

MicroProfile Fault Tolerance extension is implemented by the SmallRye Fault Tolerance project which uses https://github.com/Netflix/Hystrix[Hystrix] as an underlying library.

MicroProfile Config is used to configure Hystrix properties.
The integration module picks up all `hystrix` prefixed properties to configure the library.
Please refer to https://github.com/Netflix/Hystrix/wiki/Configuration[configuration for configurable properties].

NOTE: Deployments can supply configuration for Hystrix using the defined `META-INF/microprofile-config.properties` file.
      However, when multiple MicroProfile Fault Tolerance deployments are deployed in a single WildFly instance and since configuration of Hystrix is singleton
      it is recommended to use globally scoped properties in this case. Please refer to MicroProfile Config subsystem how to configure `ConfigSource`-s.

WARNING: In future version of the server a different underlying library might be used to implement MicroProfile Fault Tolerance
capabilities and thus these properties are subject to change.

// Following caveats are ported from https://github.com/thorntail/thorntail/tree/master/fractions/microprofile/microprofile-fault-tolerance

=== Bulkhead fallback rejection

If you use the `@Bulkhead` pattern together with some `@Fallback` logic to limit the number of concurrent requests, an invocation may still result in an exception.

=== Semaphore Isolation

For semaphore-style `@Bulkhead` a `BulkheadException` may be thrown if the maximum concurrent limit is reached.
To avoid that, configure `hystrix.command.default.fallback.isolation.semaphore.maxConcurrentRequests` property to increase the limit.

=== Thread Isolation

For `@Bulkhead` used together with `@Asynchronous` a `RejectedExecutionException` may be thrown if the maximum concurrent limit is reached.
To avoid that, set the `hystrix.threadpool.default.maximumSize` property to increase the limit and set `hystrix.threadpool.default.allowMaximumSizeToDivergeFromCoreSize` property to `true`.

== Migration from Thorntail

Thorntail (and WildFly swarm) prefixed all Hystrix properties with `thorntail.hystrix.` (or `swarm.hystrix.`) to configure Hystrix.
To migrate these properties, remove the `thorntail.` (or `swarm.hystrix.`) prefix from all configured properties.

== Component Reference

The Eclipse MicroProfile Fault Tolerance is implemented by the SmallRye Fault Tolerance project.

****

* https://microprofile.io/project/eclipse/microprofile-fault-tolerance[Eclipse MicroProfile Fault Tolerance]
* https://github.com/smallrye/smallrye-fault-tolerance[SmallRye Fault Tolerance]

****
