简体   繁体   中英

Spring Integration File Support

In Spring Integration how to prevent two different machines to work in the same file? I know that nio library(javaSE) provides a mechanism to lock File FileLocker but how can I implement it using Spring Integration? A concrete example would be appreciated.

There is indeed a org.springframework.integration.file.locking.NioFileLocker implementation which can be used for the FileReadingMessageSource option like:

/**
 * Optional. Sets a {@link FileLocker} to be used to guard files against
 * duplicate processing.
 * <p>
 * <b>The supplied FileLocker must be thread safe</b>
 * @param locker a locker
 */
public void setLocker(FileLocker locker) {

From the XML perspective it is like this:

<file:inbound-channel-adapter>
    <file:nio-locker/>
</file:inbound-channel-adapter>

More info is in the Reference Manual .

Another option to avoid concurrent access and duplication in differen JVMs is like using FileSystemPersistentAcceptOnceFileListFilter with the shared persistent ConcurrentMetadataStore : https://docs.spring.io/spring-integration/docs/5.0.3.RELEASE/reference/html/files.html#file-reading

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM