E-Riz
E-Riz

Reputation: 32994

How to add or adjust the configuration of the file supplier in Spring Cloud Stream

Spring Cloud Stream's file-supplier dependency includes FileSupplierConfiguration which configures a File message source (from Spring Integration). I need to customize the FileReadingMessageSource that this @Configuration provides, but I'm not sure of the best way to do so. It provided only basic properties to control its @Beans, but I need more.

I considered excluding FileSupplierConfiguration from the app, but I'd then have to copy most of the code from it into my own @Confguration class. Obviously that's a less than ideal solution.

So how can I customize the File message source, for example with additional FileListFilters?

Upvotes: 1

Views: 130

Answers (1)

dturanski
dturanski

Reputation: 1723

Add a BeanPostProcessor @Bean, like this:

@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;
        }
    };
}

Upvotes: 1

Related Questions