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

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.

主站蜘蛛池模板: 运城市| 屯门区| 麻阳| 凯里市| 大荔县| 白河县| 东乡族自治县| 新密市| 林州市| 三门峡市| 即墨市| 安义县| 鸡西市| 天津市| 双柏县| 万州区| 卢氏县| 宝鸡市| 南昌市| 子洲县| 原平市| 横峰县| 安龙县| 肃南| 孟州市| 哈巴河县| 扶绥县| 道真| 含山县| 武宣县| 陇川县| 夏河县| 临海市| 抚州市| 郯城县| 息烽县| 洪雅县| 喜德县| 水城县| 织金县| 长顺县|