Inbound Channel Adapters: Controlling Remote File Fetching
在配置入站通道适配器时,应考虑两个属性。max-messages-per-poll
(与所有轮询器一样)可用于限制每次轮询中发出的消息数(如果已准备就绪的消息数超过配置值)。max-fetch-size
(自版本 5.0 起)可以限制一次从远程服务器检索的文件数。
There are two properties that you should consider when you configure inbound channel adapters.
max-messages-per-poll
, as with all pollers, can be used to limit the number of messages emitted on each poll (if more than the configured value are ready).
max-fetch-size
(since version 5.0) can limit the number of files retrieved from the remote server at one time.
以下场景假设起始状态是一个空本地目录:
The following scenarios assume the starting state is an empty local directory:
-
max-messages-per-poll=2
andmax-fetch-size=1
: The adapter fetches one file, emits it, fetches the next file, emits it, and then sleeps until the next poll. -
max-messages-per-poll=2
andmax-fetch-size=2
): The adapter fetches both files and then emits each one. -
max-messages-per-poll=2
andmax-fetch-size=4
: The adapter fetches up to four files (if available) and emits the first two (if there are at least two). The next two files are emitted on the next poll. -
max-messages-per-poll=2
andmax-fetch-size
not specified: The adapter fetches all remote files and emits the first two (if there are at least two). The subsequent files are emitted on subsequent polls (two at a time). When all files are consumed, the remote fetch is attempted again, to pick up any new files.
当您部署应用程序的多个实例时,我们建议使用较小的 max-fetch-size
,以避免一个实例 “grabbing” 所有文件并使其他实例匮乏。
When you deploy multiple instances of an application, we recommend a small max-fetch-size
, to avoid one instance “grabbing” all the files and starving other instances.
如果您想停止获取远程文件但继续处理已获取的文件,则 @{69} 的另一种用途是。对 @{71}(通过编程、使用 JMX 或 @{72})设置 @{70} 属性会有效阻止适配器获取更多文件,但允许轮询器继续为先前已获取的文件发出消息。如果属性更改时轮询器处于活动状态,则更改将在下次轮询中生效。
Another use for max-fetch-size
is if you want to stop fetching remote files but continue to process files that have already been fetched.
Setting the maxFetchSize
property on the MessageSource
(programmatically, with JMX, or with a control bus) effectively stops the adapter from fetching more files but lets the poller continue to emit messages for files that have previously been fetched.
If the poller is active when the property is changed, the change takes effect on the next poll.
从版本 5.1 开始,可以使用 Comparator<FTPFile>
为同步器提供。在使用 maxFetchSize
限制所获取文件数时,这非常有用。
Starting with version 5.1, the synchronizer can be provided with a Comparator<FTPFile>
.
This is useful when restricting the number of files fetched with maxFetchSize
.