You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Klug, Johannes" <jo...@logica.com> on 2010/03/15 20:13:08 UTC

POJO Splitter - how to send multiple messages?

Dear list,

I am implementing a POJO splitter that takes one message as its input,
and shall split this message into multiple output messages.

My route looks like this:

...
processor = new ContainerProcessor();
from("direct:start").split().method(processor,
"process").to(resultEndpoint);
...

Processor's process function returns List<Message>.
However, no messages are received in resultEndpoint.

According to http://camel.apache.org/splitter.html, I need my own
AggregationStrategy to combine the split messages. Unless there is a way
to add more than one message to an exchange, this is not what I want - I
just want a route that will produce n messages for each message put in.

Is there a way I can achieve this with Camel?

Thanks and kind regards,
Johannes Klug



Please help Logica to respect the environment by not printing this email  / Pour contribuer comme Logica au respect de l'environnement, merci de ne pas imprimer ce mail /  Bitte drucken Sie diese Nachricht nicht aus und helfen Sie so Logica dabei, die Umwelt zu schützen. /  Por favor ajude a Logica a respeitar o ambiente nao imprimindo este correio electronico.



This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.


Re: POJO Splitter - how to send multiple messages?

Posted by Willem Jiang <wi...@gmail.com>.
A small step camel route unit test can help us locate the issue.
It's good to see you finally resolved the issue yourself.

Willem

Klug, Johannes wrote:
> I fixed it, sorry for the commotion.
> Turned out I cleared my message list too soon, so it didn't reach the next Camel hop.
> 	
> Cheers,
> Johannes
> 
> 
>> -----Original Message-----
>> From: Klug, Johannes [mailto:johannes.klug@logica.com]
>> Sent: 16 March 2010 11:30
>> To: users@camel.apache.org
>> Subject: RE: POJO Splitter - how to send multiple messages?
>>
>> I wrote a very simple splitter test, and it behaves like expected - the
>> returned List<Message> is sent to the endpoint. It's just in my more
>> complex scenario where it doesn't act like it should.
>>
>> I'm debugging this now, hints are appreciated, though :)
>>
>> Cheers,
>> Johannes
>>
>>> -----Original Message-----
>>> From: Klug, Johannes [mailto:johannes.klug@logica.com]
>>> Sent: 16 March 2010 10:25
>>> To: users@camel.apache.org
>>> Subject: RE: POJO Splitter - how to send multiple messages?
>>>
>>> Hi Willem,
>>>
>>> Thanks for your reply.
>>> I'm using Camel v2.2.0.
>>>
>>> I implemented a Splitter that returns List<Message>, just like in
>> your
>>> example. That list gets built properly, in my test it contains 26
>>> messages.
>>> However, nothing reaches the endpoint.
>>>
>>> This is my route:
>>> ...
>>> processor = new ContainerProcessor();
>>> from("direct:start").split().method(processor,
>>> "process").to("mock:result");
>>> ...
>>>
>>> From my understanding, all messages in the returned list should be
>> sent
>>> to the endpoint "mock:result", no?
>>>
>>> Cheers,
>>> Johannes
>>>
>>>> -----Original Message-----
>>>> From: Willem Jiang [mailto:willem.jiang@gmail.com]
>>>> Sent: 16 March 2010 03:18
>>>> To: users@camel.apache.org
>>>> Subject: Re: POJO Splitter - how to send multiple messages?
>>>>
>>>> Which version of Camel are you using?
>>>> Here is an example of split the message in POJO.
>>>>
>>>>   public List<Message> splitMessage(@Header(value = "user") String
>>>> header, @Body String body) {
>>>>              // we can leverage the Parameter Binding Annotations
>>>>              // http://camel.apache.org/parameter-binding-
>>>> annotations.html
>>>>              // to access the message header and body at same time,
>>>>              // then create the message that we want, splitter will
>>>>              // take care rest of them.
>>>>              // *NOTE* this feature requires Camel version >= 1.6.1
>>>>              List<Message> answer = new ArrayList<Message>();
>>>>              String[] parts = header.split(",");
>>>>              for (String part : parts) {
>>>>                  DefaultMessage message = new DefaultMessage();
>>>>                  message.setHeader("user", part);
>>>>                  message.setBody(body);
>>>>                  answer.add(message);
>>>>              }
>>>>              return answer;
>>>>          }
>>>>
>>>> Willem
>>>>
>>>> Klug, Johannes wrote:
>>>>> Dear list,
>>>>>
>>>>> I am implementing a POJO splitter that takes one message as its
>>>> input,
>>>>> and shall split this message into multiple output messages.
>>>>>
>>>>> My route looks like this:
>>>>>
>>>>> ...
>>>>> processor = new ContainerProcessor();
>>>>> from("direct:start").split().method(processor,
>>>>> "process").to(resultEndpoint);
>>>>> ...
>>>>>
>>>>> Processor's process function returns List<Message>.
>>>>> However, no messages are received in resultEndpoint.
>>>>>
>>>>> According to http://camel.apache.org/splitter.html, I need my own
>>>>> AggregationStrategy to combine the split messages. Unless there
>> is
>>> a
>>>> way
>>>>> to add more than one message to an exchange, this is not what I
>>> want
>>>> - I
>>>>> just want a route that will produce n messages for each message
>> put
>>>> in.
>>>>> Is there a way I can achieve this with Camel?
>>>>>
>>>>> Thanks and kind regards,
>>>>> Johannes Klug
>>>
>>
>> Please help Logica to respect the environment by not printing this
>> email  / Pour contribuer comme Logica au respect de l'environnement,
>> merci de ne pas imprimer ce mail /  Bitte drucken Sie diese Nachricht
>> nicht aus und helfen Sie so Logica dabei, die Umwelt zu schützen. /
>> Por favor ajude a Logica a respeitar o ambiente nao imprimindo este
>> correio electronico.
>>
>>
>>
>> This e-mail and any attachment is for authorised use by the intended
>> recipient(s) only. It may contain proprietary material, confidential
>> information and/or be subject to legal privilege. It should not be
>> copied, disclosed to, retained or used by, any other party. If you are
>> not an intended recipient then please promptly delete this e-mail and
>> any attachment and all copies and inform the sender. Thank you.
>>
>>
> 
> 
> Please help Logica to respect the environment by not printing this email  / Pour contribuer comme Logica au respect de l'environnement, merci de ne pas imprimer ce mail /  Bitte drucken Sie diese Nachricht nicht aus und helfen Sie so Logica dabei, die Umwelt zu schützen. /  Por favor ajude a Logica a respeitar o ambiente nao imprimindo este correio electronico.
> 
> 
> 
> This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
> 
> 
> 


