apache-cameljgroupscontrol-bus

Apache Camel Jgroups controlbus XML examples to use predefined filters


I'm trying to retro fit my code to utilize Jgroups / controlbus, however, I need an Blueprint XML representation.

how can I implement predefined filters and delay on camel routes?

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

how can I utilize these predefined filters and expressions with XML?

<filter><simple> JGroupsFilters.dropNonCoordinatorViews() </simple></filter>
<threads><delay> delayIfContextNotStarted(SECONDS.toMillis(5) </delay></threads>

Solution

  • I have asked RedHat Team, credit, these guys are great!

    I knew we have to implement as beans, but, needed syntax, couldn't find on line. so here it is...

    In general, if you log into the karaf shell and run the command:

    route-show

    You will get an XML representation (Spring, but close to the blueprint syntax) of the route code.

    In this case, it gets a little complicated, because the route is using a compiled Predicate and Expresssion (dropNonCoordinatorViews and delayIfContextNotStarted), which are just displayed as object instances (with the @ symbol for address).

    In order to use those compiled predicates / expressions in blueprint, we need to instantiate them as beans and then refer to them.

    We can instantiate them by leveraging the static methods on org.apache.camel.component.jgroups.JGroupsFilters and org.apache.camel.component.jgroups.JGroupsExpressions as factory methods, like so:

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