January 2018
Intermediate to advanced
350 pages
9h 7m
English
The easiest implementation of a failover is switching to another system when an error occurs. This is what we saw in the previous section with load balancing. The only condition for us to be able to implement a failover is to be able to identify the error encountered by the system.
Here is an example using the JAX-RS client API of Java EE to illustrate this logic:
@ApplicationScopedpublic class ExternalServiceClient { @Inject private Client client; public Data get() { return Stream.of("http://server1.company.com", "http://server2.company.com") .map(server -> { try { return client.target(server) .path("/api/quote") .request(APPLICATION_JSON_TYPE) .get(Data.class); } catch (final WebApplicationException wae) {
Read now
Unlock full access