Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring integration tailing multiple files

I am writing a spring integration application that is supposed to tail multiple files (could be as many as 100). I am using the OSDelegatingFileTailingMessageProducer as the message source, which is the beginning of a pipeline involving multiple filters and channels.

Tailing one file works fine with this pipeline with an XML configuration file for the channels and transformers, but tailing many of those files would mean multiplication of this XML configuration, which is not good programming practice in my eyes.

I guess I will have to build these pipelines within Java by programmatically constructing a Spring application context. Are there any other options?

EDIT:

Probably using the BeanFactoryPostProcessor is the way to go: https://stackoverflow.com/a/15773000/2069922 ?

like image 841
user152468 Avatar asked Sep 28 '22 06:09

user152468


1 Answers

I think it would be easiest to create the message producers programmatically, and wire them into the same outputChannel. There's not really any need to create a Spring Application context each time. Just get the channel from the context (e.g. @AutoWired) and set the outputChannel.

Polled adapters are a bit more complicated but, in this case, each tail adapter is a simple single bean.

Just be sure to invoke afterPropertiesSet() and start() after setting the properties.

However, if you want a unique downstream flow for each tailer, then you can use a technique similar to the dynamic ftp sample, with parameterized application contexts.

like image 64
Gary Russell Avatar answered Nov 02 '22 22:11

Gary Russell