> XPathBuilder xPathBuilder=new XPathBuilder("trainSchedule/stops/station");
> from("activemq:queue:camel.train.plan.queue")
> .splitter(xPathBuilder)
> .convertBodyTo(String.class)
> .to("activemq:queue:camel.train.plan.queue.router");
>
> from("activemq:queue:camel.train.plan.queue.router").process(new Processor
> () {
>         public void process(Exchange exchange) {
>         Message in = exchange.getIn();
>             String text = (String)in.getBody();
>                 // city is the attribute, used for routing
>               String city;
>
>                 ...
>                 // find out city attribute of message content
>                 ...
>
>             //destinationCity is a variable defined outside the route, so it
> can be used outside, too
>             destinationCity = city;
>       }
> }).to("activemq:queue:camel.train.plan.queue." + destinationCity);
>
> I would expect Camel now to route the splitted message all to different
> endpoints, according to the city attributes of each
> message. But no routing at all happens. When I look at the ActiveMQ web
> console I see that a "camel.train.plan.queue." gets
> created, but this is not what I want. Is it not allowed to use string
> concatenation in the to-field of a route?

Forget such approach ;)

Notice that the method you are implementing is configure() method - it
is executed ONCE at the very beginning. It is not executed on each
message. And concatenation you use is executed when configure() method
is executed - it is still Java after all.

what you could do is

from("activemq:queue:camel.train.plan.queue.router")
.setHeader("endpointName",
constant("activemq:queue:camel.train.plan.queue.").append(new
Expression() {
    public Object evaluate(Exchange exchange) {
        return <evaluate your queue name postfix>
    }))
.receipentList(header("endpointName"));
}

Maybe instead of using new Expression() it will be enough to evaluate
the value using xpath or el so it will be simpler?

If you have only short list of destinations then maybe filter() is
better for you?

Roman

Reply via email to