Apache Camel Jgroups controlbus XML示例使用预定义的过滤器

我正在尝试对代码进行改进以利用Jgroups / controlbus,但是,我需要一个Blueprint XML表示形式。

如何在骆驼路线上实施预定义的过滤器和延迟?

<route autoStartup="true" id="clusterControlRoute">
   <from uri="jgroups:fleetPredixCluster?enableViewMessages=true&amp;channelProperties=etc/jgroups.xml" />

   <!-- 
        .filter(dropNonCoordinatorViews())
        .threads().delay(delayIfContextNotStarted(SECONDS.toMillis(5))) // run in separated and delayed thread. Delay only if the context hasn't been started already. 
        .log(LoggingLevel.INFO,"Starting JGroups JChannel Consumer!!!!!!!!!!!!!!!!!!!!!")
   -->

   <to uri="controlbus:route?routeId=inRouteMT1&amp;action=start&amp;async=true"/>
</route>

如何通过XML使用这些预定义的过滤器和表达式?

<filter><simple> JGroupsFilters.dropNonCoordinatorViews() </simple></filter>
<threads><delay> delayIfContextNotStarted(SECONDS.toMillis(5) </delay></threads>
mm3030 回答:Apache Camel Jgroups controlbus XML示例使用预定义的过滤器

我已经问过RedHat团队,谢谢,这些家伙很棒!

我知道我们必须实现为bean,但是所需的语法无法在线找到。 所以这里是...

通常,如果您登录karaf shell并运行命令:

路线展示

您将获得路由代码的XML表示形式(Spring,但接近蓝图语法)。

在这种情况下,它变得有点复杂,因为路由使用的是已编译的谓词和表达式(dropNonCoordinatorViews和delayIfContextNotStarted),它们仅显示为对象实例(以@符号表示地址)。

为了在蓝图中使用那些已编译的谓词/表达式,我们需要将它们实例化为bean,然后引用它们。

我们可以通过将org.apache.camel.component.jgroups.JGroupsFilters和org.apache.camel.component.jgroups.JGroupsExpressions上的静态方法作为工厂方法来实例化它们,例如:

    <bean id="dropNonCoordinatorViews" class="org.apache.camel.component.jgroups.JGroupsFilters" factory-method="dropNonCoordinatorViews" scope="prototype"/>    

    <bean id="delayIfContextNotStarted" class="org.apache.camel.component.jgroups.JGroupsExpressions" factory-method="delayIfContextNotStarted" scope="prototype">
        <argument value="5000"/>
    </bean>  

This gives us the dropNonCoordinatorViews Predicate and delayIfContextNotStarted Expression as beans we can use in the route:

We can use the Predicate as a method directly,like so:

           <filter id="filterNonCoordinatorViews">
                <method ref="dropNonCoordinatorViews"/>

And the Expression in a <ref> block,like so:

                    <delay id="delay1">
                        <ref>delayIfContextNotStarted</ref>
本文链接:https://www.f2er.com/3148915.html

大家都在问