骆驼组播问题

时间:2013-08-20 04:15:25

标签: apache-camel

我们使用以下配置将文件从单一来源发送到多个远程目的地。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
        xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

        <routeContext id="gcgRatesOutbound" xmlns="http://camel.apache.org/schema/spring">
                <route id="gcgRatesFileOut">       
                        <from uri="file:{{nas.root}}/{{gcg.out.prices.dir}}?delay={{poll.delay}}&amp;initialDelay={{initial.delay}}&amp;readLock=rename&amp;scheduledExecutorService=#scheduledExecutorService" />                                       
                        <multicast stopOnException="true">

                                <to uri="scp://{{gcg.ste.Client1_User_Name}}@{{gcg.ste.Host_Name}}:{{gcg.ste.Port_Number}}/{{gcg.ste.Destination_Client1}}?knownHostsFile={{ssh.knownHosts}}&amp;privateKeyFile={{ssh.privateKey}}" />

                                <to uri="scp://{{gcg.ste.Client2_User_Name}}@{{gcg.ste.Host_Name}}:{{gcg.ste.Port_Number}}/{{gcg.ste.Destination_Client2}}?knownHostsFile={{ssh.knownHosts}}&amp;privateKeyFile={{ssh.privateKey}}" />                               

                                <to uri="scp://{{gcg.ste.Client3_User_Name}}@{{gcg.ste.Host_Name}}:{{gcg.ste.Port_Number}}/{{gcg.ste.Destination_Client3}}?knownHostsFile={{ssh.knownHosts}}&amp;privateKeyFile={{ssh.privateKey}}" />                                               
                        </multicast> 
                </route>
        </routeContext>
</beans>

使用上述确认,文件到达远程目的地,确认与所有远程目的地的连接成功。

我们需要在文件成功转移到所有远程目标后将文件移动到存档文件夹。 并且应该移动到错误文件夹中,包含任何错误。

但是,当我将归档代码(元素)作为子元素添加到上述配置中的多播元素时,使用和标记将文件移动到错误文件夹中。该文件未到达远程目的地。

<doTry>       
        <multicast stopOnException="true" parallelProcessing="true">

                                <to uri="scp://{{gcg.ste.Client1_User_Name}}@{{gcg.ste.Host_Name}}:{{gcg.ste.Port_Number}}/{{gcg.ste.Destination_Client1}}?knownHostsFile={{ssh.knownHosts}}&amp;privateKeyFile={{ssh.privateKey}}" />

                                <to uri="scp://{{gcg.ste.Client2_User_Name}}@{{gcg.ste.Host_Name}}:{{gcg.ste.Port_Number}}/{{gcg.ste.Destination_Client2}}?knownHostsFile={{ssh.knownHosts}}&amp;privateKeyFile={{ssh.privateKey}}" />                               

                                <to uri="scp://{{gcg.ste.Client3_User_Name}}@{{gcg.ste.Host_Name}}:{{gcg.ste.Port_Number}}/{{gcg.ste.Destination_Client3}}?knownHostsFile={{ssh.knownHosts}}&amp;privateKeyFile={{ssh.privateKey}}" />

                <to uri="file://{{nas.root}}/{{gcg.out.prices.dir}}?fileName={{archive.dir}}" />
        </multicast> 
<doCatch>
        <exception>java.lang.Exception</exception>
                <handled>
                        <constant>true</constant>
                </handled>                                       

                <to uri="file://{{nas.root}}/{{gcg.out.prices.dir}}?fileName={{error.dir}}" />
</doCatch>
</doTry>

文件未到达远程目的地,也没有生成任何日志,文件也被移动到存档文件夹。

我尝试将远程目的地,档案代码和移动到错误代码放在单独的路由中,并在单个多播中引用,如下所示

            <to uri="direct:Client1FileOut" />

            <to uri="direct:Client2FileOut" />                                                                                                                       

            <to uri="direct:Client3FileOut" />                       

            <to uri="direct:MoveToArchive" />                                       

<route id="gcgFileOut1">       
                        <from uri="direct:Client1FileOut" />                       
                        <doTry>                       

                                <to uri="scp://{{gcg.ste.Client1_User_Name}}@{{gcg.ste.Host_Name}}:{{gcg.ste.Port_Number}}/{{gcg.ste.Destination_Client1}}?knownHostsFile={{ssh.knownHosts}}&amp;privateKeyFile={{ssh.privateKey}}" />
                                <doCatch>
                                                <exception>java.lang.Exception</exception>
                                                <handled>
                                                        <constant>true</constant>
                                                </handled>

                                                <to uri="direct:gcgError" />       

                                </doCatch>
                        </doTry>
                </route>

但是,该文件没有到达远程目标,也没有生成任何日志,文件也被移动到存档文件夹。

我是骆驼的新手。

我尝试使用shareUnitOfWork属性,如下所示

<multicast shareUnitOfWork="true">

但是,文件与Test_2_19082013_3.txt.camelLock文件一起移动到存档文件夹

当丢弃的文件为Test_2_19082013_3.txt

时,不确定为什么此文件也会移动到存档

此外,在放置位置创建了名为“ARCHIV~1”的文件夹。

1 个答案:

答案 0 :(得分:1)

将文件移动到存档时可能会出错。你有stopOnException="true" parallelProcessing="true",本地文件可能先完成,因为它应该是最快的。

您可能想要在某处打印错误。现在,您捕获异常并将错误标记为已处理。你仍然期望日志。使用log组件并手动输出一些日志语句。不仅在案件或错误中,而且在成功的情况下。您可以登录调试级别,以便在需要时手动启用日志输出 - 就像现在一样。

另一个让你弄清楚发生了什么的选择是启用trace,这会让你不那么“盲目”。

关于自己进行调试的说法 -

您正在输入目录中存档和存储错误消息。你看到的锁文件是Camel正在读的时候。这很可能会使您的应用程序出现故障。

{{nas.root}}/{{gcg.out.prices.dir}}

fileName=...是文件名,而不是另一个子目录。

所以:file://{{nas.root}}/{{gcg.out.prices.dir}}/{{archive.dir}}应该这样做(同样是错误路径)。

相关问题