Apache camel 在驼峰ssh组件启动远程scp失败时重命名文件

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,发送到另一个路由,但它不会复制文件,但可能是文件指针的副本。我不能

当使用ssh组件启动远程scp命令时,我必须设置主体。ssh组件使用body作为远程执行的命令

我想要实现的是:

  • 监视文件夹中的文件。“from”使用delete=true,因为我不想在路由完成后保留文件
  • 使用sftp在DMZ服务器上复制文件
  • 使用ssh在DMZ服务器上启动scp
  • 如果失败,scp将返回大于0的代码,并将文件重命名为“.failed”
  • 不幸的是,使用ssh需要覆盖正文,而我失去了文件的内容。我尝试使用inOnly,发送到另一个路由,但它不会复制文件,但可能是文件指针的副本。我不能使用wireTap,因为当它完成远程执行时,路由已完成,文件已删除。我不能使用(我认为)临时变量,因为该文件的大小可能高达GB

    我使用的是在Karaf 2.3.2下运行的Camel版本2.12.1。我尝试使用BlueprintXML只是为了尽可能避免java编码。下面是一个样本。如果ssh组件的退出代码为非零,则结果是包含我的远程命令的文件

    <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
    的目标目录并从中删除文件。我没有。我试试看。谢谢