我决定尝试使用Mulesoft ESB和Anypoint。它很有用,直到我添加一些脚本。 在我的测试中,文件根据他们的扩展名重定向到文件夹。 然后在一个目录中,一些文件通过python脚本接收修改。 那就是它不再起作用的地方了。 如果我修改文件,它似乎关闭了流程。 那么我该如何避免呢?
感谢。
以下是错误消息:
ERROR 2015-07-20 09:20:32,114 [[filetransfer].FileR.dispatcher.15] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=file:///home/glass/AnypointStudio/workspace/filetransfer/Data/temp, connector=FileConnector
{
name=FileR
lifecycle=start
this=70a37e7f
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true
connected=true
supportedProtocols=[file]
serviceOverrides=<none>
}
, name='endpoint.file.home.glass.AnypointStudio.workspace.filetransfer.Data.temp', mep=ONE_WAY, properties={}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: ReceiverFileInputStream
Type : org.mule.api.transport.DispatchException
Code : MULE_ERROR--2
Payload : org.mule.transport.file.ReceiverFileInputStream@18806dc1
JavaDoc : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html
********************************************************************************
Exception stack is:
1. Stream Closed (java.io.IOException)
java.io.FileInputStream:-2 (null)
2. Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=file:///home/glass/AnypointStudio/workspace/filetransfer/Data/temp, connector=FileConnector
{
name=FileR
lifecycle=start
this=70a37e7f
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true
connected=true
supportedProtocols=[file]
serviceOverrides=<none>
}
, name='endpoint.file.home.glass.AnypointStudio.workspace.filetransfer.Data.temp', mep=ONE_WAY, properties={}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: ReceiverFileInputStream (org.mule.api.transport.DispatchException)
org.mule.transport.AbstractMessageDispatcher:117 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)
********************************************************************************
Root Exception stack trace:
java.io.IOException: Stream Closed
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:243)
at org.mule.util.IOUtils.copyLarge(IOUtils.java:239)
at org.mule.transport.file.FileMessageDispatcher.doDispatch(FileMessageDispatcher.java:80)
at org.mule.transport.AbstractMessageDispatcher.process(AbstractMessageDispatcher.java:107)
at org.mule.transport.AbstractConnector$DispatcherMessageProcessor.process(AbstractConnector.java:2662)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:107)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:94)
at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:56)
at org.mule.interceptor.AbstractEnvelopeInterceptor.processBlocking(AbstractEnvelopeInterceptor.java:58)
at org.mule.processor.AbstractRequestResponseMessageProcessor.process(AbstractRequestResponseMessageProcessor.java:47)
at org.mule.processor.AsyncInterceptingMessageProcessor.processNextTimed(AsyncInterceptingMessageProcessor.java:123)
at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker$1.process(AsyncInterceptingMessageProcessor.java:208)
at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker$1.process(AsyncInterceptingMessageProcessor.java:201)
at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:16)
at org.mule.execution.CommitTransactionInterceptor.execute(CommitTransactionInterceptor.java:35)
at org.mule.execution.CommitTransactionInterceptor.execute(CommitTransactionInterceptor.java:22)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:30)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:14)
at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:67)
at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:44)
at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:50)
at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:40)
at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:41)
at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:48)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:28)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:13)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:110)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:30)
at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker.doRun(AsyncInterceptingMessageProcessor.java:200)
at org.mule.work.AbstractMuleEventWork.run(AbstractMuleEventWork.java:49)
at org.mule.work.WorkerContext.run(WorkerContext.java:286)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
********************************************************************************
这是带有python脚本的XML
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.7.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">
<file:connector name="FileR" readFromDirectory="/home/glass/AnypointStudio/workspace/filetransfer/Data/MInbox" autoDelete="true" streaming="true" recursive="true" validateConnections="true" doc:name="File"/>
<flow name="Dispatcher">
<file:inbound-endpoint path="/home/glass/AnypointStudio/workspace/filetransfer/Data/Inbox" responseTimeout="10000" doc:name="Input" connector-ref="FileR"/>
<logger message="name : #[originalFilename]" level="INFO" doc:name="Logger"/>
<choice doc:name="Choice">
<when expression="#[regex('^.*(iso|ISO)' , originalFilename)]">
<file:outbound-endpoint path="/home/glass/AnypointStudio/workspace/filetransfer/Data/BIGFILE" responseTimeout="10000" doc:name="FileISO"/>
</when>
<when expression="#[regex('^.*xml' , originalFilename)]">
<file:outbound-endpoint path="/home/glass/AnypointStudio/workspace/filetransfer/Data/temp" responseTimeout="10000" doc:name="File"/>
<scripting:transformer doc:name="Python">
<scripting:script engine="jython"><![CDATA[import os
print("__________________________________________________________________")
new_name = "test-" + originalFilename
os.rename(originalFilename, new_name)
print(new_name)]]></scripting:script>
</scripting:transformer>
</when>
<otherwise>
<file:outbound-endpoint path="/home/glass/AnypointStudio/workspace/filetransfer/Data/DEFAULT" responseTimeout="10000" doc:name="FileDefault"/>
</otherwise>
</choice>
</flow>
</mule>
答案 0 :(得分:0)
file:outbound-endpoint
是one-way
,这意味着默认情况下,Mule将在另一个线程中运行调度操作。因此:
os.rename(originalFilename, new_name)
当file:outbound-endpoint
仍在originalFilename
上打开的流中复制数据时,会发生。
使流程同步:
<flow name="Dispatcher" processingStrategy="synchronous">
强制Mule用同一个线程做所有事情。