我有一个SI从文件夹中读取的文件,但我的应用程序部署在两个集群上,因此该文件被读取了两次,所以我使用了spring Integration中提供的文件锁机制,但在这种情况下,我发现我的文件根本没有被处理。我错过了什么?
更新:我正在使用FileInbound适配器以这种方式使用FileLocker类
private FileInboundChannelAdapterSpec readFilefromDirectory(){
return Files.inboundAdapter(getInboxDirectory())
.autoCreateDirectory(true)
.locker(asFileLocker)
.preventDuplicates();
}
@Component
public class ASFileLocker implements FileLocker{
@Autowired
Properties properties;
@Override
public boolean lock(File fileToLock) {
try{
if(properties.getProperty("fileName").equalsIgnoreCase(fileToLock.getName())){
return false;
}
else{
properties.setProperty("fileName", fileToLock.getName());
return true;
}
}catch(Exception e){
return false;
}
}
@Override
public boolean isLockable(File file) {
String fileName= properties.getProperty("fileName");
if(fileName.equalsIgnoreCase(file.getName())){
return true;
}
else{
return false;
}
}
@Override
public void unlock(File fileToUnlock) {
}发布于 2016-09-20 01:32:34
要读取文件内容,必须使用FileLock中的FileChannel。
但是无法从NioFileLocker访问该对象。
考虑改用FileSystemPersistentAcceptOnceFileListFilter。当然是使用共享MetadataStore。在这种情况下,您的文件将仅由应用程序的一个实例拾取。
https://stackoverflow.com/questions/39578125
复制相似问题