如何增加或调整Spring Cloud Stream中文件供应商的配置



Spring Cloud Stream的文件供应商依赖包括配置File消息源(来自Spring Integration)的FileSupplierConfiguration。我需要自定义这个@Configuration提供的FileReadingMessageSource,但我不确定这样做的最佳方法。它只提供了控制其@Beans的基本属性,但我需要更多。

我考虑从应用程序中排除FileSupplierConfiguration,但我必须将大部分代码从它复制到我自己的@ configuration类。显然,这不是一个理想的解决方案。

那么我如何自定义File消息源,例如使用额外的FileListFilter?

添加BeanPostProcessor@Bean,如下所示:

@Bean
public BeanPostProcessor inboundFileAdaptorCustomizer() {
return new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof FileInboundChannelAdapterSpec) {
//add filter function here
((FileInboundChannelAdapterSpec) bean).filter(files -> ...);
}
return bean;
}
};
}

最新更新