Skip to content

Instantly share code, notes, and snippets.

@njofce
Created March 7, 2021 16:46
Show Gist options
  • Save njofce/c785a4c0578792123693dcdc04a620af to your computer and use it in GitHub Desktop.
Save njofce/c785a4c0578792123693dcdc04a620af to your computer and use it in GitHub Desktop.
public class FeignClient {
public static void main(String[] args) throws ExecutionException, InterruptedException {
synchronousTest();
asyncTest();
}
private static void synchronousTest() {
FileApi fileApi = FileApiFactory.getSynchronousFileAPI();
FileMetadata file1 = fileApi.getFile("file1");
System.out.println("Loaded from server: " + file1.fileName);
}
private static void asyncTest() throws ExecutionException, InterruptedException {
AsyncFileApi asyncFileAPI = FileApiFactory.getAsyncFileAPI();
CompletableFuture<FileMetadata> file = asyncFileAPI.getFile("file2");
String id = file.thenApply(f -> "ID: " + f.id).get();
System.out.println("Loaded asynchronously the file with id: " + id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment