Camel Components

Azure Files

Since Camel 3.22

Both producer and consumer are supported

This component provides access to Azure Files.

This is preview component, therefore, anything can change in future releases (features and behavior can be changed, modified or even dropped without notice). At the same time it is consolidated enough, sparingly documented, a few users reported it was working in their environment, and it is ready for wider feedback.

When consuming from remote files server, make sure you read the section titled Consuming Files further below for details related to consuming files.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-azure-files</artifactId>
    <version>x.y.z</version>
    <!-- use the same version as your Camel core version -->
</dependency>

Endpoint URI Format

azure-files://account[.file.core.windows.net][:port]/share[/directory]

Where directory represents the underlying directory. The directory is a relative path and does not include the share name. The relative path can contain nested folders, such as inbox/spam. It defaults to the share root directory.

The autoCreate option is supported for the directory; when consumer or producer starts, there’s an additional operation performed to create the directory configured for the endpoint. The default value for autoCreate is true. On the contrary, the share must exist; it is not automatically created.

When the consumer cannot create the directory as the route starts, for example because the identity is not allowed to create directories in the share, or the share refuses the credentials, the route still starts: the consumer logs a WARN and tries again on each poll.

If no port number is provided, Camel will provide default values according to the protocol (https 443).

You can append query options to the URI in the following format ?option=value&option2=value&…​.

To use this component, you have multiple options to provide the required Azure authentication information:

  • Via Azure Identity, when specifying credentialType=AZURE_IDENTITY and providing required environment variables. This enables service principal (e.g. app registration) authentication with secret/certificate as well as username password.

  • Via shared storage account key, when specifying credentialType=SHARED_ACCOUNT_KEY and providing sharedKey for your Azure account, this is the simplest way to get started. The sharedKey can be generated through your Azure portal.

  • Via Azure SAS, when specifying credentialType=AZURE_SAS and providing a SAS Token parameter through the token parameter.

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The Azure Files component supports the following options which are listed below.

Name Description Default Type

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

healthCheckConsumerEnabled (health)

Used for enabling or disabling all consumer based health checks from this component.

true

boolean

healthCheckProducerEnabled (health)

Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true.

true

boolean

Endpoint Options

The Azure Files endpoint is configured using URI syntax:

azure-files:account/share

With the following path and query parameters:

Path Parameters

Name Description Default Type

account (common)

Required The name of the storage account, for example myaccount, or the host name of its file service, for example myaccount.file.core.windows.net. With a name alone, the component connects to that name with the .file.core.windows.net suffix, always over HTTPS.

String

share (common)

Required The name of the file share in the storage account. A path after the share name in the endpoint URI is the directory, from the share root, that the consumer polls and that the producer writes to. Without it, the share root is used.

String

port (common)

The port of the remote server. When not set, the default port of the protocol is used.

int

directoryName (common)

The starting directory.

String

Query Parameters

Name Description Default Type

credentialType (common)

How the component authenticates: SHARED_ACCOUNT_KEY with the sharedKey option, AZURE_SAS with the SAS token options (sv, sig, se and the others), or AZURE_IDENTITY with the DefaultAzureCredential of the Azure Identity library and the backup intent, which needs the Storage File Data Privileged Reader or Contributor role. SHARED_KEY_CREDENTIAL is not supported: with it, or with SHARED_ACCOUNT_KEY and no sharedKey, the requests carry no credentials.

Enum values:

  • SHARED_ACCOUNT_KEY

  • SHARED_KEY_CREDENTIAL

  • AZURE_IDENTITY

  • AZURE_SAS

SHARED_ACCOUNT_KEY

CredentialType

disconnect (common)

Whether to disconnect from the remote server right after use: the consumer disconnects after each poll, and the producer after each message it writes. This only closes the current connection: to stop a consumer, stop the consumer or the route instead.

false

boolean

doneFileName (common)

The name of the done file, an empty file that marks a file as complete. Producer: after the file is written, the done file is written in the same directory. Consumer: a file is only consumed when its done file exists in the same directory, and the done file is deleted once the file is consumed (unless noop=true). The name is either a fixed name, or uses the placeholders $\{file:name} and $\{file:name.noext}, which are the only ones supported; the consumer supports the fixed part of the name either as a prefix or as a suffix, not both.

String

fileName (common)

The file name, as an expression such as the File Language. Consumer: only the file with exactly this name is consumed, as the name is not a pattern (use antInclude or include to consume the files that match a pattern); for example consume the file of today with mydata-$\{date:now:yyyyMMdd}.txt. Producer: the name of the file to write; when set, it is used instead of the CamelFileName header, unless that header holds an org.apache.camel.Expression (a String header is used as it is, not evaluated). A String value of this option is evaluated with the File Language, and an Expression object as it is. The producer also supports the CamelOverruleFileName header, which takes precedence over the CamelFileName header and is used only once, so CamelFileName does not have to be stored and restored around the producer.

String

jailStartingDirectory (common)

Used for jailing (restricting) writing files to the starting directory (and sub) only. This is enabled by default to not allow Camel to write files to outside directories (to be more secured out of the box). You can turn this off to allow writing files to directories outside the starting directory, such as parent or root folders. For consumers that use a localWorkDirectory, this also restricts the downloaded files to stay within the configured localWorkDirectory.

true

boolean

sharedKey (common)

The access key of the storage account, for credentialType=SHARED_ACCOUNT_KEY. The component signs the requests with this key and the account option as the account name, so the endpoint URI must give the account name, not the host name. A + in the key can stay unencoded in the endpoint URI.

String

delete (consumer)

If true, the file is deleted after it is processed successfully. Cannot be combined with move.

false

boolean

moveFailed (consumer)

Sets the move failure expression based on Simple language. For example, to move files into a .error subdirectory use: .error. Note: When moving the files to the fail location Camel will handle the error and will not pick up the file again.

String

noop (consumer)

If true, the consumer leaves the file in place: it does not move or delete the file after it is processed (preMove and moveFailed still apply, and delete=true takes precedence over noop). Good for read-only data or ETL. noop=true also turns on idempotent (unless idempotent is set), so the same files are not consumed over and over again.

false

boolean

preMove (consumer)

Expression (such as File Language) used to dynamically set the filename when moving it before processing. For example to move in-progress files into the order directory set this value to order.

String

preSort (consumer)

When pre-sort is enabled then the consumer will sort the file and directory names during polling, that was retrieved from the file system. You may want to do this in case you need to operate on the files in a sorted order. The pre-sort is executed before the consumer starts to filter, and accept files to process by Camel. This option is default=false meaning disabled. The following values are supported: name (sort by file name), modified (sort by last-modified timestamp), size (sort by file size). To sort in descending (reverse) order, prefix the value with a minus sign (e.g., -modified to sort newest first). The value true is an alias for name (backward compatible).

Enum values:

  • true

  • false

  • name

  • -name

  • modified

  • -modified

  • size

  • -size

String

recursive (consumer)

Whether to also consume the files in all the subdirectories of the starting directory (see minDepth and maxDepth).

false

boolean

resumeDownload (consumer)

Whether the consumer resumes a download that failed, instead of downloading the whole file again. It needs localWorkDirectory: the consumer keeps the partial .inprogress file of a failed download there and fetches only the rest of the file in the next attempt. The route fails to start if localWorkDirectory is not set.

false

boolean

sendEmptyMessageWhenIdle (consumer)

If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead.

false

boolean

streamDownload (consumer)

How the consumer downloads a file when no localWorkDirectory is set. When true, the message body is the stream of the remote file, which the route reads as the file is downloaded. When false, the whole file is loaded into memory before it is sent to the route. For ftp and ftps, stepwise must then be set to false, as both cannot be enabled at the same time.

false

boolean

bridgeErrorHandler (consumer (advanced))

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

boolean

download (consumer (advanced))

Whether the consumer downloads the file. When false, the message body is null, but the consumer still creates an exchange with the details of the file, such as its name and size, in the headers.

true

boolean

exceptionHandler (consumer (advanced))

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

ExceptionHandler

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly

  • InOut

ExchangePattern

inProgressRepository (consumer (advanced))

A custom org.apache.camel.spi.IdempotentRepository that keeps track of the files being consumed, so that a later poll does not pick up a file that is still in progress. By default, a memory based repository (of up to 50000 entries) is used.

IdempotentRepository

localWorkDirectory (consumer (advanced))

A local directory to download the remote files into, so their content is stored in local files instead of in memory. Useful to save memory when consuming very big files. Not used by the file component.

String

onCompletionExceptionHandler (consumer (advanced))

A custom org.apache.camel.spi.ExceptionHandler that handles the exceptions thrown when the consumer completes a file, by a commit or a rollback (such as moving or deleting the file). By default, the exceptions are logged at WARN level and ignored.

ExceptionHandler

pollStrategy (consumer (advanced))

A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel.

PollingConsumerPollStrategy

processStrategy (consumer (advanced))

A pluggable org.apache.camel.component.file.GenericFileProcessStrategy allowing you to implement your own readLock option or similar. Can also be used when special conditions must be met before a file can be consumed, such as a special ready file exists. If this option is set then the readLock option does not apply.

GenericFileProcessStrategy

throwExceptionOnConnectFailed (consumer (advanced))

Whether the consumer throws an exception when it cannot connect or log in to the server, or cannot create the starting directory. By default, the consumer logs a WARN and skips the poll. When enabled, the exception goes to the rollback method of the poll strategy (the pollStrategy option), which can handle it.

false

boolean

checksumFileAlgorithm (producer)

The algorithm of a checksum to calculate from the content of the written file. The checksum is set in the CamelFileChecksum header (and written to a checksum file, see checksumWriteFile). The name is passed to java.security.MessageDigest, which accepts names such as MD5, SHA-1, SHA-256 or SHA3-256.

Enum values:

  • MD2

  • MD5

  • SHA_1

  • SHA_224

  • SHA_256

  • SHA_384

  • SHA_512

  • SHA_512_224

  • SHA_512_256

  • SHA3_224

  • SHA3_256

  • SHA3_384

  • SHA3_512

String

checksumWriteFile (producer)

Whether to also write the checksum to a file, when checksumFileAlgorithm is set. The checksum file is written in the same directory as the file, with the algorithm as extension (for example hello.txt.MD5 with checksumFileAlgorithm=MD5).

true

boolean

fileExist (producer)

What to do when a file with the same name already exists: - Override - replaces the existing file (the default). - Append - adds the content to the existing file. - Fail - fails with a GenericFileOperationFailedException. - Ignore - keeps the existing file and writes nothing, without failing. - Move - moves the existing file to the name given by the moveExisting option (which must be set) before writing the file. The eagerDeleteTargetFile option controls what happens when a file already exists at that name. - TryRename - only used with tempFileName or tempPrefix: renames the temporary file to the real name without checking whether a file exists, which can be faster on some file systems and FTP servers.

Enum values:

  • Override

  • Append

  • Fail

  • Ignore

  • Move

  • TryRename

Override

GenericFileExist

flatten (producer)

Whether to strip the leading paths from the file name, so only the name of the file is left. The consumer then sets the CamelFileName header to the name only, and the producer strips the paths from the name it writes (from the fileName option or the CamelFileName header). For example, files consumed recursively from subdirectories are then all written in a single directory.

false

boolean

tempFileName (producer)

The same as tempPrefix option but offering a more fine grained control on the naming of the temporary filename as it uses the File Language. The location for tempFilename is relative to the final file location in the option 'fileName', not the target directory in the base uri. For example if option fileName includes a directory prefix: dir/finalFilename then tempFileName is relative to that subdirectory dir.

String

tempPrefix (producer)

This option is used to write the file using a temporary name and then, after the write is complete, rename it to the real name. Can be used to identify files being written and also avoid consumers (not using exclusive read locks) reading in progress files. Is often used by FTP when uploading big files.

String

allowNullBody (producer (advanced))

Whether a message with a null body can be written. If true, an empty file is written: an existing file is truncated with fileExist=Override, and left unchanged with fileExist=Append. If false, a null body fails with a GenericFileOperationFailedException.

false

boolean

disconnectOnBatchComplete (producer (advanced))

Whether the producer disconnects from the remote server after the last message of a batch, which is a message whose exchange property CamelBatchComplete is true, such as the last file of a poll of a file consumer. This only closes the current connection.

false

boolean

eagerDeleteTargetFile (producer (advanced))

Whether to delete an existing target file before the temporary file is written, when fileExist=Override is used with tempFileName or tempPrefix. Set it to false to keep the existing target file while the temporary file is written, for example when writing big files: the target file is then deleted just before the temporary file is renamed to it. With fileExist=Move, it also controls what happens when a file already exists at the name given by moveExisting: true deletes that file before the move, false fails the move with an exception.

true

boolean

keepLastModified (producer (advanced))

Whether to set the last modified timestamp of the written file to the value of the CamelFileLastModified header (a java.util.Date or a long), for example to keep the timestamp of the source file. Nothing is set when the header is missing. Only used by the file component.

false

boolean

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

moveExistingFileStrategy (producer (advanced))

A custom FileMoveExistingStrategy that moves the existing file when fileExist=Move is used. By default, the component uses its own implementation, which moves the file to the name computed by moveExisting.

FileMoveExistingStrategy

autoCreate (advanced)

Automatically create missing directories in the file’s pathname. For the file consumer, that means creating the starting directory. For the file producer, it means the directory the files should be written to.

true

boolean

browseLimit (advanced)

Maximum number of messages to keep in memory available for browsing. Use 0 for unlimited.

100

int

connectTimeout (advanced)

The timeout in milliseconds for establishing the connection to the server. For sftp, mina-sftp and scp, it also applies to the SSH handshake and the login. 0 means no timeout.

10000

int

maximumReconnectAttempts (advanced)

The maximum number of attempts to connect to the remote server each time a connection is needed, reconnectDelay apart. Default is 3. 0 or less means a single attempt. A login that the server rejects is not retried.

