繁体   English   中英

具有动态属性的Mule SFTP端点

[英]Mule sftp endpoint with dynamic properties

我试图找出如何在流中使用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

我注意到那里的最后一句话,只有出站端点可以是动态的。 但是,还有人对动态入站端点的解决方法有任何想法吗?

谢谢

入站端点在流中不能是动态的。

  • 使用所有可能的入站端点定义不同的流,并使用选择过滤器重定向到特定流
  • 使用Java通过EndpointBuilder接口代码示例动态创建端点:

// 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); }

@Christian Karlsson,如果要获取带有动态端点的任何资源,可以使用Mule请求程序模块。 您可以在https://github.com/mulesoft/mule-module-requester中找到更多详细信息。

希望这可以帮助。

Mule SFTP连接器不支持动态端点。

但是,您可以使用脚本通过sftp中流读取文件。 就像是:

<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}&amp;passphrase=${sftp.passphrase}&amp;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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM