我的要求如下。使用Apache Camel同步FTP遠程和FS(或HDFS)
有時,我想手動運行一個工具,將遠程FTP與我的FS(至少,HDFS)遠程同步。 應該下載每個文件,應該附加更新的文件。
我使用Apache Camel FTP2示例: https://github.com/apache/camel/tree/master/examples/camel-example-ftp 啓動該項目。在其他來源的幫助下,這是一個簡單的解決方案。
object Main{
def main(args: Array[String]): Unit = {
val context = new DefaultCamelContext
context.addRoutes(FtpRoute())
context.start
Thread.sleep(100000)
context.stop
}
}
case class FtpRoute() extends RouteBuilder {
def configure(): Unit = { // configure properties component
val pc = getContext.getComponent("properties", classOf[PropertiesComponent])
pc.setLocation("classpath:ftp.properties")
val ftpSource = getContext.resolvePropertyPlaceholders(
s"ftp://{{ftp.serv}}{{ftp.path}}?username={{ftp.user}}&password={{ftp.pass}}&passiveMode=true")
from(ftpSource)
.to("file:/tmp/ftp")
.log("Downloaded file ${file:name} complete.")
}
}
我可以說它的工作原理,但是......絕對不是我想要的。
- 如何跟蹤文件進度,以及(可能)在所有文件下載時停止
Camel
上下文?我需要單獨處理嗎? - 來自
FTP
的文件被一遍又一遍地下載。馬不停蹄。爲什麼他一直在重新下載文件? - 很多FTP連接正在創建中。
disconnect=true
在這裏沒有幫助。你有什麼經驗嗎?
非常感謝!
所以我需要一個數據庫來告訴駱駝被下載哪些文件?有沒有內存中的解決方案?但不是h2分貝。 – Atais
@Atais MemoryIdempotentRepository是默認解決方案,但是如果您重新啓動駱駝上下文,則會丟失所有以前下載的文件密鑰。默認情況下,它包含最後的1000個鍵。您也可以使用FileIdempotentRepository和其他許多其他解決方案(您可以在這裏找到完整的解決方案列表:http://camel.apache.org/idempotent-consumer.html)。 –
@Atais我擴展了我的答案。 –