Skip to content

Instantly share code, notes, and snippets.

@MafaldaLandeiro
Created March 15, 2016 20:09
Show Gist options
  • Save MafaldaLandeiro/8319737574d1709c602f to your computer and use it in GitHub Desktop.
Save MafaldaLandeiro/8319737574d1709c602f to your computer and use it in GitHub Desktop.
Lookup service
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