int

reconnectDelay (advanced)

The delay in milliseconds between two attempts to connect to the remote server.

1000

long

timeout (advanced)

The data timeout in milliseconds. For ftp and ftps, it is the read timeout of the data connection (the data timeout of the Apache Commons Net FTPClient), and 0 means no timeout. For scp, it is the timeout of the JSch session. The sftp and mina-sftp components do not use it.

30000

int

antExclude (filter)

Excludes the files whose path, relative to the starting directory, matches one of these Ant style patterns, such as */.bak. Separate several patterns with a comma. Takes precedence over antInclude.

String

antFilterCaseSensitive (filter)

Whether the antInclude and antExclude patterns are matched case sensitive.

true

boolean

antInclude (filter)

Includes only the files whose path, relative to the starting directory, matches one of these Ant style patterns, such as */.txt. Separate several patterns with a comma.

String

eagerMaxMessagesPerPoll (filter)

Allows for controlling whether the limit from maxMessagesPerPoll is eager or not. If eager then the limit is during the scanning of files, and the file, sftp, mina-sftp and smb consumers stop reading the directory once the limit is hit, unless preSort or doneFileName is used, as they need the whole directory. Where as false would scan all files, and then perform sorting. Setting this option to false allows for sorting all files first, and then limit the poll. Mind that this requires a higher memory usage as all file details are in memory to perform the sorting.

true

boolean

exclude (filter)

Excludes the files whose name matches this regular expression (matched ignoring the case). Takes precedence over include. It is a regular expression, not a wildcard: use antExclude for wildcards, or excludeExt to exclude files by extension. When the expression has characters such as the plus sign, set it with RAW() in an endpoint URI.

String

excludeExt (filter)

Excludes the files with one of these extensions (ignoring the case), separated by comma, for example excludeExt=bak,dat. A file matches when its name ends with a dot and the extension, so both excludeExt=gz and excludeExt=tar.gz match mydata.tar.gz. For more flexibility use the include and exclude options.

String

filter (filter)

Pluggable filter as a org.apache.camel.component.file.GenericFileFilter class. Will skip files if filter returns false in its accept() method.

GenericFileFilter

filterDirectory (filter)

A File Language predicate that filters the subdirectories to scan with recursive=true: only the directories for which it is true are scanned. For example, to scan only the directory of today: $\{file:onlyname} == $\{date:now:yyyyMMdd}.

String

filterFile (filter)

A File Language predicate that filters the files: only the files for which it is true are consumed. For example, to filter on the file extension: $\{file:ext} == 'txt'.

String

idempotent (filter)

Option to use the Idempotent Consumer EIP pattern to let Camel skip already processed files. Will by default use a memory based LRUCache that holds 1000 entries. If noop=true then idempotent will be enabled as well to avoid consuming the same files over and over again. Setting only idempotentRepository or idempotentKey does not turn it on.

false

Boolean

idempotentEager (filter)

Sets whether to eagerly add the filename to the idempotent repository or wait until the exchange is complete. Does not apply with an idempotent read lock (readLock=idempotent, idempotent-changed or idempotent-rename), which adds the filename when it acquires the lock.

true

Boolean

idempotentKey (filter)

To use a custom idempotent key. By default the absolute path of the file is used. You can use the File Language, for example to use the file name and file size, you can do: idempotentKey=$\{file:name}-$\{file:size}. It is used only with idempotent=true (noop=true turns it on), or by an idempotent read lock (readLock=idempotent, idempotent-changed or idempotent-rename) of the file component.

String

idempotentRepository (filter)

A pluggable repository org.apache.camel.spi.IdempotentRepository which by default use MemoryIdempotentRepository if none is specified and idempotent is true. It is used only with idempotent=true (noop=true turns it on), or by an idempotent read lock (readLock=idempotent, idempotent-changed or idempotent-rename) of the file component. Set without them, it does not skip any file.

IdempotentRepository

include (filter)

Includes only the files whose name matches this regular expression (matched ignoring the case). It is a regular expression, not a wildcard: use antInclude for wildcards, or includeExt to include files by extension. When the expression has characters such as the plus sign, set it with RAW() in an endpoint URI.

String

includeExt (filter)

Includes only the files with one of these extensions (ignoring the case), separated by comma, for example includeExt=txt,xml. A file matches when its name ends with a dot and the extension, so both includeExt=gz and includeExt=tar.gz match mydata.tar.gz. For more flexibility use the include and exclude options.

String

maxDepth (filter)

The maximum depth to traverse when recursively processing a directory. maxDepth=1 means only the starting directory.

2147483647

int

maxMessagesPerPoll (filter)

