[英]Accessing Mule flowVars/Variable from a Java method
I have created a Mule flow which determines whether or not to download a group of files via SFTP, provided they are all present. 我创建了一个Mule流,该流决定了是否通过SFTP下载一组文件,前提是它们都存在。
I determine this using a Java method which reads the contents of a folder and then returns either true
or false
. 我使用Java方法确定此内容,该方法读取文件夹的内容,然后返回true
或false
。
The structure of the Mule flow looks like this: Mule流的结构如下所示:
<spring:beans>
<spring:bean class="com.test.FileCheck" name="invokeFileChecks">
</spring:bean>
</spring:beans>
<flow name="check-files" processingStrategy="synchronous">
<set-variable variableName="allFilesPresent" value="False" doc:name="Variable - all files present boolean"/>
<invoke object-ref="invokeFileChecks"
method="checkFiles"
doc:name="Invoke folder scan"
methodArguments="#[flowVars.sftpHost], #[flowVars.sftpPort], #[flowVars.sftpUserName], #[flowVars.sftpPassword], #[flowVars.sftpRequestedFiles]"/>
<echo-component doc:name="Echo"/>
The Java method looks like this: Java方法如下所示:
public boolean checkFiles(String hostname, int port, String username, String password, String fileList){
boolean filesPresentTrueOrFalse;
//logic to list folder contents of SFTP:
//If all files are present, return true, otherwise false.
return filesPresentTrueOrFalse;
}
How can I assign allFilesPresent
the value of filesPresentTrueOrFalse
? 如何为filesPresentTrueOrFalse
分配allFilesPresent
的值?
Mule variables can be accessed via setProperty
/ getProperty
methods from the MuleMessage class. 可以通过MuleMessage类中的setProperty
/ getProperty
方法访问Mule变量。
An instance of MuleMessage
can be obtained from MuleEventContext
via getMessage
method. 的一个实例MuleMessage
可获自MuleEventContext
经由getMessage
方法。 The event context itself gets injected by implementing method onCall
of Callable interface. 通过实现Callable接口的onCall
方法可以注入事件上下文本身。
So, start with implementing the Callable
interface in you bean. 因此,从在bean中实现Callable
接口开始。
Wrap the invoke in an enricher. 将调用包装在扩充器中。 This way the result will go to the target var and not overwrite the payload. 这样,结果将到达目标var而不覆盖有效负载。 It will also keep your java decoupled from mule internals: 它还可以使您的java与m子内部分离:
<enricher target="#[flowVars.allFilesPresent]">
<invoke object-ref="invokeFileChecks"
method="checkFiles"
doc:name="Invoke folder scan"
methodArguments="#[flowVars.sftpHost], #[flowVars.sftpPort], #[flowVars.sftpUserName], #[flowVars.sftpPassword], #[flowVars.sftpRequestedFiles]"/>
</enricher>
Enricher Can only have one processor so anytime thing else needed in there wrap in a processor-chain or a flow and use flow-ref. Enricher只能有一个处理器,因此随时可以将处理器链或流中的其他内容包装起来并使用流引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.