【问题标题】:Spring Integration SFTP channel adapter not sending the message to the down stream service activator for the second pollingSpring Integration SFTP 通道适配器未将消息发送到下游服务激活器以进行第二次轮询
【发布时间】:2016-12-14 19:31:52
【问题描述】:

我正在尝试实现简单的 SFTP 通道适配器以接受具有任何文件名的文件(以允许重复的文件名)。对于第一次轮询,文件从 SFTP 服务器目录传输到本地目录,订阅此频道的服务激活器能够接收消息,但第二次如果我在 SFTP 服务器中保留同名文件,则文件已传输,但服务激活器无法获取消息。我尝试实现本地过滤器,但它进入了无限循环(轮询文件并创建消息)。

配置

<int:channel id="inboundMGetRecursive">
    <int:queue/>
</int:channel>

<int-sftp:inbound-channel-adapter id="sftpInboundAdapter"
                                  auto-startup="true"
                                  channel="channel1"
                                  session-factory="sftpSessionFactory"
                                  local-directory="c:/tmp/"
                                  remote-directory="${sftp.file.remote.inbound.dir}"
                                  auto-create-local-directory="false"
                                  filename-pattern="*.txt"
                                  local-filter="acceptAll">
    <int:poller fixed-delay="60000" error-channel="sftpExceptionsChannel"
                max-messages-per-poll="-1"/>
<bean id="acceptAll" class="org.springframework.integration.file.filters.AcceptAllFileListFilter"/
<int:service-activator id="serviceActivator" input-channel="channel1" ref="fileMoverHandler"
                       method="method1">
    <int:poller fixed-rate="3000" max-messages-per-poll="-1"/>
</int:service-activator>

无限循环日志

