File outbound channel adapter
Write messages to a file in a specified system directory
Directory
Destination directory where the files will be written to.
Some examples:
C:/files/out
${file.base-dir}/my-files/out
${file.dir.out}
Auto create directory
Specify whether to automatically create the destination directory if it does not yet exist when this adapter is being initialized.
If set to false and the directory does not exist upon initialization, an exception will be thrown.
Default is true.
Delete source files
Specify whether to delete source files after writing to the destination directory.
This will only take effect if the message payload is the actual source File
instance
or if the original File
instance (or its path) is available in the header.
Default: false
Mode
Determines the behaviour of this adapter when the destination file already exists.
Replace (default): If the target file already exists, it will be overwritten.
Append: If append is specified, the data will be appended to the existing file if such file exists, otherwise the new file will be created as usual but, once created, the subsequent data will be appended to it. This attribute is mutually exclusive the use of a temporary file, since append is done to the actual file and not its temporary counterpart. If set to Append, the component will also use an instance of the LockRegistry
to ensure that there are no collisions when multiple threads are writing to the same file.
Append no flush: Same as Append but the data is not flushed or the file closed. This can significantly improve performance at the risk of lost data in the event of a failure. See also flush interval.
Fail: If the target file exists, a MessageHandlingException
is thrown.
Ignore: If the target file exists, the message payload is silently ignored.
Directory expression
Specifies the output directory using a SpEL expression. This allows you to dynamically specify the output directory on a per message basis. For example a message header can be used for specifying the destination directory at runtime.
Filename generator
Specifies a file name generator. If empty, the default file name generator will be used.
The default generator first checks for a message name in the message header. If no name is available it checks if the Message payload is a File instance, and if so, it uses the same name. Finally, it falls back to the Message ID and adds the suffix '.msg'.
Filename generator is mutually exclusive with Filename generator expression.
Filename generator expression
Allows you to provide SpEL expression which will compute file name of the target file.
Optional
Filename generator expression is mutually exclusive with filename generator.
Charset
Character set to be used in case of a String payload.
Optional
Append new line
Whether to append a new-line after each write.
Default is false
.
Buffer size
The buffer size to use when writing to files.
Default is 8192
bytes (8 KiB).
Flush interval
When using mode append no flush if this time (in milliseconds) elapses without any new writes, the data is flushed and the file closed. This is approximate and may be up to 1.33x this time.
Default is 30000
ms (30 seconds).
Flush when idle
When using mode append no flush, set to false
to indicate the flush interval starts from the first new write to a previously flushed (or new) file. When true
, the interval starts from the last write (the file is flushed if it has no writes during the interval).
Default is true
.
Preserve timestamp
Specify whether to preserve the modified timestamp from the source file on the destination file after copying. Applies to java.io.File
payloads. For other payload types, the optional file_setModified
header will be used, if present, to set the last modified time.
By default, the timestamp will not be preserved.
Temporary file suffix
Extension used when writing files. We change it right after we know the file content has been written.
This attribute is mutualy exclusive with mode Append, since the append is done to the actual file and not its temporary counterpart.
Default is .writing
.
Advice can be added to change the behaviour of this endpoint, for example to add retry logic in case of failures. The following types of advice are available:
Retry advice: allows configuration of sophisticated retry scenarios; this includes specifying policies for retry attemps, backoff periods between attempts and the recovery strategy when retries are exhausted Circuit breaker: if a certain number of consecutive attempts fails, new requests will fail fast and no attempt will be made to invoke the request handler again until some time has expired Expression evaluating advice: general advice that evaluates a configurable SpEL expression on successful and/or failed attempts, and optionally can send a message to a success channel and/or failure channel
By adding multiple advices to this endpoint you can create even more complex combined behaviour. For example, if you add a circuit breaker and a retry advice, you can create a scenario where the circuit breaker only opens when all retries are exhaused. Note that the order of the advice types is important, as switching the order will change the combined behaviour: the first item in the list will be the top of the advice chain, meaning it will be the last advice that is evaluated. Also note that if any advice "traps" exceptions, all advices higher up in the chain won't know about any failures.
Channel
Channel to consume messages from.
Required
Id
Name that uniquely identifies this flow component.
Required