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

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.

主站蜘蛛池模板: 保德县| 临朐县| 乌恰县| 潞城市| 黄龙县| 永德县| 镶黄旗| 东阿县| 朝阳县| 潞城市| 鹿泉市| 房产| 滦平县| 阿图什市| 永年县| 昭苏县| 尼玛县| 曲周县| 莫力| 大城县| 儋州市| 郑州市| 海兴县| 措美县| 八宿县| 临湘市| 夹江县| 全州县| 朝阳县| 贵州省| 洞头县| 绵竹市| 油尖旺区| 洪泽县| 项城市| 麻栗坡县| 平山县| 日照市| 梁平县| 和林格尔县| 柏乡县|