WSO2ESB 文件适配器 - transport.vfs
WSO2ESB file adapter - transport.vfs
我使用 WSO2ESB 4.8.1。目前我尝试创建相当简单的服务,它将从一个文件夹中读取文件并将它们写入另一个文件夹。所有文件夹都在同一个物理分区上。
我按照 VFS+Transport 的说明进行操作
在 Sample File Processing
这是我简单的文件处理代理配置:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="FileProcessorProxy" transports="vfs" startOnLoad="true" trace="disable">
<target>
<inSequence>
<log level="full"/>
<property xmlns:ns2="http://org.apache.synapse/xsd" name="transport.vfs.ReplyFileName" expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.txt')" scope="transport" type="STRING"/>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<send>
<endpoint>
<address uri="vfs:file:///opt/wso2/wso2data/esboverviewtest/out"/>
</endpoint>
</send>
</inSequence>
</target>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.PollInterval">5</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///opt/wso2/wso2data/esboverviewtest/original</parameter>
<parameter name="transport.vfs.FileURI">file:///opt/wso2/wso2data/esboverviewtest/in</parameter>
<parameter name="transport.vfs.MoveAfterFailure">file:///opt/wso2/wso2data/esboverviewtest/failure</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.txt</parameter>
<parameter name="transport.vfs.ContentType">text/plain</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
<parameter name="transport.vfs.MoveTimestampFormat">yyyy-MM-dd'T'HH:mm:ss.SSSZ_</parameter>
<parameter name="transport.vfs.FailedRecordsFileDestination">file:///opt/wso2/wso2data/esboverviewtest</parameter>
<parameter name="transport.vfs.FailedRecordsFileName">transferFails.log</parameter>
<parameter name="transport.vfs.MoveFailedRecordTimestampFormat">yyyy-MM-dd'T'HH:mm:ss.SSSZ_</parameter>
</proxy>
总而言之,它有效。当我将文件放入 "in" 目录时,它被移动到 "out" 和 "original" 目录。
当我开始测试如果 "out" 或 "original" 目录不可用时会发生什么时我开始的问题...即移动新传入文件时出错。
尽管 wso2 网站上有文档,但似乎参数如下:
transport.vfs.MoveAfterFailure
transport.vfs.ActionAfterFailure
transport.vfs.FailedRecordsFileDestination
transport.vfs.FailedRecordsFileName
transport.vfs.MoveFailedRecordTimestampFormat
完全被忽略...如果在文件传输到 "out" 目录期间出现任何故障,该文件永远不会放入 "failure" 文件夹中。
这是日志:
TID: [0] [ESB] [2015-09-03 21:43:41,120] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:86C197EE849A6CA9071441298621105, Direction: request, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><text xmlns="http://ws.apache.org/commons/ns/payload">test message 1
</text></soapenv:Body></soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [ESB] [2015-09-03 21:43:41,128] INFO {org.apache.synapse.core.axis2.TimeoutHandler} - This engine will expire all callbacks after : 120 seconds, irrespective of the timeout action, after the specified or optional timeout {org.apache.synapse.core.axis2.TimeoutHandler}
TID: [0] [ESB] [2015-09-03 21:43:41,134] ERROR {org.apache.synapse.transport.vfs.VFSUtils} - Cannot get the lock for the file : file:///XXXopt/wso2/wso2data/esboverviewtest/out before processing {org.apache.synapse.transport.vfs.VFSUtils}
TID: [0] [ESB] [2015-09-03 21:43:41,135] WARN {org.apache.synapse.transport.vfs.VFSTransportSender} - Couldn't get the lock for the file : file:///XXXopt/wso2/wso2data/esboverviewtest/out, retry : 1 scheduled after : 30000 {org.apache.synapse.transport.vfs.VFSTransportSender}
TID: [0] [ESB] [2015-09-03 21:44:11,136] ERROR {org.apache.synapse.transport.vfs.VFSUtils} - Cannot get the lock for the file : file:///XXXopt/wso2/wso2data/esboverviewtest/out before processing {org.apache.synapse.transport.vfs.VFSUtils}
TID: [0] [ESB] [2015-09-03 21:44:11,136] WARN {org.apache.synapse.transport.vfs.VFSTransportSender} - Couldn't get the lock for the file : file:///XXXopt/wso2/wso2data/esboverviewtest/out, retry : 2 scheduled after : 30000 {org.apache.synapse.transport.vfs.VFSTransportSender}
TID: [0] [ESB] [2015-09-03 21:44:41,137] ERROR {org.apache.synapse.transport.vfs.VFSUtils} - Cannot get the lock for the file : file:///XXXopt/wso2/wso2data/esboverviewtest/out before processing {org.apache.synapse.transport.vfs.VFSUtils}
TID: [0] [ESB] [2015-09-03 21:44:41,137] WARN {org.apache.synapse.transport.vfs.VFSTransportSender} - Couldn't get the lock for the file : file:///XXXopt/wso2/wso2data/esboverviewtest/out, retry : 3 scheduled after : 30000 {org.apache.synapse.transport.vfs.VFSTransportSender}
TID: [0] [ESB] [2015-09-03 21:45:11,138] ERROR {org.apache.synapse.transport.vfs.VFSUtils} - Cannot get the lock for the file : file:///XXXopt/wso2/wso2data/esboverviewtest/out before processing {org.apache.synapse.transport.vfs.VFSUtils}
TID: [0] [ESB] [2015-09-03 21:45:11,139] ERROR {org.apache.synapse.transport.vfs.VFSTransportSender} - Couldn't send the message to file : file:///XXXopt/wso2/wso2data/esboverviewtest/out, unable to acquire the lock even after 4 retries {org.apache.synapse.transport.vfs.VFSTransportSender}
TID: [0] [ESB] [2015-09-03 21:45:11,140] INFO {org.apache.axis2.engine.AxisEngine} - [MessageContext: logID=9ffc75049fa389747d1fe3eac64c356ce001a7d103ba20fd] Couldn't send the message to file : file:///XXXopt/wso2/wso2data/esboverviewtest/out, unable to acquire the lock even after 4 retries {org.apache.axis2.engine.AxisEngine}
文件移至 "original"(没关系),但在尝试 4 次后文件被简单地丢弃,文件夹 "failure" 留空...
更多,属性 transport.vfs.FailedRecordsFileDestination 和 transport.vfs.FailedRecordsFileName 也被忽略,没有生成任何文件,其中应该包含问题传输列表...
问题是如何通过 WSO2ESB 配置可靠的文件传输,以便可以跟踪哪些文件已成功传输,哪些文件应该重新处理。
如果失败,您的输入文件将移至 transport.vfs.MoveAfterFailure。
但在这里,"failure" 代表 ESB 无法读取文件或构建文件内容的情况。
例如,您将 transport.vfs.ContentType 配置为 application/xml 并且您的文件内容是纯文本:它将被移动到 transport.vfs.MoveAfterFailure.
一旦您的输入文件的内容被发送到您的 inSequence,无论您的调解是什么问题,该文件都将被移动到 transport.vfs.MoveAfterProcess
transport.vfs.FailedRecordsFileName是维护失败文件列表的文件名。默认为 repository/conf/vfs-move-failed-records.properties
还有第二次机会 transport.vfs.MoveAfterFailedMove : 移动失败文件的新目标。
如果您想在调解内部(例如在 faultSequence 中)选择输入文件必须移动到的其他目录,则必须扩展 org.apache.synapse.transport.vfs.VFSTransportListener,将您的 .jar 放入 repository/components/lib 并将您的特定 class 配置为 axis2.xml
我使用 WSO2ESB 4.8.1。目前我尝试创建相当简单的服务,它将从一个文件夹中读取文件并将它们写入另一个文件夹。所有文件夹都在同一个物理分区上。
我按照 VFS+Transport 的说明进行操作 在 Sample File Processing
这是我简单的文件处理代理配置:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="FileProcessorProxy" transports="vfs" startOnLoad="true" trace="disable">
<target>
<inSequence>
<log level="full"/>
<property xmlns:ns2="http://org.apache.synapse/xsd" name="transport.vfs.ReplyFileName" expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.txt')" scope="transport" type="STRING"/>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<send>
<endpoint>
<address uri="vfs:file:///opt/wso2/wso2data/esboverviewtest/out"/>
</endpoint>
</send>
</inSequence>
</target>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.PollInterval">5</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///opt/wso2/wso2data/esboverviewtest/original</parameter>
<parameter name="transport.vfs.FileURI">file:///opt/wso2/wso2data/esboverviewtest/in</parameter>
<parameter name="transport.vfs.MoveAfterFailure">file:///opt/wso2/wso2data/esboverviewtest/failure</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.txt</parameter>
<parameter name="transport.vfs.ContentType">text/plain</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
<parameter name="transport.vfs.MoveTimestampFormat">yyyy-MM-dd'T'HH:mm:ss.SSSZ_</parameter>
<parameter name="transport.vfs.FailedRecordsFileDestination">file:///opt/wso2/wso2data/esboverviewtest</parameter>
<parameter name="transport.vfs.FailedRecordsFileName">transferFails.log</parameter>
<parameter name="transport.vfs.MoveFailedRecordTimestampFormat">yyyy-MM-dd'T'HH:mm:ss.SSSZ_</parameter>
</proxy>
总而言之,它有效。当我将文件放入 "in" 目录时,它被移动到 "out" 和 "original" 目录。
当我开始测试如果 "out" 或 "original" 目录不可用时会发生什么时我开始的问题...即移动新传入文件时出错。
尽管 wso2 网站上有文档,但似乎参数如下:
transport.vfs.MoveAfterFailure
transport.vfs.ActionAfterFailure
transport.vfs.FailedRecordsFileDestination
transport.vfs.FailedRecordsFileName
transport.vfs.MoveFailedRecordTimestampFormat
完全被忽略...如果在文件传输到 "out" 目录期间出现任何故障,该文件永远不会放入 "failure" 文件夹中。
这是日志:
TID: [0] [ESB] [2015-09-03 21:43:41,120] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:86C197EE849A6CA9071441298621105, Direction: request, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><text xmlns="http://ws.apache.org/commons/ns/payload">test message 1
</text></soapenv:Body></soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator}
TID: [0] [ESB] [2015-09-03 21:43:41,128] INFO {org.apache.synapse.core.axis2.TimeoutHandler} - This engine will expire all callbacks after : 120 seconds, irrespective of the timeout action, after the specified or optional timeout {org.apache.synapse.core.axis2.TimeoutHandler}
TID: [0] [ESB] [2015-09-03 21:43:41,134] ERROR {org.apache.synapse.transport.vfs.VFSUtils} - Cannot get the lock for the file : file:///XXXopt/wso2/wso2data/esboverviewtest/out before processing {org.apache.synapse.transport.vfs.VFSUtils}
TID: [0] [ESB] [2015-09-03 21:43:41,135] WARN {org.apache.synapse.transport.vfs.VFSTransportSender} - Couldn't get the lock for the file : file:///XXXopt/wso2/wso2data/esboverviewtest/out, retry : 1 scheduled after : 30000 {org.apache.synapse.transport.vfs.VFSTransportSender}
TID: [0] [ESB] [2015-09-03 21:44:11,136] ERROR {org.apache.synapse.transport.vfs.VFSUtils} - Cannot get the lock for the file : file:///XXXopt/wso2/wso2data/esboverviewtest/out before processing {org.apache.synapse.transport.vfs.VFSUtils}
TID: [0] [ESB] [2015-09-03 21:44:11,136] WARN {org.apache.synapse.transport.vfs.VFSTransportSender} - Couldn't get the lock for the file : file:///XXXopt/wso2/wso2data/esboverviewtest/out, retry : 2 scheduled after : 30000 {org.apache.synapse.transport.vfs.VFSTransportSender}
TID: [0] [ESB] [2015-09-03 21:44:41,137] ERROR {org.apache.synapse.transport.vfs.VFSUtils} - Cannot get the lock for the file : file:///XXXopt/wso2/wso2data/esboverviewtest/out before processing {org.apache.synapse.transport.vfs.VFSUtils}
TID: [0] [ESB] [2015-09-03 21:44:41,137] WARN {org.apache.synapse.transport.vfs.VFSTransportSender} - Couldn't get the lock for the file : file:///XXXopt/wso2/wso2data/esboverviewtest/out, retry : 3 scheduled after : 30000 {org.apache.synapse.transport.vfs.VFSTransportSender}
TID: [0] [ESB] [2015-09-03 21:45:11,138] ERROR {org.apache.synapse.transport.vfs.VFSUtils} - Cannot get the lock for the file : file:///XXXopt/wso2/wso2data/esboverviewtest/out before processing {org.apache.synapse.transport.vfs.VFSUtils}
TID: [0] [ESB] [2015-09-03 21:45:11,139] ERROR {org.apache.synapse.transport.vfs.VFSTransportSender} - Couldn't send the message to file : file:///XXXopt/wso2/wso2data/esboverviewtest/out, unable to acquire the lock even after 4 retries {org.apache.synapse.transport.vfs.VFSTransportSender}
TID: [0] [ESB] [2015-09-03 21:45:11,140] INFO {org.apache.axis2.engine.AxisEngine} - [MessageContext: logID=9ffc75049fa389747d1fe3eac64c356ce001a7d103ba20fd] Couldn't send the message to file : file:///XXXopt/wso2/wso2data/esboverviewtest/out, unable to acquire the lock even after 4 retries {org.apache.axis2.engine.AxisEngine}
文件移至 "original"(没关系),但在尝试 4 次后文件被简单地丢弃,文件夹 "failure" 留空...
更多,属性 transport.vfs.FailedRecordsFileDestination 和 transport.vfs.FailedRecordsFileName 也被忽略,没有生成任何文件,其中应该包含问题传输列表...
问题是如何通过 WSO2ESB 配置可靠的文件传输,以便可以跟踪哪些文件已成功传输,哪些文件应该重新处理。
如果失败,您的输入文件将移至 transport.vfs.MoveAfterFailure。 但在这里,"failure" 代表 ESB 无法读取文件或构建文件内容的情况。
例如,您将 transport.vfs.ContentType 配置为 application/xml 并且您的文件内容是纯文本:它将被移动到 transport.vfs.MoveAfterFailure.
一旦您的输入文件的内容被发送到您的 inSequence,无论您的调解是什么问题,该文件都将被移动到 transport.vfs.MoveAfterProcess
transport.vfs.FailedRecordsFileName是维护失败文件列表的文件名。默认为 repository/conf/vfs-move-failed-records.properties
还有第二次机会 transport.vfs.MoveAfterFailedMove : 移动失败文件的新目标。
如果您想在调解内部(例如在 faultSequence 中)选择输入文件必须移动到的其他目录,则必须扩展 org.apache.synapse.transport.vfs.VFSTransportListener,将您的 .jar 放入 repository/components/lib 并将您的特定 class 配置为 axis2.xml