我试图弄清楚如何在流中使用sftp端点,其中属性是动态的,具体取决于某些传入变量。 所以流程基本上是这样的:
<flow name="dynamicSftpEndpoint">
<sftp:inbound-endpoint name="inbound" connector-ref="SFTP"
host="#[sftpHost]" port="#[sftpPort]"
user="#[sftpUser]" password="#[sftpPassword]"
archiveDir="#[sftpInboundArchive]"
responseTimeout="${sftp.responseTimeout}"
path="#[sftpInboundPath]">
<file:filename-regex-filter pattern="#[sftpInboundPattern]" caseSensitive="false"/>
</sftp:inbound-endpoint>
<set-variable variableName="filename" value="#[message.inboundProperties.originalFilename]"/>
<log:info message="File '#[filename]' received from endpoint #[market]"/>
</flow>
但是我得到了像
这样的例外Caused by: org.mule.api.endpoint.MalformedEndpointException: The endpoint "sftp://#[sftpUser]:#[sftpPassword]@#[sftpHost]:#[sftpPort]/#[sftpInboundPath]" is malformed and cannot be parsed. If this is the name of a global endpoint, check the name is correct, that the endpoint exists, and that you are using the correct configuration (eg the "ref" attribute). Note that names on inbound and outbound endpoints cannot be used to send or receive messages; use a named global endpoint instead.. Only Outbound endpoints can be dynamic
我注意到那里的最后一句话,只有出站端点可以是动态的。但有没有人对动态入站端点的解决方法有所了解?
由于
答案 0 :(得分:0)
入站端点在流程中不能是动态的,或者是;
// sftp server connector config
String uri = "sftp://" + userDetails + "@" + serverDetails + "/tmp/sftpFolder";
EndpointBuilder endpointBuilder = eventContext.getMuleContext().getEndpointFactory().getEndpointBuilder(uri);
InboundEndpoint inboundEndpoint = endpointBuilder.buildInboundEndpoint();
SftpConnector connector = (SftpConnector) inboundEndpoint.getConnector();
connector.connect();
// sftp client connection config
SftpClient client = new SftpClient(host);
client.setPort(port);
client.login(user, password);
//client.mkdir("dirFromSftp");
client.changeWorkingDirectory("dirFromSftp");
String[] listFiles = client.listFiles();
for(String file: listFiles) {
System.out.println("File : " + file);
}
答案 1 :(得分:0)
@Christian Karlsson,如果您想获得带有动态端点的任何资源,您可以使用Mule请求者模块。您可以在https://github.com/mulesoft/mule-module-requester找到更多详细信息。
希望这有帮助。
答案 2 :(得分:0)
Mule SFTP连接器不支持动态端点。
但是,您可以使用脚本通过sftp mid flow读取文件。类似的东西:
<scripting:transformer>
<scripting:script engine="Groovy">
<scripting:text>
def endpointBuilder = muleContext.endpointFactory.getEndpointBuilder(
"sftp://${sftp.username}@${sftp.host}:${sftp.port}/${sftp.path}?identityFile=${app.home}/${sftp.keyPath}&passphrase=${sftp.passphrase}&connector=sftp-csv")
endpointBuilder.addMessageProcessor(new org.mule.routing.MessageFilter(new org.mule.transport.file.filters.FilenameWildcardFilter(sessionVars.expectedFilename)))
def inboundEndpoint = endpointBuilder.buildInboundEndpoint()
inboundEndpoint.request(30000L)
</scripting:text>
</scripting:script>
</scripting:transformer>