Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Or you could write a custom processor which is injected with a ProducerTemplate instance that just generates N messages...

Code Block
public class MyProcessorMyProducer implements Processor {
  ProducerTemplate<Exchange>ProducerTemplate producer;

  public void setProducer(ProducerTemplate<Exchange>ProducerTemplate producer) {
    this.producer = producer;
  }

  public Exchangevoid process(Exchange inExchange) {
    // some loop for each message 
    for (String template in templates) {
       // lets send a new exchange to the producers default destination
       // being called back so we can customize the message
       producer.send(new Processor() {
          public Exchangevoid process(Exchange outExchange) {
              outExchange.getIn().setBody("This is the body"); 
              // set some headers too?
          }
       });
    }
}

...

Code Block
<camelContext xmlns="http://activemqcamel.apache.org/camel/schema/spring">
    <template id="myTemplate" defaultEndpoint="activemq:someQueue"/>
</camelContext>

<bean id="foo" class="MyProducer">
  <property name="producer" ref="myTemplate"/>
</bean>

Note that the default output URI is inherited from the <template/> configuration. If you prefer you could specify that in the *producer.send()( method call