0
votes

Java 8 and Apache Camel 2.19.5 here. I want to define a route (using Spring XML DSL) that accomplishes the following:

  1. Consumes a message from an ActiveMQ queue
  2. Deserializes the XML message from a String into a Fizzbuzz instance
  3. Sends the Fizzbuzz to a FoobarGenerator processor
  4. The FoobarGenerator processor generates a Foobar on the exchange
  5. Copies of the Foobar message then pass to two downstream processors at the same time: (a) The Configurator processor and (b) the Analyzer processor 6a. The Configurator processes the Foobar and stores some results in a DB 6b. The Analyzer processes the Foobar and then the route sends that instance to a deserializer (back into a String) and then sends that String to another AMQ queue

Here's what I have so far:

<route id="fizzbuzz_processor">
  <!-- Step 1: Consume Fizzbuzz XML from AMQ -->
  <from uri="activemq:fizzbuzzes"/>

  <!-- Step 2: Deserialize into Fizzbuzz POJO instance, using XStream -->
  <unmarshall ref="xs"/>

  <!--
    Step 3 + 4: Send to FoobarGenerator processor;
    output is a 'Foobar' POJO instance
  -->
  <to uri="bean:foobarGenerator"/>

  <!-- Step 5: Send Foobar to two places at the same time -->
  <multicast>
    <!-- Step 6a: Foobar goes to Configurator processor -->
    <to uri="bean:configurator"/>

    <!-- Step 6b: Foobar also goes to Analyzer processor -->
    <to uri="bean:analyzer"/>

    <!--
      AFTER Analyzer, Foobar gets serialized into XML and sent
      to another queue
    -->
    <marshall ref="xs"/>
    <to uri="activemq:foobars"/>
  </multicast>
</route>

The problem with this setup is that, from what I can tell, multicasters can only be defined with the top-level endpoints that they will be sending the messages to. So the way I have it configured above, the multicaster will send the message to: (a) bean:configurator, (b) bean:analyzer, (c) XStream/marshaller, and (d) activemq:fizzbuzzes at the same time, as opposed to sending to bean:configurator and bean:analyzer at the same time, and then after bean:analyzer, marshalling and sending to AMQ.

How can I reconfigure this route to do what I want?

2

2 Answers

0
votes

Turns out you can just:

<route id="fizzbuzz_processor">
  <!-- Step 1: Consume Fizzbuzz XML from AMQ -->
  <from uri="activemq:fizzbuzzes"/>

  <!-- Step 2: Deserialize into Fizzbuzz POJO instance, using XStream -->
  <unmarshall ref="xs"/>

  <!--
    Step 3 + 4: Send to FoobarGenerator processor;
    output is a 'Foobar' POJO instance
  -->
  <to uri="bean:foobarGenerator"/>

  <!-- Step 5: Send Foobar to two places at the same time -->
  <multicast parallelProcessing="true">
    <!-- Step 6a: Foobar goes to Configurator processor -->
    <to uri="bean:configurator"/>

    <!-- Step 6b: Foobar also goes to Analyzer processor -->
    <to uri="direct:someOtherRoute"/>
  </multicast>
</route>

Where direct:someOtherRoute goes to another route that implements everything after 6b that I described, and boom you've multicasted to both "places" at the same time.

-1
votes

Why do you want to use the multicaster EIP? Seems that you can have the same result, either by removing the multicaster altogether, e.g.:

<route id="fizzbuzz_processor">
  <!-- Step 1: Consume Fizzbuzz XML from AMQ -->
  <from uri="activemq:fizzbuzzes"/>
  <!-- Step 2: Deserialize into Fizzbuzz POJO instance, using XStream -->
  <unmarshall ref="xs"/>
  <!--
    Step 3 + 4: Send to FoobarGenerator processor;
    output is a 'Foobar' POJO instance
  -->
  <to uri="bean:foobarGenerator"/>

  <!-- Step 6a: Foobar goes to Configurator processor -->
  <to uri="bean:configurator"/>

  <!-- Step 6b: Foobar also goes to Analyzer processor -->
  <to uri="bean:analyzer"/>
  <marshall ref="xs"/>
  <to uri="activemq:foobars"/>
</route>

Or by leaving the marshal/activemq part out of the multicaster. Camel should complete the multicaster and the proceed with the marshal/to afterwards.