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


                

Reply via email to