- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试构建一个简单的 Spring Integration 文件夹用于数据导入。但在处理最后一个文件时,进程会抛出 NoSuchFileException
。我正在使用 Spring 5.0.5(在本演示中使用 Spring Boot 2.0.1)
配置:
<bean id="dataImporter" class="com.example.demo.DataImporter" />
<bean id="XMLFileListFilter" class="org.springframework.integration.file.filters.SimplePatternFileListFilter" >
<constructor-arg value="*.xml" />
</bean>
<bean id="XMLFilter" class="org.springframework.integration.file.config.FileListFilterFactoryBean">
<property name="filter" ref="XMLFileListFilter" />
<property name="preventDuplicates" value="false" />
</bean>
<bean id="importFileComparator" class="com.example.demo.ImportFileComparator" />
<!--Input channel-->
<int-file:inbound-channel-adapter id="FilesInChannel"
directory="file:C:/Users/USER/Desktop/SI-Failing"
filter="XMLFilter"
auto-startup="true">
<int:poller fixed-rate="1000" time-unit="MILLISECONDS" max-messages-per-poll="1" />
</int-file:inbound-channel-adapter>
<!--Output channel-->
<int:recipient-list-router input-channel="FilesOutChannel"
default-output-channel="FilesOutSuccessChannel" >
<int:recipient channel="FilesOutFailureChannel" selector-expression="headers.containsKey('IMPORT_FAILURE')" />
</int:recipient-list-router>
<!--Success / Failure channel-->
<int-file:outbound-channel-adapter id="FilesOutSuccessChannel"
directory="file:C:/Users/USER/Desktop/SI-Failing/success/" delete-source-files="true"
filename-generator-expression="new java.text.SimpleDateFormat('yyyy-MM-dd_HH.mm.ss').format(new java.util.Date()) + '_' + payload.name"/>
<int-file:outbound-channel-adapter id="FilesOutFailureChannel"
directory="file:C:/Users/USER/Desktop/SI-Failing/error" delete-source-files="true"
filename-generator-expression="new java.text.SimpleDateFormat('yyyy-MM-dd_HH.mm.ss').format(new java.util.Date()) + '_' + payload.name"/>
<!--Verheiratung zwischen Importer, Input und Output-->
<int:service-activator
ref="dataImporter"
input-channel="FilesInChannel"
output-channel="FilesOutChannel" />
这是导入处理程序:
public class DataImporter {
public Message<File> handleFileImport(Message<File> message) {
final File file = message.getPayload();
System.out.println("Processing file " + file);
return message;
}
}
当将 3 个 XML 文件放入该文件夹时,将生成以下日志消息:
2018-05-09 13:47:34.989 INFO 6888 --- [ask-scheduler-5]
o.s.i.file.FileReadingMessageSource : Created message: [GenericMessage [payload=C:\Users\fischer\Desktop\SI-Failing\typeA_1.xml, headers={file_originalFile=C:\Users\fischer\Desktop\SI-Failing\typeA_1.xml, id=29b41c2e-3302-ca26-93a5-423f6f57fd4d, file_name=typeA_1.xml, file_relativePath=typeA_1.xml, timestamp=1525866454989}]]
Processing file C:\Users\fischer\Desktop\SI-Failing\typeA_1.xml
2018-05-09 13:47:35.986 INFO 6888 --- [ask-scheduler-3] o.s.i.file.FileReadingMessageSource : Created message: [GenericMessage [payload=C:\Users\fischer\Desktop\SI-Failing\typeA_2.xml, headers={file_originalFile=C:\Users\fischer\Desktop\SI-Failing\typeA_2.xml, id=4fe71062-12b0-3649-56de-8c432ae2c6e4, file_name=typeA_2.xml, file_relativePath=typeA_2.xml, timestamp=1525866455986}]]
Processing file C:\Users\fischer\Desktop\SI-Failing\typeA_2.xml
2018-05-09 13:47:35.991 ERROR 6888 --- [ask-scheduler-3] o.s.integration.handler.LoggingHandler : org.springframework.messaging.MessageHandlingException: failed to write Message payload to file; nested exception is java.nio.file.NoSuchFileException: C:\Users\fischer\Desktop\SI-Failing\typeA_2.xml, failedMessage=GenericMessage [payload=C:\Users\fischer\Desktop\SI-Failing\typeA_2.xml, headers={file_originalFile=C:\Users\fischer\Desktop\SI-Failing\typeA_2.xml, id=4fe71062-12b0-3649-56de-8c432ae2c6e4, file_name=typeA_2.xml, file_relativePath=typeA_2.xml, timestamp=1525866455986}]
at org.springframework.integration.file.FileWritingMessageHandler.handleRequestMessage(FileWritingMessageHandler.java:590)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:109)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:158)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:132)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:105)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:445)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:394)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:181)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:160)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:47)
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:108)
at org.springframework.integration.router.AbstractMessageRouter.handleMessageInternal(AbstractMessageRouter.java:200)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:158)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:132)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:105)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:445)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:394)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:181)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:160)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:47)
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:108)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:426)
at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:336)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:227)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:115)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:158)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:132)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:105)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:445)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:394)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:181)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:160)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:47)
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:108)
at org.springframework.integration.endpoint.SourcePollingChannelAdapter.handleMessage(SourcePollingChannelAdapter.java:220)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:277)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.lambda$run$0(AbstractPollingEndpoint.java:378)
at org.springframework.integration.util.ErrorHandlingTaskExecutor.lambda$execute$0(ErrorHandlingTaskExecutor.java:53)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:51)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:372)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.nio.file.NoSuchFileException: C:\Users\fischer\Desktop\SI-Failing\typeA_2.xml
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
at sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:318)
at sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:287)
at java.nio.file.Files.move(Files.java:1395)
at org.springframework.integration.file.FileWritingMessageHandler.rename(FileWritingMessageHandler.java:1030)
at org.springframework.integration.file.FileWritingMessageHandler.handleFileMessage(FileWritingMessageHandler.java:626)
at org.springframework.integration.file.FileWritingMessageHandler.handleRequestMessage(FileWritingMessageHandler.java:559)
... 55 more
似乎 spring 试图获取一个本身已经放入 success
文件夹中的文件,因此失败并出现 NoSuchFileException
...我做错了什么?
如果需要,我可以提供一个 Spring Boot 演示应用程序:https://www.dropbox.com/s/7fwr9qi84c03u85/demo.7z?dl=0
最佳答案
您的问题出在 <property name="preventDuplicates" value="false" />
.
这样<int-file:inbound-channel-adapter>
将能够在下一个轮询周期再次轮询同一文件。不过我发现没关系,因为你有 delete-source-files="true"
两者<int-file:outbound-channel-adapter>
。所以,preventDuplicates
选择并不是那么重要。
这是值得思考的一点。另一个我认为是罪魁祸首的是:fixed-rate="1000"
。当您长时间处理文件时,调度程序可能会启动新的轮询任务,因此可能会拾取相同的文件,因为您尚未到达 <int-file:outbound-channel-adapter>
用于删除。考虑切换到fixed-delay="1000"
相反。
更新
您的解决方案是这样的:
<bean id="XMLFileListFilter" class="org.springframework.integration.file.filters.SimplePatternFileListFilter" >
<constructor-arg value="*.xml" />
</bean>
<bean id="acceptOnceFileListFilter"
class="org.springframework.integration.file.filters.FileSystemPersistentAcceptOnceFileListFilter">
<constructor-arg>
<bean class="org.springframework.integration.metadata.SimpleMetadataStore"/>
</constructor-arg>
<constructor-arg value="foo"/>
</bean>
<bean id="XMLFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
<constructor-arg>
<list>
<ref bean="XMLFileListFilter"/>
<ref bean="acceptOnceFileListFilter"/>
</list>
</constructor-arg>
</bean>
关注FileSystemPersistentAcceptOnceFileListFilter
。正如我在下面的一条评论中所说,最好不要传递同一文件,但它可以跟踪同一文件的修改。因此,您可以将同一文件的新版本放入该目录,只要其时间戳是最新的,该文件就会被 <int-file:inbound-channel-adapter>
拾取。 .
关于java - Spring Integration 抛出 NoSuchFileException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50252921/
我目前是一群学生的团队负责人,他们正在为一门类(class)的项目工作,该类(class)目前由电气和计算机工程专业的学生组成。我是一名电气工程专业的学生,我还没有开始研究该项目的软件组件。我觉得
我们对 spring-integration 非常满意,除非事情没有按预期工作。然后真的很难找出发生了什么(我们使用的是xml配置)。有人可以将我指向 spring 集成组件背后的 java 组件以便
我需要评估几个积分,我正在使用正常 (0,1) 密度来测试。 在 python 中 import scipy.integrate as integrate import scipy.stats imp
我想保留原始请求的原始有效负载并将其放在 xslt-transformer 或其他操作中。我丢失了它,因为我使用了 xslt-transformer,并且我只需要转换中的一些元素。所以我的场景是: 1
我想知道在 Spring Integration 中使消息不可变的原因是什么。 仅仅是因为多线程环境中的线程安全吗? 表现?当您每次要向现有消息添加某些内容时都必须创建新消息时,您不会受到性能惩罚吗?
我有一个偶尔会返回 503 错误的 http 网关调用。我想配置 retry advice围绕那个调用,但我不想为每个错误都这样做,只是 503s。 我已经配
我们正在使用 Spring Integration 4.2.3 聚合器组件和定义的组超时,并期望组在给定的超时值内超时,同时向组添加消息和发布大小标准不满足。 但我们看到了不同的结果,当我们向服务输入
我需要轮询邮件服务器。由于我的项目已经在 Spring 中,我使用 Spring-Integration 来轮询邮件服务器。我在这方面很成功。但现在我必须轮询多封电子邮件。有人可以告诉我该怎么做吗。
现在,我正在从事的项目已经达到了一个复杂的水平,需要完成多个步骤(实际上,它变得不可思议!)才能生产出完整/可用的产品。不幸的是,我们并不是从Continuos Integration的心态开始的,所
哪些指标表明应该使用企业集成模式框架?另一方面,哪些指标表明应该坚持使用简单的旧代码进行逻辑流? 就我而言,我们将 Spring Integration 应用于映射/处理应用程序,该应用程序从数据库读
我们在 XML 中有以下工作配置,并正在尝试转换为 DSL。不确定它们是否等效,也尝试使用 inboundAdapter。但是,我无法弄清楚如何在那里设置与并发相关的值。有人可以建议他们是否在 DSL
所以我在玩这个: factors :: Integral a => a -> [a] factors n = filter (\d -> n `rem` d == 0) . takeWhile (\d
我是 Spring 集成的新手,正在尝试建模一个流程,其中我通过 HTTP 进行同步请求和响应,但也是交付的同一流程的一部分将响应发送到队列,对其进行后处理,并让一个单独的进程使用该响应。所以从调用流
我有一个 Spring Integration Flow 项目,它公开了一个 Rest 网关,在收到 Rest POST 请求后,它会执行一些小逻辑。基于一些有效负载参数,我想动态激活另一个 Spri
我浏览了 Internet,在 Spring 论坛上发帖,并阅读了几乎全部在线文档,但我无法弄清楚 Spring Integration 是否可以在单个多资源 (JTA) 事务中处理多个消息。这对于我
我正在查看 spring-projects/spring-integration-samples 中的聚合器示例。 https://github.com/spring-projects/spring-
我正在查看 spring-projects/spring-integration-samples 中的聚合器示例。 https://github.com/spring-projects/spring-
我有一个 spring-integration接受 org.w3c.dom.Document 并返回域对象的转换器。这很好。如果缺少元素,我会引发应用程序异常。 但是,我想将该异常放到错误 chann
我显然已经通读了 documentation , 但我无法找到更详细的幕后情况描述。具体来说,有几个行为我很疑惑: 一般设置 import numpy as np from scipy.integra
我正在使用 Spring Integration 使用以下配置从目录中读取文件。但是,我希望在找到任何文件后停止轮询,直到服务不再重新启动为止。有什么方法可以在运行时更改轮询器延迟或在运行时启动/停止
我是一名优秀的程序员,十分优秀!