Created
          March 15, 2016 20:09 
        
      - 
      
 - 
        
Save MafaldaLandeiro/8319737574d1709c602f to your computer and use it in GitHub Desktop.  
    Lookup service
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package org.AsynchronousRESTServiceCall.lookup; | |
| import java.util.concurrent.Future; | |
| import org.AsynchronousRESTServiceCall.response.Greeting; | |
| import org.slf4j.Logger; | |
| import org.slf4j.LoggerFactory; | |
| import org.springframework.scheduling.annotation.Async; | |
| import org.springframework.scheduling.annotation.AsyncResult; | |
| import org.springframework.stereotype.Service; | |
| import org.springframework.web.client.RestTemplate; | |
| @Service | |
| public class GreetingLookUpService { | |
| private static final Logger log = LoggerFactory | |
| .getLogger(GreetingLookUpService.class); | |
| RestTemplate restTemplate = new RestTemplate(); | |
| @Async | |
| public Future<Greeting> getGreeting(String name) | |
| throws InterruptedException { | |
| log.info("Looking up " + name); | |
| Greeting result = restTemplate.getForObject( | |
| "http://localhost:8080/getGreeting?name=".concat(name), | |
| Greeting.class); | |
| Thread.sleep(1000L); | |
| return new AsyncResult<Greeting>(result); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment