[英]File reading in Mule CE Cluster environment
我们目前正在研究在 Mule CE 运行时上运行的应用程序。 在本地机器上从共享挂载文件夹读取文件很好。 但是在生产集群环境中,我们有 2 个节点,每个节点轮询相同的位置。 有可能两个节点同时选择同一个文件。
我知道 Mule EE 运行时可以出色地处理这种情况,但我们现在还不能从 CE 升级到 EE。 这就是为什么我需要一些帮助。
我尝试使用 Quartz,但根据我们的分析,在 CE 运行时 Quartz 调度程序会导致同样的问题。 调度器可以建议两个节点同时选择同一个文件。
然后我尝试实现自定义文件消息接收器,请查看以下设置:
听众:
<file:inbound-endpoint path="${file_to_mq_wholefile.path}"
moveToPattern="#[message.inboundProperties['originalFilename']+'_'+message.rootId+'_'+org.mule.util.DateUtils.getTimeStamp('yyyy_MM_dd-HH_mm_ss.SSSSSS')].backup"
moveToDirectory="${file_to_mq_wholefile.move.to.directory}"
responseTimeout="10000" doc:name="File"
connector-ref="FileInboundGeneralConnector"
transformer-refs="RemoveArchiveInboundFileTransformer">
</file:inbound-endpoint>
骡子配置:
<file:connector name="FileInboundGeneralConnector" autoDelete="true" streaming="false" validateConnections="false" doc:name="File">
<service-overrides messageReceiver="com.company.adaptors.components.CustomFileMessageReceiver"/>
</file:connector>
代码:
public class CustomFileMessageReceiver extends FileMessageReceiver {
public CustomFileMessageReceiver(Connector connector, FlowConstruct flowConstruct, InboundEndpoint endpoint, String readDir, String moveDir, String moveToPattern, long frequency) throws CreateException {
super(connector, flowConstruct, endpoint, readDir, moveDir, moveToPattern, frequency);
}
protected boolean attemptFileLock(File sourceFile) throws MuleException {
System.out.println("************");
return true;
}
}
我已经查看了其他 stackoverflow 链接(例如: 在集群环境中使用 Quartz 和 Mule )但是,没有达到最终解决方案......
我能想到的有两个选项:
在 mule4 连接器中,我们可以选择使用锁。 它确保没有其他进程可以读取一个进程开始处理它的文件。 更多信息可以在这里找到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.