官术网_书友最值得收藏!

The @Fallback policy

The @Fallback annotation can only be applied on a method; annotating a class will give an unexpected result:

@Retry(maxRetries = 2)
@Fallback(StringFallbackHandler.class)
public String shouldFallback() {
...
}

The fallback method is called after the number of retries is reached. In the previous example, the method will be retried twice in case of an error, and then the fallback will be used to invoke another piece of code—in this case, the following StringFallbackHandler class:

import javax.enterprise.context.ApplicationScoped;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.faulttolerance.ExecutionContext;
import org.eclipse.microprofile.faulttolerance.FallbackHandler;

@ApplicationScoped
public class StringFallbackHandler implements FallbackHandler<String> {
@ConfigProperty(name="app1.requestFallbackReply", defaultValue = "Unconfigured Default Reply")
private String replyString;

@Override
public String handle(ExecutionContext ec) {
return replyString;
}
}

Fallback code can be defined by a class implementing the FallbackHandler interface (see the previous code) or by a method in the current bean. In the StringFallbackHandler code, a MicroProfile Config property named app1.requestFallbackReply is used to externalize the application's fallback string value.

主站蜘蛛池模板: 连江县| 友谊县| 黔西| 新蔡县| 天峻县| 门源| 湖北省| 张家界市| 泗洪县| 顺平县| 马山县| 余姚市| 乐山市| 天长市| 辽阳市| 志丹县| 滕州市| 和静县| 武川县| 清丰县| 耒阳市| 迁西县| 靖远县| 福州市| 乐昌市| 霍州市| 甘谷县| 合作市| 图木舒克市| 鄄城县| 威信县| 偃师市| 高密市| 徐水县| 商都县| 泾阳县| 阳信县| 清苑县| 绵竹市| 墨玉县| 宽甸|