我使用Spring Integration(smb实现)从windows share读取文件。
我们创建了入站文件适配器,它定期读取共享位置。当我们有大于100 mb的文件时,当inboud poller处理它时,用户会更新此文件。一旦用户使用相同的名称替换新文件,轮询器就会在处理过程中断。
请你帮忙解决一下这个问题。
编辑 - 为此org.springframework.integration调试添加日志
我已配置DirectChannel
入站适配器和服务激活器。
当轮询器开始读取大文件时
2017-04-26 06:50:50.485 DEBUG 9892 --- [ask-scheduler-1] o.s.i.smb.session.SmbSessionFactory : SMB share initialized.
2017-04-26 06:50:50.485 DEBUG 9892 --- [ask-scheduler-1] o.s.integration.smb.session.SmbSession : New org.springframework.integration.smb.session.SmbSession created.
2017-04-26 06:50:50.485 DEBUG 9892 --- [ask-scheduler-1] o.s.integration.smb.session.SmbSession : Created new jcifs.smb.SmbFile[smb://xxx@xxxx//Tracker/Test/] for path [Test/].
2017-04-26 06:50:50.516 DEBUG 9892 --- [ask-scheduler-1] o.s.integration.smb.session.SmbSession : Successfully listed 1 resource(s) in [Test/]: [smb://xxx@xxxx//Tracker/Test/data.txt]
2017-04-26 06:50:50.516 DEBUG 9892 --- [ask-scheduler-1] o.s.integration.smb.session.SmbSession : Created new jcifs.smb.SmbFile[smb://xxx@xxxx//Tracker/ /Test/data.txt] for path [Test//data.txt].
文件仍在编写中,然后用户修改远程文件
2017-04-26 06:51:21.062 INFO 9892 --- [ask-scheduler-1] o.s.integration.smb.session.SmbSession : Successfully read resource [Test//data.txt].
2017-04-26 06:51:21.065 DEBUG 9892 --- [ask-scheduler-1] o.s.i.s.i.SmbInboundFileSynchronizer : 1 files transferred
2017-04-26 06:51:21.080 DEBUG 9892 --- [ask-scheduler-1] o.s.i.file.FileReadingMessageSource : Added to queue: [smb-inbound\data.txt]
2017-04-26 06:51:21.080 INFO 9892 --- [ask-scheduler-1] o.s.i.file.FileReadingMessageSource : Created message: [GenericMessage [payload=smb-inbound\data.txt, headers={id=ed02c489-8e7d-4c6b-0e25-25f85ed3c6f5, timestamp=1493207481080}]]
2017-04-26 06:51:21.080 DEBUG 9892 --- [ask-scheduler-1] o.s.i.e.SourcePollingChannelAdapter : Poll resulted in Message: GenericMessage [payload=smb-inbound\data.txt, headers={id=ed02c489-8e7d-4c6b-0e25-25f85ed3c6f5, timestamp=1493207481080}]
2017-04-26 06:51:21.080 DEBUG 9892 --- [ask-scheduler-1] o.s.integration.channel.DirectChannel : preSend on channel 'smbFileInputChannel', message: GenericMessage [payload=smb-inbound\data.txt, headers={id=ed02c489-8e7d-4c6b-0e25-25f85ed3c6f5, timestamp=1493207481080}]
2017-04-26 06:51:21.080 DEBUG 9892 --- [ask-scheduler-1] o.s.i.handler.ServiceActivatingHandler : ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProcessor@bfc322c] (smbConfig.serviceActivator.serviceActivator.handler) received message: GenericMessage [payload=smb-inbound\data.txt, headers={id=ed02c489-8e7d-4c6b-0e25-25f85ed3c6f5, timestamp=1493207481080}]
received file : data.txt
2017-04-26 06:51:21.096 DEBUG 9892 --- [ask-scheduler-1] o.s.i.handler.ServiceActivatingHandler : handler 'ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProcessor@bfc322c] (smbConfig.serviceActivator.serviceActivator.handler)' produced no reply for request Message: GenericMessage [payload=smb-inbound\data.txt, headers={id=ed02c489-8e7d-4c6b-0e25-25f85ed3c6f5, timestamp=1493207481080}]
2017-04-26 06:51:21.096 DEBUG 9892 --- [ask-scheduler-1] o.s.integration.channel.DirectChannel : postSend (sent=true) on channel 'smbFileInputChannel', message: GenericMessage [payload=smb-inbound\data.txt, headers={id=ed02c489-8e7d-4c6b-0e25-25f85ed3c6f5, timestamp=1493207481080}]
答案 0 :(得分:0)
我想我们可以使用SmbRemoteFileTemplate rt?
这正是从SmbSession
下载SmbFile
所使用的内容。我想知道我们是否可以覆盖createSmbFileObject()
仅向FILE_SHARE_READ
ctor提供SmbFile
。因为默认情况下它就像:
private int shareAccess = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
其中:
/**
* When specified as the <tt>shareAccess</tt> constructor parameter,
* other SMB clients will be permitted to write to the target file while
* this file is open. This constant may be logically OR'd with other share
* access flags.
*/
public static final int FILE_SHARE_WRITE = 0x02;
因此,当已经打开它时,可以从其他进程写入。
我建议你就此事https://github.com/spring-projects/spring-integration-extensions/issues提出GH问题,我们真的可以尝试专门写作。