Mule SFTP 入站端点不公开时间戳
Mule SFTP inbound endpoint does not expose timestamp
我有一个从 Mule 中的 SFTP 连接器获取文件的流程。应用程序没有权限在处理后删除文件。
为了防止重复处理,应用程序使用基于文件名和时间戳的幂等过滤器。
SFTP 没有在消息中返回每个文件的时间戳。结果,message.inboundProperties.timestamp returns 为空。
<!-- SFTP connector -->
<sftp:connector
name="SFTP_Origin"
validateConnections="true"
pollingFrequency="${sftp.origin.pollingFrequency:60000}"
fileAge="${sftp.origin.fileAge:60000}"
duplicateHandling="overwrite"
doc:name="SFTP"
archiveDir="${local.archive.directory}"/>
<!-- Move XML files from one SFTP location to another location.
Archive each file locally on the mule server in the event the file transfer fails.
Upon failure, notify those responsible so that action can be remedied. -->
<flow name="TransferFilesViaSFTP_Flow" >
<sftp:inbound-endpoint
connector-ref="SFTP_Origin"
host="${sftp.origin.host}"
port="${sftp.origin.port:22}"
path="${sftp.origin.path}"
user="${sftp.origin.user}"
password="${sftp.origin.password}"
responseTimeout="10000"
archiveDir="${local.archive.directory}"
doc:name="InboundSFTPEndpoint">
<!-- Use RegEx filter to filter only files with within the proper date format YYYYMMdd
Range of dates are from 19000101 to 20991231 -->
<file:filename-regex-filter pattern="${regex.filter:filename(.*)xml}" caseSensitive="false"/>
</sftp:inbound-endpoint>
<!-- Get the files via SFTP -->
<logger
message="#[message]"
level="INFO"
category="sftp"
doc:name="Logger"/>
<!-- Eliminate redundant file transfers by filtering out files that have
been transfered previously, unless their timestamp has changed. -->
<idempotent-message-filter
idExpression="#[message.inboundProperties.originalFilename + '-' +
message.inboundProperties.timestamp]"
storePrefix="prefix"
doc:name="Filter out redundant files transfers">
<simple-text-file-store
name="filesMessages"
directory="${idempotent.directory}"/>
</idempotent-message-filter>
<!-- log event information -->
<logger
message="#['Payload after SFTP is ' + payload]"
level="DEBUG"
doc:name="Payload Logger"
category="sftp"/>
<!-- Send the files to Windows Share -->
<file:outbound-endpoint
path="${windows.share.path}"
connector-ref="WindowsShareFile"
responseTimeout="10000"
doc:name="File"/>
<!-- log event information -->
<logger
message="#['file ' + message.inboundProperties.'originalFilename' + ' successfully processed.']"
level="INFO"
category="sftp"
doc:name="Logger: Success"/>
<!-- Based on property, smtp.onSuccess.sendEmail, notify when files have been moved successfully. -->
<expression-filter
expression="#[${smtp.onSuccess.sendEmail:false}]"
doc:name="onSuccess Send Email"/>
<set-session-variable
variableName="emailSubject"
value="#['Mule Flow Successful']"
doc:name="emailSubject"/>
<flow-ref
name="aggregateSuccessfulFilesTransferForEmail_Subflow"
doc:name="aggregateSuccessfulFilesTransferForEmail_Subflow"/>
<!-- default exception strategy -->
<exception-strategy
ref="transferFilesExceptionStrategy"
doc:name="Reference Exception Strategy"/>
</flow>
我在 Mulesoft 上发现了一个似乎未解决的问题。
https://www.mulesoft.org/jira/browse/MULE-7175
是否有其他方法可以从 SFTP 连接器获取文件的时间戳?
如果文件小到可以放入内存:
- 在
sftp:inbound-endpoint
之后将其转化为byte[]
计算负载的 SHA 哈希,而不是尝试使用远程文件的时间戳。它无论如何都会工作并且更可靠:
idExpression="#[message.inboundProperties.originalFilename + '-' +
org.apache.commons.codec.digest.DigestUtils.sha256Hex(message.payload)]"
我有一个从 Mule 中的 SFTP 连接器获取文件的流程。应用程序没有权限在处理后删除文件。
为了防止重复处理,应用程序使用基于文件名和时间戳的幂等过滤器。
SFTP 没有在消息中返回每个文件的时间戳。结果,message.inboundProperties.timestamp returns 为空。
<!-- SFTP connector -->
<sftp:connector
name="SFTP_Origin"
validateConnections="true"
pollingFrequency="${sftp.origin.pollingFrequency:60000}"
fileAge="${sftp.origin.fileAge:60000}"
duplicateHandling="overwrite"
doc:name="SFTP"
archiveDir="${local.archive.directory}"/>
<!-- Move XML files from one SFTP location to another location.
Archive each file locally on the mule server in the event the file transfer fails.
Upon failure, notify those responsible so that action can be remedied. -->
<flow name="TransferFilesViaSFTP_Flow" >
<sftp:inbound-endpoint
connector-ref="SFTP_Origin"
host="${sftp.origin.host}"
port="${sftp.origin.port:22}"
path="${sftp.origin.path}"
user="${sftp.origin.user}"
password="${sftp.origin.password}"
responseTimeout="10000"
archiveDir="${local.archive.directory}"
doc:name="InboundSFTPEndpoint">
<!-- Use RegEx filter to filter only files with within the proper date format YYYYMMdd
Range of dates are from 19000101 to 20991231 -->
<file:filename-regex-filter pattern="${regex.filter:filename(.*)xml}" caseSensitive="false"/>
</sftp:inbound-endpoint>
<!-- Get the files via SFTP -->
<logger
message="#[message]"
level="INFO"
category="sftp"
doc:name="Logger"/>
<!-- Eliminate redundant file transfers by filtering out files that have
been transfered previously, unless their timestamp has changed. -->
<idempotent-message-filter
idExpression="#[message.inboundProperties.originalFilename + '-' +
message.inboundProperties.timestamp]"
storePrefix="prefix"
doc:name="Filter out redundant files transfers">
<simple-text-file-store
name="filesMessages"
directory="${idempotent.directory}"/>
</idempotent-message-filter>
<!-- log event information -->
<logger
message="#['Payload after SFTP is ' + payload]"
level="DEBUG"
doc:name="Payload Logger"
category="sftp"/>
<!-- Send the files to Windows Share -->
<file:outbound-endpoint
path="${windows.share.path}"
connector-ref="WindowsShareFile"
responseTimeout="10000"
doc:name="File"/>
<!-- log event information -->
<logger
message="#['file ' + message.inboundProperties.'originalFilename' + ' successfully processed.']"
level="INFO"
category="sftp"
doc:name="Logger: Success"/>
<!-- Based on property, smtp.onSuccess.sendEmail, notify when files have been moved successfully. -->
<expression-filter
expression="#[${smtp.onSuccess.sendEmail:false}]"
doc:name="onSuccess Send Email"/>
<set-session-variable
variableName="emailSubject"
value="#['Mule Flow Successful']"
doc:name="emailSubject"/>
<flow-ref
name="aggregateSuccessfulFilesTransferForEmail_Subflow"
doc:name="aggregateSuccessfulFilesTransferForEmail_Subflow"/>
<!-- default exception strategy -->
<exception-strategy
ref="transferFilesExceptionStrategy"
doc:name="Reference Exception Strategy"/>
</flow>
我在 Mulesoft 上发现了一个似乎未解决的问题。 https://www.mulesoft.org/jira/browse/MULE-7175
是否有其他方法可以从 SFTP 连接器获取文件的时间戳?
如果文件小到可以放入内存:
- 在
sftp:inbound-endpoint
之后将其转化为 计算负载的 SHA 哈希,而不是尝试使用远程文件的时间戳。它无论如何都会工作并且更可靠:
idExpression="#[message.inboundProperties.originalFilename + '-' + org.apache.commons.codec.digest.DigestUtils.sha256Hex(message.payload)]"
byte[]