RE: POJO Splitter - how to send multiple messages?

Posted by "Klug, Johannes" <jo...@logica.com>.
I fixed it, sorry for the commotion.
Turned out I cleared my message list too soon, so it didn't reach the next Camel hop.
	
Cheers,
Johannes


> -----Original Message-----
> From: Klug, Johannes [mailto:johannes.klug@logica.com]
> Sent: 16 March 2010 11:30
> To: users@camel.apache.org
> Subject: RE: POJO Splitter - how to send multiple messages?
> 
> I wrote a very simple splitter test, and it behaves like expected - the
> returned List<Message> is sent to the endpoint. It's just in my more
> complex scenario where it doesn't act like it should.
> 
> I'm debugging this now, hints are appreciated, though :)
> 
> Cheers,
> Johannes
> 
> > -----Original Message-----
> > From: Klug, Johannes [mailto:johannes.klug@logica.com]
> > Sent: 16 March 2010 10:25
> > To: users@camel.apache.org
> > Subject: RE: POJO Splitter - how to send multiple messages?
> >
> > Hi Willem,
> >
> > Thanks for your reply.
> > I'm using Camel v2.2.0.
> >
> > I implemented a Splitter that returns List<Message>, just like in
> your
> > example. That list gets built properly, in my test it contains 26
> > messages.
> > However, nothing reaches the endpoint.
> >
> > This is my route:
> > ...
> > processor = new ContainerProcessor();
> > from("direct:start").split().method(processor,
> > "process").to("mock:result");
> > ...
> >
> > From my understanding, all messages in the returned list should be
> sent
> > to the endpoint "mock:result", no?
> >
> > Cheers,
> > Johannes
> >
> > > -----Original Message-----
> > > From: Willem Jiang [mailto:willem.jiang@gmail.com]
> > > Sent: 16 March 2010 03:18
> > > To: users@camel.apache.org
> > > Subject: Re: POJO Splitter - how to send multiple messages?
> > >
> > > Which version of Camel are you using?
> > > Here is an example of split the message in POJO.
> > >
> > >   public List<Message> splitMessage(@Header(value = "user") String
> > > header, @Body String body) {
> > >              // we can leverage the Parameter Binding Annotations
> > >              // http://camel.apache.org/parameter-binding-
> > > annotations.html
> > >              // to access the message header and body at same time,
> > >              // then create the message that we want, splitter will
> > >              // take care rest of them.
> > >              // *NOTE* this feature requires Camel version >= 1.6.1
> > >              List<Message> answer = new ArrayList<Message>();
> > >              String[] parts = header.split(",");
> > >              for (String part : parts) {
> > >                  DefaultMessage message = new DefaultMessage();
> > >                  message.setHeader("user", part);
> > >                  message.setBody(body);
> > >                  answer.add(message);
> > >              }
> > >              return answer;
> > >          }
> > >
> > > Willem
> > >
> > > Klug, Johannes wrote:
> > > > Dear list,
> > > >
> > > > I am implementing a POJO splitter that takes one message as its
> > > input,
> > > > and shall split this message into multiple output messages.
> > > >
> > > > My route looks like this:
> > > >
> > > > ...
> > > > processor = new ContainerProcessor();
> > > > from("direct:start").split().method(processor,
> > > > "process").to(resultEndpoint);
> > > > ...
> > > >
> > > > Processor's process function returns List<Message>.
> > > > However, no messages are received in resultEndpoint.
> > > >
> > > > According to http://camel.apache.org/splitter.html, I need my own
> > > > AggregationStrategy to combine the split messages. Unless there
> is
> > a
> > > way
> > > > to add more than one message to an exchange, this is not what I
> > want
> > > - I
> > > > just want a route that will produce n messages for each message
> put
> > > in.
> > > >
> > > > Is there a way I can achieve this with Camel?
> > > >
> > > > Thanks and kind regards,
> > > > Johannes Klug
> >
> >
> 
> 
> Please help Logica to respect the environment by not printing this
> email  / Pour contribuer comme Logica au respect de l'environnement,
> merci de ne pas imprimer ce mail /  Bitte drucken Sie diese Nachricht
> nicht aus und helfen Sie so Logica dabei, die Umwelt zu schützen. /
> Por favor ajude a Logica a respeitar o ambiente nao imprimindo este
> correio electronico.
> 
> 
> 
> This e-mail and any attachment is for authorised use by the intended
> recipient(s) only. It may contain proprietary material, confidential
> information and/or be subject to legal privilege. It should not be
> copied, disclosed to, retained or used by, any other party. If you are
> not an intended recipient then please promptly delete this e-mail and
> any attachment and all copies and inform the sender. Thank you.
> 
> 


