简体   繁体   English

Spring Integration-如何处理LoggingHandler的异常

[英]Spring Integration - How to handle exception from LoggingHandler

I have been working on Spring Integration File Support where I need to move file from input directory to output directory. 我一直在进行Spring Integration File Support,在那里我需要将文件从输入目录移到输出目录。 After it is successfully moved to output directory it should be archived and then deleted from the input directory. 成功移动到输出目录后,应将其存档,然后从输入目录中删除。 I am using the below configuration to achieve this. 我正在使用以下配置来实现此目的。

Please correct me if my configuration can be better way. 如果我的配置更好,请更正我。

Spring Integration Configuration: Spring集成配置:

    <int:channel id="inboundFileChannel"/>
<int:channel id="outboundFileChannel"/>
<int:channel id="archiveFileChannel"/>

 <int-file:inbound-channel-adapter channel="inboundFileChannel"
                              directory="file://${file.input.dir}" filename-pattern="*.txt" auto-startup="true" auto-create-directory="false">
    <int:poller fixed-rate="${file.poller.interval}"/>
</int-file:inbound-channel-adapter>

<int:service-activator input-channel="inboundFileChannel" output-channel="outboundFileChannel" ref="fileHandler"/>

<int-file:outbound-gateway request-channel="outboundFileChannel" reply-channel ="archiveFileChannel" directory="file://${file.output.dir}"
                           mode="REPLACE" delete-source-files="false" auto-create-directory="false" />

<int:service-activator input-channel="archiveFileChannel" ref="archiveFileHandler" method="copyToArchiveDirectory"/>

<int:logging-channel-adapter channel="inboundFileChannel" level="DEBUG"/>

<bean id="fileHandler" class="FileHandler"/>
<bean id="archiveFileHandler" class="ArchiveFileHandler"/>

I have code in service activator if archive directory is not available it should terminate the application. 如果存档目录不可用,我在服务激活器中有代码,它将终止应用程序。 So while running the application , after the first time the file is moved I have deleted the archive directory. 因此,在运行应用程序时,第一次移动文件后,我已删除了存档目录。 then i placed new file in input directory and the file is polled and sent to a channel but the service activator handler is not picked up and does not check for archive directory exists or not. 然后我在输入目录中放置了新文件,并且对该文件进行了轮询并发送到通道,但是未激活服务激活处理程序,并且不检查是否存在存档目录。

I have found out from the logs that the message is sent to the ServiceActivatorHandler for the first time and moved the file but for the second time message is sent to LoggingHandler. 我从日志中发现,消息是第一次发送到ServiceActivatorHandler并移动了文件,但是第二次将消息发送到LoggingHandler。

