Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 59 java ee @ ConfigProperty name server base url private String baseUrl @ Inject @ ConfigProperty name server port private Optional Integer port The given property server base url must be defined in one of the provided configuration sources a DeploymentException will be thrown if no definition exists On the other hand the server port property is defined with Optional so a DeploymentException will not occur if the property is missing in the configuration MicroProfile FaultTolerance The MicroProfile FaultTolerance specification provides strategies for implementing resilient applications Its aim is to separate the execution logic from the execution itself by focusing on features such as TimeOut RetryPolicy Fallback CircuitBreaker and Bulkhead I will describe each concept with code samples Timeout This feature prevents the execution of a microservice from being unresponsive Its vital to have a timeout value defined for a microservice so that an alternative execution mechanism can be applied such as Fallback RetryPolicy CircuitBreaker and so forth Methods annotated with @ Timeout as shown in Listing 5 will have the policy applied and if execution exceeds the given timeout value a TimeoutException will be thrown Annotations can be used at the class level as well in which case the timeout policy is applied to all methods defined within that class Listing 5 @ Timeout 500 timeout is 500 ms public List Recommendation fetchRecommendations Aggregate recommendations
You must have JavaScript enabled to view digital editions.