The maximum number of files to consume in one poll. 0 or negative (the default) means no limit. Can be used, for example, to avoid picking up thousands of files at once when the server starts. With eagerMaxMessagesPerPoll=true (the default) the limit applies while the files are scanned, before any sorting: with 100000 files and maxMessagesPerPoll=500, the first 500 files found are taken and then sorted. Set eagerMaxMessagesPerPoll=false to scan and sort all the files first, and then take the limit.

int

minDepth (filter)

The minimum depth to start processing when recursively processing a directory. Using minDepth=1 means the base directory. Using minDepth=2 means the first sub directory.

int

move (filter)

Expression (such as Simple Language) used to dynamically set the filename when moving it after processing. To move files into a .done subdirectory just enter .done.

String

exclusiveReadLockStrategy (lock)

A custom org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy to use as the read lock. When set, the readLock option is not used.

GenericFileExclusiveReadLockStrategy

readLock (lock)

The read lock strategy, so that the consumer only picks up a file that is not being written (in progress). The consumer waits for the read lock up to readLockTimeout. The strategies are: - none - no read lock is used. - changed - uses the length and the modification timestamp of the file to detect whether it is still being written, so files cannot be consumed as fast as with the others. The option readLockCheckInterval sets the time between two checks. - rename - tries to rename the file, to test whether the consumer can get an exclusive read lock. The other read locks of the file component (markerFile, fileLock and the idempotent read locks) are not supported, and fail when the consumer is created.

Enum values:

  • none

  • rename

  • changed

none

String

readLockCheckInterval (lock)

The interval in millis between the attempts to acquire the read lock, for the read locks that retry (changed, fileLock and rename, and also idempotent-changed and idempotent-rename of the file component). For example, set a higher interval with readLock=changed to cater for slow writes. The ftp, ftps, sftp, mina-sftp and azure-files components use 5000 by default. readLockTimeout must be higher than readLockCheckInterval; as a rule of thumb, make the timeout at least 2 or 3 times the interval, so the read lock has enough time to be acquired before the timeout.

1000

long

readLockLoggingLevel (lock)

The logging level of the message logged when a read lock cannot be acquired, for example OFF for no logging. Used by the read locks changed, fileLock, idempotent, idempotent-changed, idempotent-rename and rename.

Enum values:

  • TRACE

  • DEBUG

  • INFO

  • WARN

  • ERROR

  • OFF

DEBUG

LoggingLevel

readLockMarkerFile (lock)

Whether the changed, fileLock and rename read locks also create a marker file, to keep other processes from picking up the same files. Set it to false, for example, to not write marker files to the file system. Only used by the file component.

true

boolean

readLockMinAge (lock)

The minimum age in millis a file must have before the changed read lock (readLock=changed or idempotent-changed) acquires it, for example readLockMinAge=300s for 5 minutes. When set, the read lock acquires a file as soon as it is older than this, without waiting for its length and timestamp to stay the same, which can make it faster.

0

long

readLockMinLength (lock)

The minimum length in bytes a file must have before the changed read lock (readLock=changed or idempotent-changed) acquires it. The default 1 means an empty file is not consumed; set 0 to consume empty files.

1

long

readLockTimeout (lock)

The timeout in millis to acquire the read lock. When the lock is not granted within the timeout, the file is skipped and tried again on the next poll. 0 or lower waits forever. Used by the changed, fileLock and rename read locks (and also idempotent-changed and idempotent-rename of the file component). The ftp, ftps, sftp, mina-sftp and azure-files components use 20000 by default. readLockTimeout must be higher than readLockCheckInterval; as a rule of thumb, make the timeout at least 2 or 3 times the interval, so the read lock has enough time to be acquired before the timeout.

10000

long

backoffErrorThreshold (scheduler)

The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in.

int

backoffIdleThreshold (scheduler)

The number of subsequent idle polls that should happen before the backoffMultipler should kick-in.

int

backoffMultiplier (scheduler)

To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured.

int

delay (scheduler)

Milliseconds before the next poll.

500

long

greedy (scheduler)

If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages.

false

boolean

healthCheckMaxPollDuration (scheduler)

How long a poll may run before the health check of the consumer reports DOWN. The health check is otherwise based on the polls that are done, so it stays UP while a poll hangs, for example on a read without timeout from a connection that went silent. A poll includes routing the messages it polled, so set this above the longest poll you expect. The poll is not interrupted. The value is in millis (not affected by timeUnit). The default 0 turns this off.

0

long

initialDelay (scheduler)

Milliseconds before the first poll starts.

1000

long

repeatCount (scheduler)

Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever.

0

long

runLoggingLevel (scheduler)

The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that.

Enum values:

  • TRACE

  • DEBUG

  • INFO

  • WARN

  • ERROR

  • OFF

TRACE

