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

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.

主站蜘蛛池模板: 资溪县| 信阳市| 罗定市| 高雄市| 石家庄市| 翼城县| 司法| 精河县| 江川县| 淮阳县| 汝州市| 通化市| 西和县| 罗江县| 保靖县| 清苑县| 北海市| 和林格尔县| 奈曼旗| 西吉县| 嘉禾县| 乌兰县| 昌黎县| 广水市| 张家界市| 玉环县| 沅陵县| 棋牌| 桐乡市| 泗水县| 博爱县| 康定县| 天水市| 杭州市| 南京市| 舟山市| 清河县| 湘潭市| 秭归县| 常熟市| 呼玛县|