2016-12-14 13:25:39,632 [task-scheduler-1] [handlers.FileFilter] INFO  - Filter Activated
2016-12-14 13:25:39,635 [task-scheduler-1] [handlers.FileFilter] INFO  - file name : config.txt
2016-12-14 13:25:39,636 [task-scheduler-1] [file.FileReadingMessageSource] DEBUG - Added to queue: [C:\tmp\csvfiles\staging\config.txt]
2016-12-14 13:25:39,636 [task-scheduler-1] [file.FileReadingMessageSource] INFO  - Created message: [GenericMessage [payload=C:\tmp\csvfiles\staging\config.txt, headers={id=4a062556-4181-2806-d2ee-c0aa3221aec3, timestamp=1481743539636}]]
2016-12-14 13:25:39,636 [task-scheduler-1] [endpoint.SourcePollingChannelAdapter] DEBUG - Poll resulted in Message: GenericMessage [payload=C:\tmp\csvfiles\staging\config.txt, headers={id=4a062556-4181-2806-d2ee-c0aa3221aec3, timestamp=1481743539636}]
2016-12-14 13:25:39,636 [task-scheduler-1] [channel.QueueChannel] DEBUG - preSend on channel 'inboundMGetRecursive', message: GenericMessage [payload=C:\tmp\csvfiles\staging\config.txt, headers={id=4a062556-4181-2806-d2ee-c0aa3221aec3, timestamp=1481743539636}]
2016-12-14 13:25:39,636 [task-scheduler-1] [channel.QueueChannel] DEBUG - postSend (sent=true) on channel 'inboundMGetRecursive', message: GenericMessage [payload=C:\tmp\csvfiles\staging\config.txt, headers={id=4a062556-4181-2806-d2ee-c0aa3221aec3, timestamp=1481743539636}]
2016-12-14 13:25:39,637 [task-scheduler-1] [handlers.FileFilter] INFO  - Filter Activated
2016-12-14 13:25:39,637 [task-scheduler-1] [handlers.FileFilter] INFO  - file name : config.txt
2016-12-14 13:25:39,637 [task-scheduler-1] [file.FileReadingMessageSource] DEBUG - Added to queue: [C:\tmp\csvfiles\staging\config.txt]
2016-12-14 13:25:39,638 [task-scheduler-1] [file.FileReadingMessageSource] INFO  - Created message: [GenericMessage [payload=C:\tmp\csvfiles\staging\config.txt, headers={id=a2df4814-f759-0440-8ce2-c8d969a9315d, timestamp=1481743539638}]]
2016-12-14 13:25:39,638 [task-scheduler-1] [endpoint.SourcePollingChannelAdapter] DEBUG - Poll resulted in Message: GenericMessage [payload=C:\tmp\csvfiles\staging\config.txt, headers={id=a2df4814-f759-0440-8ce2-c8d969a9315d, timestamp=1481743539638}]
2016-12-14 13:25:39,638 [task-scheduler-1] [channel.QueueChannel] DEBUG - preSend on channel 'inboundMGetRecursive', message: GenericMessage [payload=C:\tmp\csvfiles\staging\config.txt, headers={id=a2df4814-f759-0440-8ce2-c8d969a9315d, timestamp=1481743539638}]
2016-12-14 13:25:39,639 [task-scheduler-1] [channel.QueueChannel] DEBUG - postSend (sent=true) on channel 'inboundMGetRecursive', message: GenericMessage [payload=C:\tmp\csvfiles\staging\config.txt, headers={id=a2df4814-f759-0440-8ce2-c8d969a9315d, timestamp=1481743539638}]
2016-12-14 13:25:39,639 [task-scheduler-1] [handlers.FileFilter] INFO  - Filter Activated
2016-12-14 13:25:39,639 [task-scheduler-1] [handlers.FileFilter] INFO  - file name : config.txt
2016-12-14 13:25:39,640 [task-scheduler-1] [file.FileReadingMessageSource] DEBUG - Added to queue: [C:\tmp\csvfiles\staging\config.txt]
2016-12-14 13:25:39,640 [task-scheduler-1] [file.FileReadingMessageSource] INFO  - Created message: [GenericMessage [payload=C:\tmp\csvfiles\staging\config.txt, headers={id=fd1ace38-6550-82ea-89c5-2a6229463167, timestamp=1481743539640}]]
2016-12-14 13:25:39,640 [task-scheduler-1] [endpoint.SourcePollingChannelAdapter] DEBUG - Poll resulted in Message: GenericMessage [payload=C:\tmp\csvfiles\staging\config.txt, headers={id=fd1ace38-6550-82ea-89c5-2a6229463167, timestamp=1481743539640}]
2016-12-14 13:25:39,640 [task-scheduler-1] [channel.QueueChannel] DEBUG - preSend on channel 'inboundMGetRecursive', message: GenericMessage [payload=C:\tmp\csvfiles\staging\config.txt, headers={id=fd1ace38-6550-82ea-89c5-2a6229463167, timestamp=1481743539640}]
2016-12-14 13:25:39,640 [task-scheduler-1] [channel.QueueChannel] DEBUG - postSend (sent=true) on channel 'inboundMGetRecursive', message: GenericMessage [payload=C:\tmp\csvfiles\staging\config.txt, headers={id=fd1ace38-6550-82ea-89c5-2a6229463167, timestamp=1481743539640}]

请帮助我如何使用过滤器来接受所有文件。

【问题讨论】:

    标签: java spring spring-integration spring-integration-sftp


    【解决方案1】:

    当使用接受所有本地过滤器时,您需要在处理完成后从本地磁盘中删除/重命名文件,然后再进行下一次轮询。

    除非您还删除了远程文件,否则您还应该在远程过滤器中使用FtpPersistentAcceptOnceFileListFilter,以便在修改时间戳更改之前不会重新获取文件。

    【讨论】:

    • 感谢加里的回复。但是它在一秒钟内轮询了很多次,尽管我有 1 分钟的轮询固定延迟。如果我遗漏了什么,请纠正我。
    • 不要使用队列通道;从频道中删除 &lt;int:queue/&gt; 并从服务激活器中删除轮询器。它现在将在适配器的轮询线程上运行。必须在适配器轮询器的线程返回到轮询器之前删除该文件。
    • 我已经从通道中删除了队列,还从服务激活器中删除了轮询器,但入站通道适配器仍然在 1 秒内第二次轮询多次。当我只保留本地过滤器时会发生这种情况。
    • 使用max-messages-per-poll="-1",我们将继续返回文件,直到没有一个文件通过过滤器。然后轮询器休眠。如果您每次投票只需要一个文件,请使用="1"
    猜你喜欢
    • 1970-01-01
    • 2012-07-22
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 2019-06-29
    • 2020-12-03
    • 2017-04-29
    • 1970-01-01
    相关资源
    最近更新 更多