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:[EMAIL PROTECTED] Sent: Wed 8/13/2008 6:05 PM To: [email protected] 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 <[EMAIL PROTECTED]>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 > > > >
