camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Brown" <Kevin.Br...@air2web.com>
Subject RE: Content Based Router - inefficient for large number of endpoints
Date Wed, 13 Aug 2008 22:26:49 GMT

Jon,

Thanks, I was unaware of dynamic nature of Recipient List (and since I visited last, James
Strachan updated the wiki to reflect that, I see).  I think Recipient List should solve both
my inefficiency and refresh problems.

- Kevin



-----Original Message-----
From: Jon Anstey [mailto:janstey@gmail.com]
Sent: Wed 8/13/2008 6:05 PM
To: camel-user@activemq.apache.org
Subject: Re: Content Based Router - inefficient for large number of endpoints
 
So, looks like your DestinationStamperProcessor adds a "url" header which is
the desired destination? If so, you could use either a dynamic recipientList
(http://activemq.apache.org/camel/recipient-list.html) or routingSlip (
http://activemq.apache.org/camel/routing-slip.html) to send to a dynamic
destination. For example,

...recipientList(header("url"))

would send incoming messages to the endpoint defined in the header "url"

Hope this helps.

Cheers,
Jon

On Wed, Aug 13, 2008 at 7:10 PM, Kevin Brown <Kevin.Brown@air2web.com>wrote:

>
>
> Camel users,
>
> I have a content based router with a large number of endpoints created
> dynamically from a database lookup (routes = dao.findAllRoutes()).  I
> have a processor/function (DestinationStamperProcessor) that determines the
> url to route a given message, but am then having to go through 400 or
> so if/then (choice/when) statements to route to the correct url (Please see
> configuration below):
>
> Is it possible to use the content based router without the choice/when
> syntax and provide my own function to determine which
> enpoint to route to?
>
> Example uglyness:
>
>
> routes = dao.findAllRoutes();
>
> context.addRoutes(new RouteBuilder() {
>        public void configure() {
>
>                ChoiceType urlChoice = from("seda:start".thread(1).
>                process(new DestinationStamperProcessor()).
>                process(new Processor() {
>                   public void process(Exchange exchange) {
>                           //convert Mo.class to
> application/x-www-form-urlencoded format for posting
>
> exchange.getIn().setBody(exchange.getIn().getBody(Mo.class).toApplicationXWwwFormUrlencoded());
>                   }
>                }).
>                choice();
>
>                //add lots of "when"s
>                Set<String> urls = getDistinctNotificationUrls(routes);
>                for (String url : urls) {
>                   urlChoice.when(header("url").isEqualTo(url)).
>                   to(url).
>                   convertBodyTo(String.class).
>                   to("log:camel [level=INFO])");
>                }
>
>              //add otherwise
>               urlChoice.otherwise().
>              to("log:MoDohickey (dead) [level=WARN])");
> }} );
>
>
> - Kevin
>
>
>
>


Mime
  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message