concept remote service in category spring
appears as: remote services, remote service, remote service

This is an excerpt from Manning's book Spring Microservices in Action, 2E.
The code shown in the following listing quickly demonstrates how the service discovery, and client-side load balancing of remote services were integrated into our “Hello World” example.
Listing 2.1 Hello World Service using Spring Cloud
package com.optima.growth.simpleservice; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; @SpringBootApplication @RestController @RequestMapping(value="hello") @EnableEurekaClient #A public class Application { public static void main(String[] args) { SpringApplication.run(ContactServerAppApplication.class, args); } public String helloRemoteServiceCall(String firstName,String lastName){ RestTemplate restTemplate = new RestTemplate(); ResponseEntity<String> restExchange = restTemplate.exchange( "http://logical-service-id/name/" #B + "{firstName}/{lastName}" ,HttpMethod.GET, null, String.class, firstName, lastName); return restExchange.getBody(); } @RequestMapping(value="/{firstName}/{lastName}",method = RequestMethod.GET) public String hello( @PathVariable("firstName") String firstName, @PathVariable("lastName") String lastName) { return helloRemoteServiceCall(firstName, lastName); } }#A Tells the service that it should register itself with a Eureka service discovery agent and that service calls are to use service discovery to “lookup” the location of remote services
Calls to remote services are usually synchronous and don’t cut short a long-running call. The caller of a service has no concept of a timeout to keep the service call from hanging out forever. The application developer calls the service to perform an action and waits for the service to return.

This is an excerpt from Manning's book Spring Microservices in Action.
The code shown in the following listing quickly demonstrates how the service discovery, circuit breaker, bulkhead, and client-side load balancing of remote services were integrated into our “Hello World” example.
Calls to remote services are usually synchronous and don’t cut short a long-running call— The caller of a service has no concept of a timeout to keep the service call from hanging out forever. The application developer calls the service to perform an action and waits for the service to return.