/** * In this example main method calls retrieveExchangeRate which asynchronously * replies back via Consumer call back. */ public class ConsumerExample {
public static void retrieveExchangeRate(Currency currency, Consumer<BigDecimal> rateConsumer) {
System.out.println("Retrieving rate for currency " + currency); //just a test , no real exchange rate service call made. Executors.newSingleThreadExecutor().submit(() -> rateConsumer.accept(new BigDecimal(Math.round(Math.random() * 100))));