O'Reilly logo

Hands-On Enterprise Java Microservices with Eclipse MicroProfile by Scott Stark, Antoine Sabot-Durand, Pavol Loffay, Jeff Mesnil, Heiko W. Rupp, Cesar Saavedra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required