Integration with other microservices

Integration - A separate class should be created for integrating with each dependent microservice. Only one method from that class should be called from the main service class for integration.

In this guide, we will be showcasing how we can integrate our microservices with other microservices like MDMS, IdGen, User and Workflow.

For interacting with other microservices, we can create and implement the following ServiceRequestRepository class under repository folder -

@Repository @Slf4j public class ServiceRequestRepository { private ObjectMapper mapper; private RestTemplate restTemplate; @Autowired public ServiceRequestRepository(ObjectMapper mapper, RestTemplate restTemplate) { this.mapper = mapper; this.restTemplate = restTemplate; } public Object fetchResult(StringBuilder uri, Object request) { mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); Object response = null; try { response = restTemplate.postForObject(uri.toString(), request, Map.class); }catch(HttpClientErrorException e) { log.error("External Service threw an Exception: ",e); throw new ServiceCallException(e.getResponseBodyAsString()); }catch(Exception e) { log.error("Exception while fetching from searcher: ",e); } return response; } }