Timeouts are crucial for robustness of the communication between reasonable WARs (also known as micro services).
Timeout settings are not standardized and have to be passed as "proprietary" properties of the JAX-RS client:
The "provided" dependency highlighted above can be omitted by using the
import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import org.glassfish.jersey.client.ClientProperties; Client client = ClientBuilder.newClient(); client.property(ClientProperties.CONNECT_TIMEOUT, 100); client.property(ClientProperties.READ_TIMEOUT, 10);
Stringrepresentation of the constants:
Timeouts will cause:
client.property("jersey.config.client.connectTimeout", 100); client.property("jersey.config.client.readTimeout", 10);
java.net.SocketTimeoutException: Read timed outexception which can be easily handled. A few years ago we would talk about exception handling and robustness, in the age of micro services we can call it now "resilience" :-).
Cloudy Jakarta EE and MicroProfile: Microservices, Clouds and Beyond Jakarta EE / MicroProfile airhacks workshops at MUC airport, Winter Edition
airhacks.fm the podcast:
Stay in touch: airhacks.news.