Apache camel ApacheCamel将ControlBusXML示例分组以使用预定义过滤器

Apache camel ApacheCamel将ControlBusXML示例分组以使用预定义过滤器,apache-camel,jgroups,control-bus,Apache Camel,Jgroups,Control Bus,我正在尝试重新调整代码以利用Jgroups/controlbus,但是,我需要一个Blueprint XML表示 如何在驼峰路线上实现预定义过滤器和延迟 <route autoStartup="true" id="clusterControlRoute"> <from uri="jgroups:fleetPredixCluster?enableViewMessages=true&amp;channelProperties=etc/jgroups.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>
JGroupsFilters.dropNonCoordinatorViews()
delayIfContextNotStarted(秒)。toMillis(5)

我已经问过RedHat团队,信用卡,这些家伙很棒

我知道我们必须实现为bean,但由于需要语法,无法在线找到。 所以它在这里

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

路演

您将获得路由代码的XML表示(Spring,但接近blueprint语法)

在本例中,它变得有点复杂,因为路由使用的是编译后的谓词和表达式(DropNonCordinatorViews和delayIfContextNotStarted),它们只是显示为对象实例(用@符号表示地址)

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

我们可以利用org.apache.camel.component.jgroups.JGroupsFilters和org.apache.camel.component.jgroups.jgroupsPressions上的静态方法作为工厂方法来实例化它们,如下所示:

    <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>

这为我们提供了DropNonCordinatorViews谓词和delayIfContextNotStarted表达式,作为我们可以在路由中使用的bean:
我们可以直接将谓词用作方法,如下所示:
块中的表达式,如下所示:
delayIfContextNotStarted