2016-09-30 14:27:36,593 [task-scheduler-1] [file.FileReadingMessageSource] INFO  - Created message: [GenericMessage [payload=c:\tmp\csvfiles\input\test1.txt, headers={id=4f03f37d-7bb4-d630-72c0-360fd07d3b88, timestamp=1475263656593}]]
2016-09-30 14:27:36,593 [task-scheduler-1] [endpoint.SourcePollingChannelAdapter] DEBUG - Poll resulted in Message: GenericMessage [payload=c:\tmp\csvfiles\input\test1.txt, headers={id=4f03f37d-7bb4-d630-72c0-360fd07d3b88, timestamp=1475263656593}]
2016-09-30 14:27:36,593 [task-scheduler-1] [channel.DirectChannel] DEBUG - preSend on channel 'inboundFileChannel', message: GenericMessage [payload=c:\tmp\csvfiles\input\test1.txt, headers={id=4f03f37d-7bb4-d630-72c0-360fd07d3b88, timestamp=1475263656593}]
2016-09-30 14:27:36,624 [task-scheduler-1] [handler.ServiceActivatingHandler] DEBUG - ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProcessor@3d1024ab] received message: GenericMessage [payload=c:\tmp\csvfiles\input\test1.txt, headers={id=4f03f37d-7bb4-d630-72c0-360fd07d3b88, timestamp=1475263656593}]
2016-09-30 14:27:36,640 [task-scheduler-1] [handlers.FileHandler] INFO  - File : c:\tmp\csvfiles\input\test1.txt is copied to : c:/tmp/csvfiles/output/
2016-09-30 14:27:36,640 [task-scheduler-1] [channel.DirectChannel] DEBUG - preSend on channel 'outboundFileChannel', message: GenericMessage [payload=c:\tmp\csvfiles\input\test1.txt, headers={id=f53fbb89-d2f2-caab-f40b-cbd825238950, timestamp=1475263656640}]
2016-09-30 14:27:36,640 [task-scheduler-1] [file.FileWritingMessageHandler] DEBUG - org.springframework.integration.file.FileWritingMessageHandler@310cd27 received message: GenericMessage [payload=c:\tmp\csvfiles\input\test1.txt, headers={id=f53fbb89-d2f2-caab-f40b-cbd825238950, timestamp=1475263656640}]
2016-09-30 14:27:36,671 [task-scheduler-1] [channel.DirectChannel] DEBUG - preSend on channel 'archiveFileChannel', message: GenericMessage [payload=c:\tmp\csvfiles\output\test1.txt, headers={file_originalFile=c:\tmp\csvfiles\input\test1.txt, id=ac2a9c1e-243d-5702-ef23-f715ebce18f8, timestamp=1475263656671}]
2016-09-30 14:27:36,671 [task-scheduler-1] [handler.ServiceActivatingHandler] DEBUG - ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProcessor@5f6b71ba] received message: GenericMessage [payload=c:\tmp\csvfiles\output\test1.txt, headers={file_originalFile=c:\tmp\csvfiles\input\test1.txt, id=ac2a9c1e-243d-5702-ef23-f715ebce18f8, timestamp=1475263656671}]
2016-09-30 14:27:36,671 [task-scheduler-1] [handlers.FileHandler] INFO  - Service Activator Activated
2016-09-30 14:27:36,671 [task-scheduler-1] [handlers.FileHandler] INFO  - File name : test1.txt
2016-09-30 14:27:36,702 [task-scheduler-1] [utility.FileUtility] INFO  - Archive file name : test1_2016-09-30_14-27-36-702.txt
2016-09-30 14:27:36,702 [task-scheduler-1] [handlers.FileHandler] INFO  - c:\tmp\csvfiles\output
2016-09-30 14:27:36,702 [task-scheduler-1] [handlers.FileHandler] INFO  - c:\tmp\csvfiles\archive
2016-09-30 14:27:36,718 [task-scheduler-1] [handlers.FileHandler] INFO  - Successfully archived file : test1.txt
2016-09-30 14:27:36,718 [task-scheduler-1] [handlers.FileHandler] INFO  - Source FIle Name with Path : c:\tmp\csvfiles\input\test1.txt
2016-09-30 14:27:36,718 [task-scheduler-1] [handlers.FileHandler] INFO  - Successfully deleted file : test1.txtfrom directory: c:/tmp/csvfiles/input/
2016-09-30 14:27:36,718 [task-scheduler-1] [handler.ServiceActivatingHandler] DEBUG - handler 'ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProcessor@5f6b71ba]' produced no reply for request Message: GenericMessage [payload=c:\tmp\csvfiles\output\test1.txt, headers={file_originalFile=c:\tmp\csvfiles\input\test1.txt, id=ac2a9c1e-243d-5702-ef23-f715ebce18f8, timestamp=1475263656671}]
2016-09-30 14:27:36,718 [task-scheduler-1] [channel.DirectChannel] DEBUG - postSend (sent=true) on channel 'archiveFileChannel', message: GenericMessage [payload=c:\tmp\csvfiles\output\test1.txt, headers={file_originalFile=c:\tmp\csvfiles\input\test1.txt, id=ac2a9c1e-243d-5702-ef23-f715ebce18f8, timestamp=1475263656671}]
2016-09-30 14:27:36,718 [task-scheduler-1] [channel.DirectChannel] DEBUG - postSend (sent=true) on channel 'outboundFileChannel', message: GenericMessage [payload=c:\tmp\csvfiles\input\test1.txt, headers={id=f53fbb89-d2f2-caab-f40b-cbd825238950, timestamp=1475263656640}]
2016-09-30 14:27:36,718 [task-scheduler-1] [channel.DirectChannel] DEBUG - postSend (sent=true) on channel 'inboundFileChannel', message: GenericMessage [payload=c:\tmp\csvfiles\input\test1.txt, headers={id=4f03f37d-7bb4-d630-72c0-360fd07d3b88, timestamp=1475263656593}]
2016-09-30 14:27:36,718 [task-scheduler-1] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:37,250 [task-scheduler-2] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:38,248 [task-scheduler-1] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:39,250 [task-scheduler-3] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:40,249 [task-scheduler-3] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:41,247 [task-scheduler-4] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:42,246 [task-scheduler-1] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:43,244 [task-scheduler-5] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:44,242 [task-scheduler-2] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:45,241 [task-scheduler-6] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:46,239 [task-scheduler-6] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:47,238 [task-scheduler-7] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:48,252 [task-scheduler-7] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:49,239 [task-scheduler-8] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:50,241 [task-scheduler-8] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:51,239 [task-scheduler-8] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:52,209 [task-scheduler-5] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:53,278 [task-scheduler-5] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:54,247 [task-scheduler-2] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:55,245 [task-scheduler-2] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:56,252 [task-scheduler-6] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:57,238 [task-scheduler-6] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:58,253 [task-scheduler-7] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:27:59,238 [task-scheduler-7] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:28:00,252 [task-scheduler-7] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:28:01,249 [task-scheduler-7] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:28:02,249 [task-scheduler-10] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:28:03,247 [task-scheduler-5] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:28:04,249 [task-scheduler-3] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:28:05,248 [task-scheduler-3] [file.FileReadingMessageSource] DEBUG - Added to queue: [c:\tmp\csvfiles\input\test2.txt]
2016-09-30 14:28:05,248 [task-scheduler-3] [file.FileReadingMessageSource] INFO  - Created message: [GenericMessage [payload=c:\tmp\csvfiles\input\test2.txt, headers={id=be245baf-52b4-8196-714b-8003b55d347b, timestamp=1475263685248}]]
2016-09-30 14:28:05,248 [task-scheduler-3] [endpoint.SourcePollingChannelAdapter] DEBUG - Poll resulted in Message: GenericMessage [payload=c:\tmp\csvfiles\input\test2.txt, headers={id=be245baf-52b4-8196-714b-8003b55d347b, timestamp=1475263685248}]
2016-09-30 14:28:05,248 [task-scheduler-3] [channel.DirectChannel] DEBUG - preSend on channel 'inboundFileChannel', message: GenericMessage [payload=c:\tmp\csvfiles\input\test2.txt, headers={id=be245baf-52b4-8196-714b-8003b55d347b, timestamp=1475263685248}]
2016-09-30 14:28:05,248 [task-scheduler-3] [handler.LoggingHandler] DEBUG - org.springframework.integration.handler.LoggingHandler#0 received message: GenericMessage [payload=c:\tmp\csvfiles\input\test2.txt, headers={id=be245baf-52b4-8196-714b-8003b55d347b, timestamp=1475263685248}]
2016-09-30 14:28:05,263 [task-scheduler-3] [handler.LoggingHandler] DEBUG - c:\tmp\csvfiles\input\test2.txt
2016-09-30 14:28:05,279 [task-scheduler-3] [channel.DirectChannel] DEBUG - postSend (sent=true) on channel 'inboundFileChannel', message: GenericMessage [payload=c:\tmp\csvfiles\input\test2.txt, headers={id=be245baf-52b4-8196-714b-8003b55d347b, timestamp=1475263685248}]
2016-09-30 14:28:06,246 [task-scheduler-3] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:28:07,248 [task-scheduler-6] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:28:08,232 [task-scheduler-1] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:28:09,261 [task-scheduler-9] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'
2016-09-30 14:28:10,244 [task-scheduler-9] [endpoint.SourcePollingChannelAdapter] DEBUG - Received no Message during the poll, returning 'false'

Since I deleted the archive directory(while application is running), message is sent to LoggingHandler. 由于我删除了存档目录(在应用程序运行时),因此消息发送到LoggingHandler。 Can anybody suggest how to handle that exception and i can write code to terminate the application. 有人可以建议如何处理该异常,我可以编写代码来终止该应用程序。

Please correct me if I am missing any thing. 如果我缺少任何东西,请指正我。

<int:channel id="inboundFileChannel"/>

<int:service-activator input-channel="inboundFileChannel" output-channel="outboundFileChannel" ref="fileHandler"/>

<int:logging-channel-adapter channel="inboundFileChannel" level="DEBUG"/>

When you have two consumers subscribed to the same channel ( DirectChannel by default) messages will go to the two consumers alternately - round-robin distribution. 当您有两个使用方订阅了相同的频道时(默认情况下为DirectChannel ),消息将交替发送给两个使用方-循环分发。

If you want the file to go to both consumers, change it to a pub/sub channel. 如果要将文件同时发送给两个使用者,请将其更改为发布/订阅频道。

<int:publish-subscribe-channel id="inboundFileChannel"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM