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

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.

主站蜘蛛池模板: 丰台区| 古浪县| 西丰县| 隆昌县| 三都| 阳新县| 阿勒泰市| 大余县| 潍坊市| 台中市| 衢州市| 台前县| 慈利县| 三原县| 禹州市| 增城市| 栖霞市| 三门县| 仁寿县| 平塘县| 靖边县| 东山县| 江陵县| 曲阳县| 宜川县| 乌海市| 罗山县| 八宿县| 宾川县| 友谊县| 巴中市| 丰宁| 潮安县| 墨竹工卡县| 诸城市| 余干县| 竹山县| 息烽县| 同江市| 永靖县| 登封市|