use of org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry in project spring-cloud-stream by spring-cloud.
the class DefaultBinderFactory method getBinderInstance.
@SuppressWarnings("unchecked")
private <T> Binder<T, ConsumerProperties, ProducerProperties> getBinderInstance(String configurationName) {
if (!this.binderInstanceCache.containsKey(configurationName)) {
logger.info("Creating binder: " + configurationName);
BinderConfiguration binderConfiguration = this.binderConfigurations.get(configurationName);
Assert.state(binderConfiguration != null, "Unknown binder configuration: " + configurationName);
BinderType binderType = this.binderTypeRegistry.get(binderConfiguration.getBinderType());
Assert.notNull(binderType, "Binder type " + binderConfiguration.getBinderType() + " is not defined");
Map<String, Object> binderProperties = new HashMap<>();
this.flatten(null, binderConfiguration.getProperties(), binderProperties);
ConfigurableApplicationContext binderProducingContext = this.initializeBinderContextSimple(configurationName, binderProperties, binderType, binderConfiguration);
Map<String, MessageConverter> messageConverters = binderProducingContext.getBeansOfType(MessageConverter.class);
if (!CollectionUtils.isEmpty(messageConverters) && !ObjectUtils.isEmpty(context.getBeansOfType(FunctionCatalog.class))) {
FunctionCatalog functionCatalog = this.context.getBean(FunctionCatalog.class);
if (functionCatalog instanceof SimpleFunctionRegistry) {
((SimpleFunctionRegistry) functionCatalog).addMessageConverters(messageConverters.values());
}
}
Binder<T, ?, ?> binder = binderProducingContext.getBean(Binder.class);
/*
* This will ensure that application defined errorChannel and other beans are
* accessible within binder's context (see
* https://github.com/spring-cloud/spring-cloud-stream/issues/1384)
*/
if (this.context != null && binder instanceof ApplicationContextAware) {
((ApplicationContextAware) binder).setApplicationContext(this.context);
}
if (!CollectionUtils.isEmpty(this.listeners)) {
for (Listener binderFactoryListener : this.listeners) {
binderFactoryListener.afterBinderContextInitialized(configurationName, binderProducingContext);
}
}
logger.info("Caching the binder: " + configurationName);
this.binderInstanceCache.put(configurationName, new SimpleImmutableEntry<>(binder, binderProducingContext));
}
logger.info("Retrieving cached binder: " + configurationName);
return (Binder<T, ConsumerProperties, ProducerProperties>) this.binderInstanceCache.get(configurationName).getKey();
}
Aggregations