1
votes

I have a requirement to tail a file so I am using tail-inbound-channel-adapter.

There are couple of challenges. File name and the file path changes for every batch run. I was looking for some regex support like this attribute (filename-regex) found in inbound-channel-adapter. I only see an attribute called file in tail-inbound-channel-adapter which expects a static file name (as shown below). How do I pass in the dynamic file name to tail-inbound-channel-adapter.

<int-file:tail-inbound-channel-adapter channel="fileChannel" file="xyz" delay="999999999999999" end="false" reopen="true" file-delay="999999999999999" />

The other challange is that I dont want this poller to start polling right away when the application comes up. Instead it should start polling when the file is ready for tailing. How do I control that?

As shown above, I tried assigning some big delay in the config file and then tried to modify the delay value during the runtime. But that did not help.

Any other alternative ways for my requirements. Thanks for your valuable input.

1

1 Answers

1
votes

The adapter implements SmartLifecycle.

Set auto-startup="false". Get a reference to the adapter (e.g. @AutoWired or context.getBean("foo", FileTailingMessageProducerSupport.class)), assuming the adapter has id="foo".

To start the adapter use foo.start().

To change the file, foo.stop(); foo.setFile(newFile); foo.start();.