Please help Logica to respect the environment by not printing this email  / Pour contribuer comme Logica au respect de l'environnement, merci de ne pas imprimer ce mail /  Bitte drucken Sie diese Nachricht nicht aus und helfen Sie so Logica dabei, die Umwelt zu schützen. /  Por favor ajude a Logica a respeitar o ambiente nao imprimindo este correio electronico.



This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.



RE: POJO Splitter - how to send multiple messages?

Posted by "Klug, Johannes" <jo...@logica.com>.
I wrote a very simple splitter test, and it behaves like expected - the
returned List<Message> is sent to the endpoint. It's just in my more
complex scenario where it doesn't act like it should.

I'm debugging this now, hints are appreciated, though :)

Cheers,
Johannes

> -----Original Message-----
> From: Klug, Johannes [mailto:johannes.klug@logica.com]
> Sent: 16 March 2010 10:25
> To: users@camel.apache.org
> Subject: RE: POJO Splitter - how to send multiple messages?
> 
> Hi Willem,
> 
> Thanks for your reply.
> I'm using Camel v2.2.0.
> 
> I implemented a Splitter that returns List<Message>, just like in your
> example. That list gets built properly, in my test it contains 26
> messages.
> However, nothing reaches the endpoint.
> 
> This is my route:
> ...
> processor = new ContainerProcessor();
> from("direct:start").split().method(processor,
> "process").to("mock:result");
> ...
> 
> From my understanding, all messages in the returned list should be
sent
> to the endpoint "mock:result", no?
> 
> Cheers,
> Johannes
> 
> > -----Original Message-----
> > From: Willem Jiang [mailto:willem.jiang@gmail.com]
> > Sent: 16 March 2010 03:18
> > To: users@camel.apache.org
> > Subject: Re: POJO Splitter - how to send multiple messages?
> >
> > Which version of Camel are you using?
> > Here is an example of split the message in POJO.
> >
> >   public List<Message> splitMessage(@Header(value = "user") String
> > header, @Body String body) {
> >              // we can leverage the Parameter Binding Annotations
> >              // http://camel.apache.org/parameter-binding-
> > annotations.html
> >              // to access the message header and body at same time,
> >              // then create the message that we want, splitter will
> >              // take care rest of them.
> >              // *NOTE* this feature requires Camel version >= 1.6.1
> >              List<Message> answer = new ArrayList<Message>();
> >              String[] parts = header.split(",");
> >              for (String part : parts) {
> >                  DefaultMessage message = new DefaultMessage();
> >                  message.setHeader("user", part);
> >                  message.setBody(body);
> >                  answer.add(message);
> >              }
> >              return answer;
> >          }
> >
> > Willem
> >
> > Klug, Johannes wrote:
> > > Dear list,
> > >
> > > I am implementing a POJO splitter that takes one message as its
> > input,
> > > and shall split this message into multiple output messages.
> > >
> > > My route looks like this:
> > >
> > > ...
> > > processor = new ContainerProcessor();
> > > from("direct:start").split().method(processor,
> > > "process").to(resultEndpoint);
> > > ...
> > >
> > > Processor's process function returns List<Message>.
> > > However, no messages are received in resultEndpoint.
> > >
> > > According to http://camel.apache.org/splitter.html, I need my own
> > > AggregationStrategy to combine the split messages. Unless there is
> a
> > way
> > > to add more than one message to an exchange, this is not what I
> want
> > - I
> > > just want a route that will produce n messages for each message
put
> > in.
> > >
> > > Is there a way I can achieve this with Camel?
> > >
> > > Thanks and kind regards,
> > > Johannes Klug
> 
> 


Please help Logica to respect the environment by not printing this email  / Pour contribuer comme Logica au respect de l'environnement, merci de ne pas imprimer ce mail /  Bitte drucken Sie diese Nachricht nicht aus und helfen Sie so Logica dabei, die Umwelt zu sch�tzen. /  Por favor ajude a Logica a respeitar o ambiente nao imprimindo este correio electronico.



This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.



RE: POJO Splitter - how to send multiple messages?

Posted by "Klug, Johannes" <jo...@logica.com>.
Hi Willem,

Thanks for your reply.
I'm using Camel v2.2.0.

I implemented a Splitter that returns List<Message>, just like in your
example. That list gets built properly, in my test it contains 26
messages.
However, nothing reaches the endpoint. 

This is my route:
...
processor = new ContainerProcessor();
from("direct:start").split().method(processor,
"process").to("mock:result");
...

>From my understanding, all messages in the returned list should be sent
to the endpoint "mock:result", no?

Cheers,
Johannes

> -----Original Message-----
> From: Willem Jiang [mailto:willem.jiang@gmail.com]
> Sent: 16 March 2010 03:18
> To: users@camel.apache.org
> Subject: Re: POJO Splitter - how to send multiple messages?
> 
> Which version of Camel are you using?
> Here is an example of split the message in POJO.
> 
>   public List<Message> splitMessage(@Header(value = "user") String
> header, @Body String body) {
>              // we can leverage the Parameter Binding Annotations
>              // http://camel.apache.org/parameter-binding-
> annotations.html
>              // to access the message header and body at same time,
>              // then create the message that we want, splitter will
>              // take care rest of them.
>              // *NOTE* this feature requires Camel version >= 1.6.1
>              List<Message> answer = new ArrayList<Message>();
>              String[] parts = header.split(",");
>              for (String part : parts) {
>                  DefaultMessage message = new DefaultMessage();
>                  message.setHeader("user", part);
>                  message.setBody(body);
>                  answer.add(message);
>              }
>              return answer;
>          }
> 
> Willem
> 
> Klug, Johannes wrote:
> > Dear list,
> >
> > I am implementing a POJO splitter that takes one message as its
> input,
> > and shall split this message into multiple output messages.
> >
> > My route looks like this:
> >
> > ...
> > processor = new ContainerProcessor();
> > from("direct:start").split().method(processor,
> > "process").to(resultEndpoint);
> > ...
> >
> > Processor's process function returns List<Message>.
> > However, no messages are received in resultEndpoint.
> >
> > According to http://camel.apache.org/splitter.html, I need my own
> > AggregationStrategy to combine the split messages. Unless there is a
> way
> > to add more than one message to an exchange, this is not what I want
> - I
> > just want a route that will produce n messages for each message put
> in.
> >
> > Is there a way I can achieve this with Camel?
> >
> > Thanks and kind regards,
> > Johannes Klug


Please help Logica to respect the environment by not printing this email  / Pour contribuer comme Logica au respect de l'environnement, merci de ne pas imprimer ce mail /  Bitte drucken Sie diese Nachricht nicht aus und helfen Sie so Logica dabei, die Umwelt zu sch�tzen. /  Por favor ajude a Logica a respeitar o ambiente nao imprimindo este correio electronico.



This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.



Re: POJO Splitter - how to send multiple messages?

Posted by Willem Jiang <wi...@gmail.com>.
Which version of Camel are you using?
Here is an example of split the message in POJO.

  public List<Message> splitMessage(@Header(value = "user") String 
header, @Body String body) {
             // we can leverage the Parameter Binding Annotations
             // http://camel.apache.org/parameter-binding-annotations.html
             // to access the message header and body at same time,
             // then create the message that we want, splitter will
             // take care rest of them.
             // *NOTE* this feature requires Camel version >= 1.6.1
             List<Message> answer = new ArrayList<Message>();
             String[] parts = header.split(",");
             for (String part : parts) {
                 DefaultMessage message = new DefaultMessage();
                 message.setHeader("user", part);
                 message.setBody(body);
                 answer.add(message);
             }
             return answer;
         }

Willem

Klug, Johannes wrote:
> Dear list,
> 
> I am implementing a POJO splitter that takes one message as its input,
> and shall split this message into multiple output messages.
> 
> My route looks like this:
> 
> ...
> processor = new ContainerProcessor();
> from("direct:start").split().method(processor,
> "process").to(resultEndpoint);
> ...
> 
> Processor's process function returns List<Message>.
> However, no messages are received in resultEndpoint.
> 
> According to http://camel.apache.org/splitter.html, I need my own
> AggregationStrategy to combine the split messages. Unless there is a way
> to add more than one message to an exchange, this is not what I want - I
> just want a route that will produce n messages for each message put in.
> 
> Is there a way I can achieve this with Camel?
> 
> Thanks and kind regards,
> Johannes Klug
> 
> 
> 
> Please help Logica to respect the environment by not printing this email  / Pour contribuer comme Logica au respect de l'environnement, merci de ne pas imprimer ce mail /  Bitte drucken Sie diese Nachricht nicht aus und helfen Sie so Logica dabei, die Umwelt zu schützen. /  Por favor ajude a Logica a respeitar o ambiente nao imprimindo este correio electronico.
> 
> 
> 
> This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
> 
>