camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpbarto <Jason.P.Ba...@gmail.com>
Subject Re: Camel Integration Advice Needed
Date Mon, 24 Jun 2013 12:56:11 GMT
Final Solution:

I think I've found the solution I was looking for in the form of the XML
'routes' tag as mentioned previously.  

In addition to the traditional camel-context.xml I've also created two
additional XML files (subscribe-template.xml and publish-template.xml).  An
example follows:

<?xml version="1.0" encoding="UTF-8"?>
<routes xmlns="http://camel.apache.org/schema/spring">
    <route id="foo-$topic">
        <from uri="rabbitmq://cml.topic:$topic"/>
        <to uri="foo://$topic"/>
    </route>
</routes>

In Java code, when I want to bind one component create a subscription I
would execute the following:

    public void subscribe(final String topic) throws Exception {
        if (! subscribedConsumerRoutes.containsKey(topic)) {
            List<Route> routes = new ArrayList<Route>();

            InputStream istream =
getClass().getClassLoader().getResourceAsStream(subscriberTemplate);
            String template = IOUtils.toString(istream,
"UTF-8").replace("$topic", topic);
            istream = IOUtils.toInputStream(template, "UTF-8");
            RoutesDefinition routesDef =
camelContext.loadRoutesDefinition(istream);
            camelContext.addRouteDefinitions(routesDef.getRoutes());

            for (RouteDefinition route : routesDef.getRoutes()) {
                routes.add(camelContext.getRoute(route.getId()));
            }
            subscribedConsumerRoutes.put(topic, routes);
        }
    }

The question now becomes how to modify an existing route to add new
'consumers' to the route.  For example if a route looks like:

<from uri="rabbitmq://cml.topic:a.b.c"/>
<multicast>
  <to uri="mock:a"/>
  <to uri="mock:b"/>
</multicast>

How does one modify it to:
<from uri="rabbitmq://cml.topic:a.b.c"/>
<multicast>
  <to uri="mock:a"/>
  <to uri="mock:b"/>
  <to uri="mock:c"/>
</multicast>

I can't find a way to get a reference to a route's multicast service so how
to best do this... perhaps with a DynamicRouter?



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Integration-Advice-Needed-tp5734283p5734664.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message