Files
spring-functions-catalog/supplier/spring-file-supplier
Artem Bilan 1611f9475c GH-3: Add tail support for spring-file-supplier (#42)
This commit adds `tail` support to the `spring-file-supplier`.

Additionally, move `FileMessageSource` specific beans into separate inner 
`FileMessageSourceConfiguration` class for easier conditional config 

Fixes: #3
2024-03-19 11:18:10 -05:00
..

= File Supplier

This module provides a File supplier that can be reused and composed in other applications.
The `Supplier` uses the `FileInboundChannelAdapter` from Spring Integration.
`FileSupplier` is implemented as a `java.util.function.Supplier`.
This supplier gives you a reactive stream of files from the provided directory as the supplier has a signature of `Supplier<Flux<Message<?>>>`.
Users have to subscribe to this `Flux` and receive the data.

This module also can be configured for file tailing functionality.
The implementation and logic is fully based on respective Spring Integration https://docs.spring.io/spring-integration/reference/file/reading.html#file-tailing[Tailing Message Producer].
The `Supplier<Flux<Message<?>>>` emits messages for each tailed line from the file.

== Beans for injection

The `FileSupplierConfiguration` auto-configuration provides the following bean:

`fileSupplier`

You need to inject this as `Supplier<Flux<Message<?>>>`.

You can use `fileSupplier` as a qualifier when injecting.

Once injected, you can use the `get` method of the `Supplier` to invoke it and then subscribe to the returned `Flux`.

== Configuration Options

All configuration properties are prefixed with `file.supplier`.
There are also properties that need to be used with the prefix `file.consumer`.

For more information on the various options available, please see link:src/main/java/org/springframework/cloud/fn/supplier/file/FileSupplierProperties.java[FileSupplierProperties].
See `FileConsumerProperties` also.

A `ComponentCustomizer<FileInboundChannelAdapterSpec>` bean can be added in the target project to provide any custom options for the `FileInboundChannelAdapterSpec` configuration used by the `fileSupplier`.

If `file.supplier.tail` option is provided, this supplier works in a tailing file mode.
See `FileSupplierProperties.Tailer` container for more information.
In `tail` mode, all other options for directory polling are ignored.

== Tests

See this link:src/test/java/org/springframework/cloud/fn/supplier/file[test suite] for the various ways, this supplier is used.

== Other usage

See this https://github.com/spring-cloud/stream-applications/blob/master/applications/source/file-source/README.adoc[README] where this supplier is used to create a Spring Cloud Stream application where it makes a File Source.