I have an existing REST web service that sends an alert based upon the
provided "recipient" and "msgtext"  (given in the GET url).

In camel, I have a route that takes the recipient name and msg from the
"sendTo" and "msg" headers and sends a request to the web service.  This has
been working fine.

Now however, in my camel app I have a new header (recipientList") that holds
a pipe-delimeted list of recipients for that msg.  So, if that list has four
recipients (e.g. "JohnSmith|JaneDoe|BillJones,BettyBlue") , I want to do
four Posts to the alert web service for each recipient.

After reading this post
(http://camel.465427.n5.nabble.com/Split-using-tokenize-on-header-td474938.html#a474945)
 
I implemented a test bean that takes parameters:

 * broadcast(@Header("recipientList") String recipientList, String endpoint,
CamelContext context, Exchange exchange)*

In that method, I put the recipients into a list and then iterate over that
list sending a message for each item to the endpoint passed in:

  *ProducerTemplate producer = context.createProducerTemplate();
  ...
  for (String recipient: recipList){
    ....
     producer.send(endpoint,exchange)
  }*

My route looks like: 
 
*from("direct:r1").bean(Splitter.class,"broadcast(*,\"direct:sendAlert\")")*

So, my question is, Is there a better way?  Is this a safe thing to do
(inserting new messages from within a route)?  I'm guessing this would break
a transaction (at least if only one of the created msgs fails).

What is the best practice to take a header, split it up by a delimiter, then
send a message for each component?

Thank you for any insight,
-J




--
View this message in context: 
http://camel.465427.n5.nabble.com/Best-Practice-for-splitting-on-header-tp5713433.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to