use of io.spring.cloud.samples.brewery.common.TestConfigurationHolder in project brewery by spring-cloud-samples.
the class IngredientsController method distributeIngredients.
/**
* [SLEUTH] Callable - separate thread pool
*/
@RequestMapping(method = RequestMethod.POST)
public Callable<Ingredients> distributeIngredients(@RequestBody Order order, @RequestHeader("PROCESS-ID") String processId, @RequestHeader(value = TestConfigurationHolder.TEST_COMMUNICATION_TYPE_HEADER_NAME, defaultValue = "REST_TEMPLATE", required = false) TestConfigurationHolder.TestCommunicationType testCommunicationType) {
log.info("Setting tags and events on an already existing span");
tracer.currentSpan().tag("beer", "stout");
tracer.currentSpan().annotate("ingredientsAggregationStarted");
log.info("Starting beer brewing process for process id [{}]", processId);
Span span = tracer.nextSpan().name("inside_aggregating").start();
try (Tracer.SpanInScope ws = tracer.withSpanInScope(span)) {
TestConfigurationHolder testConfigurationHolder = TestConfigurationHolder.TEST_CONFIG.get();
return () -> ingredientsAggregator.fetchIngredients(order, processId, testConfigurationHolder);
} finally {
span.finish();
}
}
use of io.spring.cloud.samples.brewery.common.TestConfigurationHolder in project brewery by spring-cloud-samples.
the class Bottler method bottle.
/**
* [SLEUTH] TraceCommand
*/
@Override
public void bottle(Wort wort, String processId, String testCommunicationType) {
log.info("I'm in the bottling service");
log.info("Process ID from headers {}", processId);
String groupKey = "bottling";
String commandKey = "bottle";
HystrixCommand.Setter setter = HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)).andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
TestConfigurationHolder testConfigurationHolder = TestConfigurationHolder.TEST_CONFIG.get();
new TraceCommand<Void>(tracer, traceKeys, setter) {
@Override
public Void doRun() throws Exception {
TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder);
log.info("Sending info to bottling service about process id [{}]", processId);
bottlerService.bottle(wort, processId);
return null;
}
}.execute();
}
use of io.spring.cloud.samples.brewery.common.TestConfigurationHolder 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.TestConfigurationHolder in project brewery by spring-cloud-samples.
the class Maturer method distributeIngredients.
@Override
public void distributeIngredients(io.spring.cloud.samples.brewery.common.model.Ingredients ingredients, String processId, String testCommunicationType) {
log.info("I'm in the maturing service. Will distribute ingredients");
TestConfigurationHolder configurationHolder = TestConfigurationHolder.builder().testCommunicationType(TestConfigurationHolder.TestCommunicationType.valueOf(testCommunicationType)).build();
bottlingServiceUpdater.updateBottlingServiceAboutBrewedBeer(ingredients, processId, configurationHolder);
}
Aggregations