camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Discussion - Route Policy feature in Camel 2.1
Date Wed, 28 Oct 2009 14:15:40 GMT
Hi

I have done some experiment and I am setting down for something like this

Where we can configure a route policy to use.
In this case we use a throtteling policy that is based on the number
of in flight exchanges.

In this example at most 16 in flights messages is aimed for. It can go higher.
But when the policy is investigated it will react if the current in
flight > max.
If so it will suspend/stop the consumer. And when it goes down to 25%
of 16 (=4) then it will resume / start the consumer again.

Apache CXF have already this feature. So its inspired from this project.

    <bean id="myPolicy" class="org.apache.camel.impl.ThrottelingRoutePolicy">
        <property name="maxInflightExchanges" value="16"/>
        <property name="reconnectPercentOfMax" value="25"/>
    </bean>

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route routePolicyRef="myPolicy">
            <from uri="activemq:queue:foo?concurrentConsumers=20"/>
            <transacted/>
            <delay><constant>100</constant></delay>
            <to uri="log:foo?groupSize=10"/>
            <to uri="mock:result"/>
        </route>
    </camelContext>



You can of course implement your own route policy and do whatever you like.

The route policy is this interface. I amy want to adjust the naming of
that method and maybe change it to be more routish.
Its based on a callback that is invoked when an Exchange is done being
routed. So maybe something as:

      void onRouteDone(Route route, Exchange exchange);

is better as its more clear to the point. And you can get the Consumer
from the Route so you can grab it and susped/stop it on the fly.


public interface RoutePolicy {

    /**
     * Callback invokes when a {@link Consumer} have consumed and
created an {@link Exchange}
     *
     * @param consumer  the consumer
     * @param exchange  the created exchange
     */
    void onConsume(Consumer consumer, Exchange exchange);
}




On Wed, Oct 28, 2009 at 8:15 AM, Claus Ibsen <claus.ibsen@gmail.com> wrote:
> Hi
>
> A bit of background is CAMEL-1048
> https://issues.apache.org/activemq/browse/CAMEL-1048
>
> I am looking into this how to implement this nicely in Camel.
>
> CAMEL-1048 is maybe a bit too much at current requirements from Camel users.
> What they are looking for is to be able to dynamic throttle consumers.
>
> Apache CXF and ServiceMix has such a feature specially build in their
> JMS components.
> What it does is that it can stop the JMS listener when there are too
> many messages in flight.
>
> But on the other hand we have also had Camel users wanting to dynamic
> start/stop consumers depending on some flag of some sort.
> So there is also grounds to make this a general solution that can
> cater both use cases.
>
> I do wonder how to move forward.
> In CAMEL-1048 there is an example using requires to associate a route
> that this predicate must be true for the route to be running.
> I do not like the naming requires or require. And having it in the
> fluent builder / DSL makes it fixed.
>
> Wonder if we should name such a configuration a RoutePolicy so you can
> configure it as
>
> <route routePolicy="myRoutePolicy">
>   <from .../>
>  ...
> </route>
>
> <bean id="myRoutePolicy" class=...>
>   <property name="maxInflightExchanges" value="500"/>
> </bean>
>
> This is quite flexible as we can just offer a SPI interface for the
> RoutePolicy and have people implement it as how they like it.
> For example as above something that is controlled by the number of
> current in flight exchanges.
>
> Others can control it by CPU utliization, a switch, timer based etc.
>
>
> In the Java DSL its
>
> from("xxx").routePolicy(myRoutePolicy).to(yyyy);
>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Mime
View raw message