Apache camel 在驼峰ssh组件启动远程scp失败时重命名文件
当使用ssh组件启动远程scp命令时,我必须设置主体。ssh组件使用body作为远程执行的命令 我想要实现的是:Apache camel 在驼峰ssh组件启动远程scp失败时重命名文件,apache-camel,apache-karaf,blueprint-osgi,Apache Camel,Apache Karaf,Blueprint Osgi,当使用ssh组件启动远程scp命令时,我必须设置主体。ssh组件使用body作为远程执行的命令 我想要实现的是: 监视文件夹中的文件。“from”使用delete=true,因为我不想在路由完成后保留文件 使用sftp在DMZ服务器上复制文件 使用ssh在DMZ服务器上启动scp 如果失败,scp将返回大于0的代码,并将文件重命名为“.failed” 不幸的是,使用ssh需要覆盖正文,而我失去了文件的内容。我尝试使用inOnly,发送到另一个路由,但它不会复制文件,但可能是文件指针的副本。我不能
<route id="RemoteTest1">
<!-- 1. Monitor for incoming files -->
<from uri="file:///data/karaf/tmp/RemoteTest1/?delete=true"/>
<!-- 2. Copy file on DMZ server -->
<to uri="sftp:username@myDmz.com//home/RemoteTest1/?privateKeyFile=myPrivateKey.pk"/>
<!-- 3. Execute scp remotely -->
<setHeader headerName="remoteCommand">
<simple>scp /home/RemoteTest1/${file:name} someuser@acme.com:${file:name}</simple>
</setHeader>
<doTry>
<inOnly uri="direct-vm:remoteExec"/>
<log message="Success"/>
<doCatch>
<exception>java.lang.Exception</exception>
<!-- 4. In case of failure rename the file by adding .failed -->
<to uri="file:?fileName=${file:absolute.path}.failed"/>
<log message="Failed"/>
</doCatch>
</doTry>
</route>
<route id="remoteExec">
<from uri="direct-vm:remoteExec"/>
<setBody>
<simple>${header.remoteCommand}</simple>
</setBody>
<to uri="ssh://username@myDmz.com?certResource=file:resources/keys/myPrivateKey.pk"/>
<!-- Throw exception on remote error -->
<choice>
<when>
<simple>${header.CamelSshExitValue} != '0'</simple>
<throwException ref="remoteExecException"/>
</when>
<otherwise>
<log message="scp completed normally"/>
</otherwise>
</choice>
</route>
<bean id="remoteExecException" class="java.lang.Exception">
<argument value="Failed remote execution" />
</bean>
scp/home/RemoteTest1/${file:name}someuser@acme.com:${file:name}
java.lang.Exception
${header.remoteCommand}
${header.camelsHexitValue}!='0'
有解决办法吗?任何帮助或提示都将不胜感激
谢谢您是否尝试过使用
移动
和移动失败
选项而不是删除
?您可以设置另一个路由来监视move
的目标目录并从中删除文件。我没有。我试试看。谢谢