2015-07-20 59 views
1

我決定嘗試Mulesoft ESB和Anypoint。它工作很好,直到我添加一些腳本。 在我的測試文件基於他們的擴展名重定向到文件夾。 然後在一個目錄中,一些文件通過python腳本接受了修改。 而這就是它不再工作的地方。 如果我修改文件,它似乎關閉流程。 那我該如何避免呢?Mulesoft/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    : [email protected] 
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

file:outbound-endpointone-way這意味着,在默認情況下,騾子將運行在調度動作一個不同的線程。因此:

os.rename(originalFilename, new_name) 

發生當file:outbound-endpoint仍在複製數據從數據流上originalFilename打開。

使流同步的:

<flow name="Dispatcher" processingStrategy="synchronous"> 

迫使騾子做同一個線程的一切。