LoggingLevel

scheduledExecutorService (scheduler)

Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool.

ScheduledExecutorService

scheduler (scheduler)

To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler.

none

Object

schedulerProperties (scheduler)

To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler. This is a multi-value option with prefix: scheduler.

Map

startScheduler (scheduler)

Whether the scheduler should be auto started.

true

boolean

timeUnit (scheduler)

Time unit for initialDelay and delay options.

Enum values:

  • NANOSECONDS

  • MICROSECONDS

  • MILLISECONDS

  • SECONDS

  • MINUTES

  • HOURS

  • DAYS

MILLISECONDS

TimeUnit

useFixedDelay (scheduler)

Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details.

true

boolean

sdd (security)

The signed directory depth (sdd) of a service SAS token for credentialType=AZURE_SAS. The component adds it to the token as given.

String

se (security)

The signed expiry (se) of the SAS token for credentialType=AZURE_SAS: the UTC time in ISO 8601 format after which the token is no longer valid, for example 2023-06-18T22:29:13Z.

String

si (security)

The signed identifier (si) of a service SAS token for credentialType=AZURE_SAS: the name of a stored access policy on the share, which can hold the permissions and validity times of the token.

String

sig (security)

The signature (sig) of the SAS token for credentialType=AZURE_SAS, Base64 encoded. It can be given URL-encoded, as it appears in the SAS token.

String

sip (security)

The signed IP (sip) of the SAS token for credentialType=AZURE_SAS: the IP address or range of IP addresses that requests with the token must come from, for example 168.1.5.65 or 168.1.5.60-168.1.5.70.

String

sp (security)

The signed permissions (sp) of the SAS token for credentialType=AZURE_SAS, for example rwdlc for read, write, delete, list and create.

String

spr (security)

The signed protocol (spr) of the SAS token for credentialType=AZURE_SAS: https, or https,http. The component always connects with HTTPS.

String

sr (security)

The signed resource (sr) of a service SAS token for credentialType=AZURE_SAS: s for a share or f for a file. Not used in an account SAS token.

String

srt (security)

The signed resource types (srt) of an account SAS token for credentialType=AZURE_SAS: s for service, c for container (share or directory) and o for object (file), for example sco. Not used in a service SAS token.

String

ss (security)

The signed services (ss) of an account SAS token for credentialType=AZURE_SAS, for example f. The value must include f, the file service. Not used in a service SAS token.

String

st (security)

The signed start (st) of the SAS token for credentialType=AZURE_SAS: the UTC time in ISO 8601 format from which the token is valid. If the token has no start time, it is valid from the time that the file service receives the request.

String

sv (security)

The signed version (sv) of the SAS token for credentialType=AZURE_SAS: the storage service version that signs it, for example 2022-11-02. Azure requires it in every SAS token.

String

shuffle (sort)

To shuffle the list of files (sort in random order).

false

boolean

sortBy (sort)

Sorts the files with File Language expressions, such as sortBy=file:name. Separate several groups with a semicolon to sort by the next group when the previous one is equal, such as sortBy=file:modified;file:name. Prefix a group with reverse: to sort it in reverse order, and with ignoreCase: to compare text ignoring the case (reverse: comes first when both are used).

String

sorter (sort)

Pluggable sorter as a java.util.Comparator class that compares org.apache.camel.component.file.GenericFile objects.

Comparator

Message Headers

The Azure Files component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelFileLength (consumer)

Constant: FILE_LENGTH

The size of the file in bytes, which the consumer sets. The producer uses it as the size of the file it creates when the body is a stream of unknown length.

long

CamelFileLastModified (consumer)

Constant: FILE_LAST_MODIFIED

The time that the file was last modified, in milliseconds since the epoch, as the file service lists it.

long

CamelFileNameOnly (consumer)

Constant: FILE_NAME_ONLY

Only the file name (the name with no leading paths).

String

CamelFileName (common)

Constant: FILE_NAME

The name of the file, relative to the directory of the endpoint. The consumer sets it for the consumed file. The producer writes the file under this name, a String or an Expression, unless the fileName option is set; with neither, it uses the message ID.

String

CamelFileNameConsumed (consumer)

Constant: FILE_NAME_CONSUMED

The name of the consumed file, relative to the directory of the endpoint. Unlike CamelFileName, it keeps this value when the route changes CamelFileName.

String

CamelFileAbsolute (consumer)

Constant: FILE_ABSOLUTE

Whether the path of the consumed file in CamelFileAbsolutePath is absolute, that is, starts with / at the share root.

Boolean

CamelFileAbsolutePath (consumer)

Constant: FILE_ABSOLUTE_PATH

The path of the consumed file from the share root, without the share name, for example /inbox/order.xml.

String

