Java 如何使用Apache Camel处理长时间运行的任务 我有一个CAMEL根,在root的中间执行HTTP调用,以丰富Exchange中的主要对象: <route> <from uri="http:somerest

Java 如何使用Apache Camel处理长时间运行的任务 我有一个CAMEL根,在root的中间执行HTTP调用,以丰富Exchange中的主要对象: <route> <from uri="http:somerest,java,multithreading,apache-camel,Java,Multithreading,Apache Camel,如何使用Apache Camel处理长时间运行的任务 我有一个CAMEL根,在root的中间执行HTTP调用,以丰富Exchange中的主要对象: <route> <from uri="http:somerestcall"/> <bean ref="jsonUtils" method="someJsonConversion"/> <split> <simple

如何使用Apache Camel处理长时间运行的任务

我有一个CAMEL根,在root的中间执行HTTP调用,以丰富Exchange中的主要对象:

     <route>
        <from uri="http:somerestcall"/> 
        <bean ref="jsonUtils" method="someJsonConversion"/>
        <split>
            <simple>body</simple>
            <!-- this is the one -->
            <bean ref="enrichmentBean" method="someAdditionalHTTPCall"/>
        </split>
        <to uri="writetosomequeue"/>
    </route>

身体

<> P.>我知道CAMEL提供了大量的-<强>我如何最好地利用CAMEL来处理路由中途潜在的长时间运行的HTTP调用,而不让线程陷入睡眠模式?< /强>

< P>这个问题有点具体应用,如果您的线程正在等待来自HTTP请求的响应,并且需要这些信息才能继续,那么我将使该进程更加并行,而让线程什么也不做。如果线程不工作,它也不会浪费真正的cpu。但是,如果您的进程在等待http调用时可以继续工作,那么我建议将其发送到seda路由以执行查找调用,然后将结果存储在稍后可以访问的位置,就像一个并发映射,您可以根据某种键引用结果

<route>
    <from uri="http:somerestcall"/> 
    <bean ref="jsonUtils" method="someJsonConversion"/>
    <split>
        <simple>body</simple>
        <!-- this is the one -->
        <to uri="seda:concurrentFun" />
    </split>
    <to uri="Lots of other work" />
    <bean ref="StorageBean" method="enrichFromStoreAndRemove" />
    <to uri="writetosomequeue"/>
</route>

<route>
    <From uri="seda:concurrentFun" />
    <bean ref="enrichmentBean" method="someAdditionalHTTPCall"/>
    <bean ref="StorageBean" method="store" />
</route>

身体