我遇到弹簧入站通道适配器的问题。导入新文件非常合适。
但是选项prevent-duplicates="false"
似乎无法正常工作 - 当具有相同名称的文件保存到指定目录时,它不会被导入。
入站通道适配器的定义:
<file:inbound-channel-adapter id="batchFilesDemo" directory="#{baseDirectoryDemo}" prevent-duplicates="false"
filename-regex="^(.*)-(\d+)\.csv" comparator="fileOrderComparator">
<int:poller fixed-rate="1000" />
</file:inbound-channel-adapter>
提前感谢任何建议!
答案 0 :(得分:0)
刚刚使用Spring Integration 4.2进行测试:
<inbound-channel-adapter id="adapterWithRegexPattern"
directory="d:\tmp\"
prevent-duplicates="false"
filename-regex="^.*\.txt">
<integration:poller fixed-rate="1000"/>
</inbound-channel-adapter>
<integration:chain input-channel="adapterWithRegexPattern">
<file-to-string-transformer/>
<integration:logging-channel-adapter level="FATAL" log-full-message="true"/>
</integration:chain>
我的日志看起来像:
[task-scheduler-1] ERROR: org.springframework.integration.handler.LoggingHandler - GenericMessage [payload=1, headers={file_originalFile=d:\tmp\1.txt, id=0dc6932a-3007-28bf-41e6-c1d8e3fcc91f, file_name=1.txt, timestamp=1443197583589}]
[task-scheduler-1] ERROR: org.springframework.integration.handler.LoggingHandler - GenericMessage [payload=2, headers={file_originalFile=d:\tmp\2.txt, id=e0f624eb-33b5-297d-7fb9-89904fc01a7a, file_name=2.txt, timestamp=1443197584560}]
[task-scheduler-2] ERROR: org.springframework.integration.handler.LoggingHandler - GenericMessage [payload=1, headers={file_originalFile=d:\tmp\1.txt, id=bd680d29-02d9-a5e8-4f8e-c14200315ed0, file_name=1.txt, timestamp=1443197585559}]
[task-scheduler-1] ERROR: org.springframework.integration.handler.LoggingHandler - GenericMessage [payload=2, headers={file_originalFile=d:\tmp\2.txt, id=a4f7d240-5a7b-d088-f987-84f0c747afe0, file_name=2.txt, timestamp=1443197586559}]
[task-scheduler-3] ERROR: org.springframework.integration.handler.LoggingHandler - GenericMessage [payload=1, headers={file_originalFile=d:\tmp\1.txt, id=a6a56195-7ed3-01d7-f52f-d08f9b395165, file_name=1.txt, timestamp=1443197587559}]
[task-scheduler-2] ERROR: org.springframework.integration.handler.LoggingHandler - GenericMessage [payload=2, headers={file_originalFile=d:\tmp\2.txt, id=68c95abb-b113-34b1-7488-cf56155845a4, file_name=2.txt, timestamp=1443197588559}]
[task-scheduler-4] ERROR: org.springframework.integration.handler.LoggingHandler - GenericMessage [payload=1, headers={file_originalFile=d:\tmp\1.txt, id=a58cab74-bd45-be4c-d7ee-853df5818cfa, file_name=1.txt, timestamp=1443197589560}]
[task-scheduler-1] ERROR: org.springframework.integration.handler.LoggingHandler - GenericMessage [payload=2, headers={file_originalFile=d:\tmp\2.txt, id=a9ba0460-6f37-deed-35ce-03149b23f636, file_name=2.txt, timestamp=1443197590559}]
[task-scheduler-5] ERROR: org.springframework.integration.handler.LoggingHandler - GenericMessage [payload=111111, headers={file_originalFile=d:\tmp\1.txt, id=d6de0d59-1877-e3e8-da21-8f668ec79e72, file_name=1.txt, timestamp=1443197591560}]
[task-scheduler-3] ERROR: org.springframework.integration.handler.LoggingHandler - GenericMessage [payload=2, headers={file_originalFile=d:\tmp\2.txt, id=23b36d87-0d60-0d7a-c2c7-696cf93680f7, file_name=2.txt, timestamp=1443197592559}]
[task-scheduler-6] ERROR: org.springframework.integration.handler.LoggingHandler - GenericMessage [payload=111111, headers={file_originalFile=d:\tmp\1.txt, id=98de0104-2837-6ed1-22a3-1f69292ab5af, file_name=1.txt, timestamp=1443197593559}]
[task-scheduler-2] ERROR: org.springframework.integration.handler.LoggingHandler - GenericMessage [payload=2, headers={file_originalFile=d:\tmp\2.txt, id=d303e0cc-4657-6548-e08e-863b1089528a, file_name=2.txt, timestamp=1443197594559}]
[task-scheduler-7] ERROR: org.springframework.integration.handler.LoggingHandler - GenericMessage [payload=111111, headers={file_originalFile=d:\tmp\1.txt, id=861ffa79-c76d-8216-1620-da50c53bf83c, file_name=1.txt, timestamp=1443197595560}]
[task-scheduler-4] ERROR: org.springframework.integration.handler.LoggingHandler - GenericMessage [payload=2, headers={file_originalFile=d:\tmp\2.txt, id=f63680c5-11c7-e303-9338-9dd5028b7bcb, file_name=2.txt, timestamp=1443197596559}]
[task-scheduler-8] ERROR: org.springframework.integration.handler.LoggingHandler - GenericMessage [payload=111111, headers={file_originalFile=d:\tmp\1.txt, id=7e565984-0dab-6187-5969-2bc9a5104d49, file_name=1.txt, timestamp=1443197597559}]
[task-scheduler-1] ERROR: org.springframework.integration.handler.LoggingHandler - GenericMessage [payload=2, headers={file_originalFile=d:\tmp\2.txt, id=0ae04d1c-a9c9-1877-2025-248c2f387c5a, file_name=2.txt, timestamp=1443197598559}]
等等。
请注意我在那里有永远从目录中获取的相同的两个文件,请查看文件1.txt
的内容是如何更改的,并且它也反映在我的应用程序中。
所以,或者你的fileOrderComparator
为我们做了一些意想不到的事情。或者您的文件不适合该模式。
答案 1 :(得分:0)
谢谢Artem!
确实是我的 FileOrderComparator 使用Map来确定文件名的文件优先级,因此类似的文件名总是阻止导入。
我正在使用Spring Integration版本4.1.2。