2015-10-20 60 views
3

我遇到了Mule ESB獨立FTP輪詢的問題: 應用程序運行幾天沒有問題,然後FTP輪詢停止,沒有發出警告或錯誤。Mule FTP輪詢停止沒有錯誤或警告

日誌顯示FTP輪詢的活動跡象,直到它停止。之後什麼都沒有,但其他連接器仍然處於活動狀態(主要是SFTP輪詢)。我在運行時啓用了DEBUG日誌,以查看是否仍有活動,並且相應的連接器線程完全保持沉默狀態,就好像停止或阻止一樣。

最後,重新啓動應用程序暫時解決了這個問題,但我想了解爲什麼發生這種情況以避免再次面對它。我懷疑FTP連接器線程是停止還是被阻止,阻止進一步的民意調查。

它可能是由於我們用來防止poll(覆蓋postProcess()函數)後文件刪除的擴展FtpMessageReceiver引起的。然而,看看這個組件和基本的FTP接收器和連接器的源代碼,我不明白它是如何發生的。

任何想法爲什麼民意調查會突然停止而不會引發錯誤?

這是當前連接器的配置:

<ftp:connector name="nonDeletingFtpConnector" doc:name="FTP" 
     pollingFrequency="${frequency}" 
     validateConnections="true"> 
    <reconnect frequency="${frequency}" count="${count}"/> 
    <service-overrides messageReceiver="my.comp.NonDeletingFtpMessageReceiver" /> 
</ftp:connector> 

以及相應的端點:

<ftp:inbound-endpoint host="${ftp.source.host}" 
      port="${ftp.source.port}" 
      path="${ftp.source.path}" 
      user="${ftp.source.login}" 
      responseTimeout="10000" 
      password="${ftp.source.password}" 
      connector-ref="archivingFtpConnector" 
      pollingFrequency="${ftp.default.polling.frequency}"> 
     <file:filename-wildcard-filter pattern="*.zip"/> 
    </ftp:inbound-endpoint> 

的的messageReceiver代碼:

public class NonDeletingFtpMessageReceiver extends FtpMessageReceiver { 
    public NonDeletingFtpMessageReceiver(Connector connector, FlowConstruct flowConstruct, InboundEndpoint endpoint, long frequency) throws CreateException { 
     super(connector, flowConstruct, endpoint, frequency); 
    } 

    @Override 
    protected void postProcess(FTPClient client, FTPFile file, MuleMessage message) throws Exception { 
     //do nothing 
    } 
} 

正如你可以看到我們定義了一個FtpMessageReceiver到避免在輪詢時刪除文件(這是在流程中進一步完成的),但是正在查看代碼我看不到如何跳過super.postProcess()調用(它負責刪除文件)可能會導致問題。

FtpMessageReceiver源代碼,我看了: https://github.com/mulesoft/mule/blob/mule-3.5.0/transports/ftp/src/main/java/org/mule/transport/ftp/FtpMessageReceiver.java

技術配置:

  • 騾子獨立3.5.0
  • 的Ubuntu 14.04.2 LTS
  • 的Java OpenJDK的運行時環境(2.5的IcedTea。 6)(7u79-2.5.6-0ubuntu1.14.04.1)

任何幫助,將不勝感激。感謝提前!

+0

我們在我們的應用程序中幾次遇到這個問題,在日誌文件中沒有錯誤,並且不知道發生了什麼。最終導致應用程序重新啓動。我更喜歡在線程阻塞或等待FTP連接時檢查FTP服務器中是否存在任何問題。 – RamakrishnaN

+0

幹得好,我檢查了與netstat掛起的FTP連接,並且有幾個連接打開了幾天仍然打開。使用jstack我能夠跟蹤僞代碼並用自定義FtpConnectionFactory編寫解決方法; (我創建了另一個帖子,因爲這與Apache Commons Net FTP Client更相關) –

+1

[link](https://stackoverflow.com/questions/33350649/commons-net-ftpclient-hangs-indefinitely-with-mule)to Pierre B.的另一篇文章。 – Anssssss

回答

0

正如評論中所述,該錯誤更多地與Apache FTP客戶端相關聯,並且我創建了一個特定的帖子here

以下是找到的解決方案:使用自定義FtpConnectionFactory以超時值> 0正確配置客戶端。這種方式掛起被中斷,並引發超時異常。

public class SafeFtpConnectionFactory extends FtpConnectionFactory{ 

     //define a default timeout 
     public static int defaultTimeout = 60000; 
     public static synchronized int getDefaultTimeout() { 
      return defaultTimeout; 
     } 
     public static synchronized void setDefaultTimeout(int defaultTimeout) { 
      SafeFtpConnectionFactory.defaultTimeout = defaultTimeout; 
     } 

     public SafeFtpConnectionFactory(EndpointURI uri) { 
      super(uri); 
     } 

     @Override 
     protected FTPClient createFtpClient() { 
      FTPClient client = super.createFtpClient(); 

      //Define the default timeout here, which will be used by the socket by default, 
      //instead of the 0 timeout hanging indefinitely 
      client.setDefaultTimeout(getDefaultTimeout()); 

      return client; 
     } 
    } 

然後將其連接到連接器:

<ftp:connector name="archivingFtpConnector" doc:name="FTP" 
     pollingFrequency="${frequency}" 
     validateConnections="true" 
     connectionFactoryClass="my.comp.SafeFtpConnectionFactory"> 
    <reconnect frequency="${reconnection.frequency}" count="${reconnection.attempt}"/> 
</ftp:connector> 

我會嘗試更新這個答案,如果有對其他的任何顯着的變化。