Can't I achieve something similar using bean in the splitter as explained in
Using a "Pojo to do the splitting" on http://camel.apache.org/splitter.html

I was trying to understand the code, but am wondering how will I get back
the whole message. The example there sends a arraylist of string, but I
would want messages with the existing headers intact.

Another solution I am thinking of is making the message a object and not a
string and passing the to address string as part of it.

I am making a reliable mass mailing solution with spam control based on
ActiveMQ and camel, is it the right approach?
 


Claus Ibsen-2 wrote:
> 
> On Fri, May 8, 2009 at 2:58 PM, rohitbrai <rohitb...@gmail.com> wrote:
>>
>> I have a message which has -
>> Header
>>    "To" - "a...@sdf.com,x...@dsfsdf.com,s...@serr.com"
>> Body
>>    Hello
>>
>> onthis message I tried -
>>
>> from("jms:queue:new.test1").splitter(header("To").tokenize(",")).to("jms:queue:new.test2");
>>
>> and I was expecting 3 entries on test2 queue
>> Header
>>    "To" - "a...@sdf.com"
>> Body
>>    Hello
>>
>> Header
>>    "To" - "x...@dsfsdf.com"
>> Body
>>    Hello
>>
>> Header
>>    "To" - "s...@serr.com"
>> Body
>>    Hello
>>
>>
>> But instead I got 3 messages on test2 queue like
>> Header
>>    "To" - "a...@sdf.com,x...@dsfsdf.com,s...@serr.com"
>> Body
>>    ...@sdf.com
>>
>> Header
>>    "To" - "a...@sdf.com,x...@dsfsdf.com,s...@serr.com"
>> Body
>>    ...@dsfsdf.com
>>
>> Header
>>    "To" - "a...@sdf.com,x...@dsfsdf.com,s...@serr.com"
>> Body
>>    s...@serr.com
>>
>> So I guess, I am doing it and even understanding it wrong.
>>
>> Can anyone here guide me how to handle this situation.
> Hi
> 
> Welcome on the Camel ride.
> 
> The EIP patterns is about message routing where the message relies in
> the BODY payload.
> The header is just meta data about the message.
> 
> So the splitter operates on splitting the BODY and not the headers,
> hence why you get the email address in the body.
> 
> So by default there EIP patterns dont really support your use case out
> of the box, unless you do some manual fixup in Java code.
> 
> You could use a POJO or the like where you create new messages to send
> along.
> 
> private ProducerTemplate producer
> 
> public void sendSplittedMessages(String body, @Headers Map headers) {
>   // loop the headers for each email adr
>   for (...) {
>      String email = ...
>      producer.sendBodyAndHeader("jms:queue:new:test02", body, "To",
> email);
>    }
> 
> And then have a route that is like
> from("jms:queue:new.test1").bean(MySplitMessageClass.class,
> "sendSplittedMessages");
> 
> where we route to our bean that, will do the "split" manually and send
> a new message to the JMS queue.
> 
> 
>>
>> Thanks and Regards,
>>
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Split-using-tokenize-on-header-tp23445496p23445496.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> Claus Ibsen
> Apache Camel Committer
> 
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
> Apache Camel Reference Card:
> http://refcardz.dzone.com/refcardz/enterprise-integration
> Interview with me:
> http://architects.dzone.com/articles/interview-claus-ibsen-about?mz=7893-progress
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Split-using-tokenize-on-header-tp23445496p23445999.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to