CamelFilePath (consumer)

Constant: FILE_PATH

The path of the consumed file from the share root, the same value as CamelFileAbsolutePath.

String

CamelFileRelativePath (consumer)

Constant: FILE_RELATIVE_PATH

The path of the consumed file relative to the directory of the endpoint, for example 2026/order.xml for a file in a subdirectory with recursive=true.

String

CamelFileParent (common)

Constant: FILE_PARENT

The path of the directory that holds the consumed file, from the share root, for example /inbox.

String

CamelFileNameProduced (producer)

Constant: FILE_NAME_PRODUCED

The path of the file that the producer wrote, from the share root, for example /outbox/order.xml.

String

CamelOverruleFileName (producer)

Constant: OVERRULE_FILE_NAME

A file name, a String or an Expression, that the producer uses instead of CamelFileName for one write only: the producer removes this header after the write. The fileName option, if set, still takes precedence.

Object

CamelRemoteFileInputStream (common)

Constant: REMOTE_FILE_INPUT_STREAM

The input stream of the content of the consumed file, with streamDownload=true. The consumer closes it when the exchange is done.

InputStream

CamelFileLocalWorkPath (common)

Constant: FILE_LOCAL_WORK_PATH

The path of the local file in localWorkDirectory that holds the downloaded content of the consumed file. The consumer deletes this file when the exchange is done.

String

CamelFileHost (common)

Constant: FILE_HOST

The host name of the file service of the storage account, for example myaccount.file.core.windows.net. The consumer sets it.

String

CamelAzureFilesShareName (consumer)

Constant: SHARE_NAME

The name of the share the file was consumed from.

String

Message Body

The message body at each side of the Azure Files component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Consumer

file

The file as read: a RemoteFile with its content loaded as bytes, which converts to text, bytes or a stream; a stream with streamDownload; with preMove its content, a byte array.

  • With streamDownload=true: stream

  • With download=false: null

Not known when preMove is set.

Producer input

text, bytes, stream or file

What converts to an InputStream or a byte array: text, bytes, a stream or a file. A Map or a List fails: marshal it first.

  • With allowNullBody=true: null, text, bytes, stream or file

Producer output

unchanged

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Endpoint URI Examples

azure-files://camelazurefiles.file.core.windows.net/samples?sv=2022-11-02&ss=f&srt=sco&sp=rwdlc&se=2023-06-18T22:29:13Z&st=2023-06-05T14:29:13Z&spr=https&sig=MPsMh8zci0v3To7IT9SKdaFGZV8ezno63m9C8s9bdVQ%3D
azure-files://camelazurefiles/samples/inbox/spam?sharedKey=FAKE502UyuBD...3Z%2BASt9dCmJg%3D%3D&delete=true

Usage

Paths

The path separator is /. The absolute paths start with the path separator. The absolute paths do not include the share name, and they are relative to the share root rather than to the endpoint starting directory.

NOTE: At some places, namely logs of used libraries, OS-specific path separator appears, and the relative paths are relative to the share root (rather than to the current working directory or to the endpoint starting directory) so interpret them with a grain of salt.

Concurrency

This component does not support concurrency on its endpoints.

More Information

This component mimics the FTP component. So, there are more samples and details on the FTP component page.

This component uses the Azure Java SDK libraries for the actual work.

Consuming Files

The remote consumer will by default leave the consumed files untouched on the remote cloud files server. You have to configure it explicitly if you want it to delete the files or move them to another location. For example, you can use delete=true to delete the files, or use move=.done to move the files into .done sub directory.

In Camel, the .-prefixed folders are excluded from recursive polling.

The regular File consumer is different as it will by default move files to a .camel sub directory. The reason Camel does not do this by default for the remote consumer is that it may lack permissions by default to be able to move or delete files.

Body Type Options

For each matching file, the consumer sends to the Camel exchange a message with a selected body type:

  • byte[] by default

  • java.io.InputStream if streamDownload=true is configured

  • java.io.File if localWorkDirectory is configured

The body type configuration should be tuned to fit available resources, performance targets, route processors, caching, resuming, etc.

Limitations

The option readLock can be used to force Camel not to consume files that are currently in the progress of being written. However, this option is turned off by default, as it requires that the user has write access. See the endpoint options table for more details about read locks.
There are other solutions to avoid consuming files that are currently being written; for instance, you can write to a temporary destination and move the file after it has been written.

For the readLock=changed, it relies only on the last modified; furthermore a precision finer than 5 seconds might be problematic.

The azure-files consumer supports the read locks none, rename and changed. readLock=false and readLock=off mean none. Any other readLock value, such as the markerFile, fileLock, idempotent, idempotent-changed and idempotent-rename read locks of the File component, fails when the consumer is created, also with poll and pollEnrich, with IllegalArgumentException: ReadLock invalid. The readLock option is not checked when a custom exclusiveReadLockStrategy or processStrategy is set, as it does not apply then.

