micfra
micfra

Reputation: 2820

Define multiple URI for one <to .../> element with camel-spring

Having an Apache Camel route defined in Java, I can do something like this

from("stream:in?promptMessage=Enter something: ")
  .loadBalance()
  .to("uria", "urib")

and it works like a charme.

Trying this using a Spring context file doesn't work out:

<c:camelContext id="defaultContext">
  <c:route id="defaultRoute">
    <c:from uri="stream:in?promptMessage=Enter something: "/>
    <c:loadBalance inheritErrorHandler="false">
      <c:to uri="uria, urib"/>
    </c:loadBalance>
    <c:to uri="stream:out"/>
  </c:route>
</c:camelContext>

Any idea, how i can set more than one uri per <c:to ... element? I do not want to have multiple <c:to ... elements. Is there any way, e.g. having a route factory passing the list?

What is the cause I want to achieve this: I'd like to inject a list of URIs from a configuration file passing them directly to the Camel route.

I'm using version 2.12.1 of Apache Camel.

Upvotes: 1

Views: 1297

Answers (1)

Hussain Pirosha
Hussain Pirosha

Reputation: 1376

  1. Use a RouteBuilder class to create a route that reads URI's from somewhere.
  2. Use contextScan to load the route builder class into spring camel context. Refer section Using contextScan on apache's site.

The RouteBuilder class shall be

@Component
public class MyRoute extends SpringRouteBuilder {

    @Override
    public void configure() throws Exception {
        String URIs = // read all URI's from file or somewhere
        from("direct:start")
           .loadbalance()
           .to(URIs);
    }
}

Upvotes: 1

Related Questions