[英]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.