In the end, I did not register instances of OSDelegatingFileTailingMessageProducer with the Spring application context, because there was no need, as suggested by Gary. Instead, I used ApplicationListener and registered it in my Spring context. Then I created tailers inside the onApplicationEvent (...) method. Here is the minimal version:
public class MyApplicationListener implements ApplicationListener<ContextRefreshedEvent> { @Autowired @Qualifier("outputChannel") private SubscribableChannel outputChannel; @Override public void onApplicationEvent(ContextRefreshedEvent event) { OSDelegatingFileTailingMessageProducer tailer = new OSDelegatingFileTailingMessageProducer(); tailer.setOutputChannel(outputChannel); tailer.setFile(new File("/file/to/tail.txt")); tailer.setOptions("-f -n 0"); tailer.afterPropertiesSet(); tailer.start(); } }
EDIT:
In addition, we did not use OSDelegatingFileTailingMessageProducer, but the one that was from apache, since the tail command behaves differently in different versions of Unix. At first glance, we were not able to identify differences in performance.
source share