When moving files using move or preMove option, the files are restricted to the share. That prevents consumer from moving files outside the endpoint share.

Exchange Properties

The consumer sets the following exchange properties

Header Description

CamelBatchIndex

The current index out of total number of files being consumed in this batch.

CamelBatchSize

The total number of files being consumed in this batch.

CamelBatchComplete

True if there are no more files in this batch.

Producing Files

The Files producer is optimized for two body types:

  • java.io.InputStream if CamelFileLength header is set

  • byte[]

In either case, the remote file size is allocated and then rewritten with body content. Any inconsistency between declared file length and stream length results in a corrupted remote file.

The size is the length of the body when it is known without reading the body (a file, a byte[], a cached stream). The CamelFileLength header is only used for a stream whose length is not known otherwise: a file consumer sets this header, and it is not updated when the route changes the body. Any other body is converted to byte[].

Limitations

The underlying Azure Files service does not allow growing files. The file length must be known at its creation time, consequently:

  • CamelFileLength header has an important meaning even for producers.

  • No appending mode is supported.

About Timeouts

You can use the connectTimeout option to set a timeout in millis to connect or disconnect.

The timeout option only applies as the data timeout in millis.

The meta-data operations timeout is minimum of: readLockCheckInterval, timeout and 20_000 millis.

For now, the file upload has no timeout. During the upload, the underlying library could log timeout warnings. They are recoverable and upload could continue.

Using Local Work Directory

Camel supports consuming from remote files servers and downloading the files directly into a local work directory. This avoids reading the entire remote file content into memory as it is streamed directly into the local file using FileOutputStream.

Camel will store to a local file with the same name as the remote file, though with .inprogress as an extension while the file is being downloaded. Afterward, the file is renamed to remove the .inprogress suffix. And finally, when the Exchange is complete, the local file is deleted.

So if you want to download files from a remote files server and store it as local files, then you need to route to a file endpoint such as:

  • Java

  • XML

  • YAML

from("azure-files://...&localWorkDirectory=/tmp").to("file://inbox");
<route>
  <from uri="azure-files://...&amp;localWorkDirectory=/tmp"/>
  <to uri="file://inbox"/>
</route>
- route:
    from:
      uri: azure-files://...
      parameters:
        localWorkDirectory: /tmp
      steps:
        - to:
            uri: file://inbox

The route above is ultra efficient as it avoids reading the entire file content into memory. It will download the remote file directly to a local file stream. The java.io.File handle is then used as the Exchange body. The file producer leverages this fact and can work directly on the work file java.io.File handle and perform a java.io.File.rename to the target filename. As Camel knows it’s a local work file, it can optimize and use a rename instead of a file copy, as the work file is meant to be deleted anyway.

Custom Filtering

Camel supports pluggable filtering strategies. This strategy it to use the build in org.apache.camel.component.file.GenericFileFilter in Java. You can then configure the endpoint with such a filter to skip certain filters before being processed.

In the sample, we have built our own filter that only accepts files starting with the report in the filename.

And then we can configure our route using the filter attribute to reference our filter (using # notation) that we have defined in the spring XML file:

The accept(file) file argument has properties:

  • endpoint path: the share name such as /samples

  • relative path: a path to the file such as subdir/a file

  • directory: true if a directory

  • file length: if not a directory, then a length of the file in bytes

Filtering using ANT path matcher

The ANT path matcher is a filter shipped out-of-the-box with the file component: the antInclude and antExclude options need no other dependency. Use them for wildcards such as *.txt: the fileName option is a file name, not a pattern, and the include and exclude options are regular expressions.

The file paths are matched with the following rules:

  • ? matches one character

  • * matches zero or more characters

  • ** matches zero or more directories in a path

The sample below demonstrates how to use it:

  • Java

  • XML

  • YAML

from("azure-files://...&antInclude=**/*.txt").to("...");
<route>
  <from uri="azure-files://...&amp;antInclude=**/*.txt"/>
  <to uri="..."/>
</route>
- route:
    from:
      uri: azure-files://...
      parameters:
        antInclude: "**/*.txt"
      steps:
        - to:
            uri: "..."

Using a Proxy

Consult the underlying library documentation.

Consuming a single file using a fixed name

Unlike FTP component that features a special combination of options:

  • useList=false

  • fileName=myFileName.txt

  • ignoreFileNotFoundOrPermissionError=true

to optimize the single file using a fixed name use case, it is necessary to fall back to regular filters (i.e. the list permission is needed).

Debug logging

This component has log level TRACE that can be helpful if you have problems.