use of io.spring.cloud.samples.brewery.common.model.Ingredients in project brewery by spring-cloud-samples.
the class IngredientsAggregator method fetchIngredients.
// TODO: Consider simplifying the case by removing the DB (always matches threshold)
public Ingredients fetchIngredients(Order order, String processId, TestConfigurationHolder testConfigurationHolder) throws Exception {
TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder);
log.info("Fetching ingredients for order [{}] , processId [{}]", order, processId);
/**
* [SLEUTH] ParallelStreams won't work out of the box
* - example of a completable future with our TraceableExecutorService
* - makes little business sense here but that's just an example
*/
CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> {
TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder);
ingredientsCollector.collectIngredients(order, processId).stream().filter(ingredient -> ingredient != null).forEach((Ingredient ingredient) -> {
log.info("Adding an ingredient [{}] for order [{}] , processId [{}]", ingredient);
ingredientWarehouse.addIngredient(ingredient);
});
return null;
}, new TraceableExecutorService(this.beanFactory, Executors.newFixedThreadPool(5), "fetchIngredients"));
// block to perform the request (as I said the example is stupid)
completableFuture.get();
eventGateway.emitEvent(Event.builder().eventType(EventType.INGREDIENTS_ORDERED).processId(processId).build());
Ingredients ingredients = ingredientWarehouse.getCurrentState();
return maturingUpdater.updateIfLimitReached(ingredients, processId);
}
use of io.spring.cloud.samples.brewery.common.model.Ingredients in project brewery by spring-cloud-samples.
the class MaturingServiceUpdater method updateIfLimitReached.
public Ingredients updateIfLimitReached(Ingredients ingredients, String processId) {
if (ingredientsMatchTheThreshold(ingredients)) {
log.info("Ingredients match the threshold [{}] - time to notify the maturing service!", ingredientsProperties.getThreshold());
eventGateway.emitEvent(Event.builder().eventType(EventType.BREWING_STARTED).processId(processId).build());
notifyMaturingService(ingredients, processId);
ingredientWarehouse.useIngredients(ingredientsProperties.getThreshold());
} else {
log.warn("Ingredients DO NOT match the threshold [{}]. If you're clicking manually then " + "everything is fine. If you're running the tests then most likely Config Server is not available " + "and threshold value is wrong.", ingredientsProperties.getThreshold());
}
Ingredients currentState = ingredientWarehouse.getCurrentState();
log.info("Current state of ingredients is [{}]", currentState);
return currentState;
}
Aggregations