簡體   English   中英

Mule CE集群環境下的文件讀取

[英]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;
}

}

  1. 我不知道如何從這里開始。
  2. 請任何人都可以為此解決方案提出任何其他替代方案

我已經查看了其他 stackoverflow 鏈接(例如: 在集群環境中使用 Quartz 和 Mule )但是,沒有達到最終解決方案......

我能想到的有兩個選項:

  1. 您可以檢查此解決方案,看看它是否適用於您的用例: https : //github.com/arbuzworks/fulcrum-cluster-mule
  2. 通過對所有節點使用 Redis 等通用存儲來實現自定義文件鎖定解決方案。

在 mule4 連接器中,我們可以選擇使用鎖。 它確保沒有其他進程可以讀取一個進程開始處理它的文件。 更多信息可以在這里找到。

https://docs.mulesoft.com/file-connector/1.3/file-read

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM