You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ErwinK <er...@gmail.com> on 2009/06/12 12:07:49 UTC

Custom AggregationStrategy needs specific headers

Hello,

I am using Camel 1.6.1. With the following route:

from("timer://timer?period=1000")
.setBody(constant("select * from table"))
.to("jdbc:db")
.splitter(body(List.class), new MyAggregationStrategy())
.to("some default component uri that doesn't forward headers")
.end()
.to("log:log")

The aggregationstrategy needs org.apache.camel.SplitIndex and
org.apache.camel.SplitSize but you lose them during the route in the
splitter part.

I can work around the problem by saving the headers in an exchange property
as first step and restore them just before the aggregation, but shouldn't
the splitter itself store necessary information in a property?

Regards,
Erwin
-- 
View this message in context: http://www.nabble.com/Custom-AggregationStrategy-needs-specific-headers-tp23996092p23996092.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Custom AggregationStrategy needs specific headers

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Jun 12, 2009 at 4:38 PM, ErwinK<er...@gmail.com> wrote:
>
>
> Claus Ibsen-2 wrote:
>>
>> Hi
>>
>> I have created a ticket to track this issue
>> https://issues.apache.org/activemq/browse/CAMEL-1702
>>
>> We will *only* do this migration at Camel 2.0 to keep the old behavior
>> in Camel 1.6.x as this branch is maintenance and for important bug
>> fixes only.
>> Its intended for drop in replacements for production usage and this we
>> cannot change such behavior. Even if it would make life easier.
>>
>>
>>
>
> The ticket mentions automatic fallback from header -> property. That is not
> available in 1.6.x as far as I know. That would solve half of the
> workaround.
The fallback is when you use the DSL, eg .header("foo") and not when
you do a getHeader directly on the exchange/message.

>
> It is a possibility to use header OR property for aggregation? That would
> not really break existing implementations because the whole camel namespace
> is used in the property.
Good idea. We can add the information in both header (as now) and
properties (new) in 1.6.2.
This will not break anything.

>
> The current splitter / aggregation implementation is really fragile without
> good knowleds of camel 1.6.x
The splitter has build in aggregator so often you just let the
splitter alone deal with it.
See the request/reply splitter sample on the splitter wiki page. Then
you do not have
to worry about split index and split total etc.


If you would like to contribute a patch for 1.6.2. Then I suggest to
find an unit test that uses splitter
and tests with the SPLIT_INDEX headers. Then take a copy of this class
and do a test where
you use properties instead. And then look in the Splitter (in the
processor) to find where to add
the properties as well.


>
> Regards,
> Erwin
> --
> View this message in context: http://www.nabble.com/Custom-AggregationStrategy-needs-specific-headers-tp23996092p24000219.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

Re: Custom AggregationStrategy needs specific headers

Posted by ErwinK <er...@gmail.com>.

Claus Ibsen-2 wrote:
> 
> Hi
> 
> I have created a ticket to track this issue
> https://issues.apache.org/activemq/browse/CAMEL-1702
> 
> We will *only* do this migration at Camel 2.0 to keep the old behavior
> in Camel 1.6.x as this branch is maintenance and for important bug
> fixes only.
> Its intended for drop in replacements for production usage and this we
> cannot change such behavior. Even if it would make life easier.
> 
> 
> 

The ticket mentions automatic fallback from header -> property. That is not
available in 1.6.x as far as I know. That would solve half of the
workaround. 

It is a possibility to use header OR property for aggregation? That would
not really break existing implementations because the whole camel namespace
is used in the property.

The current splitter / aggregation implementation is really fragile without
good knowleds of camel 1.6.x

Regards,
Erwin
-- 
View this message in context: http://www.nabble.com/Custom-AggregationStrategy-needs-specific-headers-tp23996092p24000219.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Custom AggregationStrategy needs specific headers

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I have created a ticket to track this issue
https://issues.apache.org/activemq/browse/CAMEL-1702

We will *only* do this migration at Camel 2.0 to keep the old behavior
in Camel 1.6.x as this branch is maintenance and for important bug
fixes only.
Its intended for drop in replacements for production usage and this we
cannot change such behavior. Even if it would make life easier.




On Fri, Jun 12, 2009 at 1:00 PM, ErwinK<er...@gmail.com> wrote:
>
>
>
> Claus Ibsen-2 wrote:
>>
>> On Fri, Jun 12, 2009 at 12:07 PM, ErwinK<er...@gmail.com> wrote:
>>>
>>> Hello,
>>>
>>> I am using Camel 1.6.1. With the following route:
>>>
>>> from("timer://timer?period=1000")
>>> .setBody(constant("select * from table"))
>>> .to("jdbc:db")
>>> .splitter(body(List.class), new MyAggregationStrategy())
>>> .to("some default component uri that doesn't forward headers")
>>> .end()
>>> .to("log:log")
>>>
>>> The aggregationstrategy needs org.apache.camel.SplitIndex and
>>> org.apache.camel.SplitSize but you lose them during the route in the
>>> splitter part.
>>>
>>> I can work around the problem by saving the headers in an exchange
>>> property
>>> as first step and restore them just before the aggregation, but shouldn't
>>> the splitter itself store necessary information in a property?
>> Hi
>>
>> The aggregation strategy interface is a bit low-level as you work
>> directly on the Exchange object.
>> Doing this you have to be a bit careful whether you set the aggregated
>> response on OUT or IN.
>>
>> If you set it on OUT and you do not copy headers from IN then they are
>> lost.
>>
>> But you are right we could build in failsafe in Camel to safe the headers.
>> But another solution would be to use exchange properties instead of
>> headers, then they are newer lost.
>>
>> I have been wondering if we should migrate Camel 2.0 to use properties
>> for such thinks as splitter indes, aggregator index, and what else
>> Camel decorate an exchange with. It kinda belong there in the first place.
>>
>>
>>
>>
>>>
>>> Regards,
>>> Erwin
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Custom-AggregationStrategy-needs-specific-headers-tp23996092p23996092.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
>>
>>
>
> The problem in this case is that I don't really mind to lose my own headers
> when using a default component, but that the headers set by the splitter are
> needed in the end for the aggregation. So that means that when you use
> default components, you have to write some extra code that ensures that the
> headers are still (or again) there just before the aggregation, otherwise it
> will just not work.
>
> I think it should definitly be addressed in 2.0, but if it is not to hard,
> also in 1.6.x. If there is a ticket I can see if I can send a patch.
>
> Regards,
> Erwin
>
> --
> View this message in context: http://www.nabble.com/Custom-AggregationStrategy-needs-specific-headers-tp23996092p23996797.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

Re: Custom AggregationStrategy needs specific headers

Posted by ErwinK <er...@gmail.com>.


Claus Ibsen-2 wrote:
> 
> On Fri, Jun 12, 2009 at 12:07 PM, ErwinK<er...@gmail.com> wrote:
>>
>> Hello,
>>
>> I am using Camel 1.6.1. With the following route:
>>
>> from("timer://timer?period=1000")
>> .setBody(constant("select * from table"))
>> .to("jdbc:db")
>> .splitter(body(List.class), new MyAggregationStrategy())
>> .to("some default component uri that doesn't forward headers")
>> .end()
>> .to("log:log")
>>
>> The aggregationstrategy needs org.apache.camel.SplitIndex and
>> org.apache.camel.SplitSize but you lose them during the route in the
>> splitter part.
>>
>> I can work around the problem by saving the headers in an exchange
>> property
>> as first step and restore them just before the aggregation, but shouldn't
>> the splitter itself store necessary information in a property?
> Hi
> 
> The aggregation strategy interface is a bit low-level as you work
> directly on the Exchange object.
> Doing this you have to be a bit careful whether you set the aggregated
> response on OUT or IN.
> 
> If you set it on OUT and you do not copy headers from IN then they are
> lost.
> 
> But you are right we could build in failsafe in Camel to safe the headers.
> But another solution would be to use exchange properties instead of
> headers, then they are newer lost.
> 
> I have been wondering if we should migrate Camel 2.0 to use properties
> for such thinks as splitter indes, aggregator index, and what else
> Camel decorate an exchange with. It kinda belong there in the first place.
> 
> 
> 
> 
>>
>> Regards,
>> Erwin
>> --
>> View this message in context:
>> http://www.nabble.com/Custom-AggregationStrategy-needs-specific-headers-tp23996092p23996092.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
> 
> 

The problem in this case is that I don't really mind to lose my own headers
when using a default component, but that the headers set by the splitter are
needed in the end for the aggregation. So that means that when you use
default components, you have to write some extra code that ensures that the
headers are still (or again) there just before the aggregation, otherwise it
will just not work.

I think it should definitly be addressed in 2.0, but if it is not to hard,
also in 1.6.x. If there is a ticket I can see if I can send a patch.

Regards,
Erwin

-- 
View this message in context: http://www.nabble.com/Custom-AggregationStrategy-needs-specific-headers-tp23996092p23996797.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Custom AggregationStrategy needs specific headers

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Jun 12, 2009 at 12:07 PM, ErwinK<er...@gmail.com> wrote:
>
> Hello,
>
> I am using Camel 1.6.1. With the following route:
>
> from("timer://timer?period=1000")
> .setBody(constant("select * from table"))
> .to("jdbc:db")
> .splitter(body(List.class), new MyAggregationStrategy())
> .to("some default component uri that doesn't forward headers")
> .end()
> .to("log:log")
>
> The aggregationstrategy needs org.apache.camel.SplitIndex and
> org.apache.camel.SplitSize but you lose them during the route in the
> splitter part.
>
> I can work around the problem by saving the headers in an exchange property
> as first step and restore them just before the aggregation, but shouldn't
> the splitter itself store necessary information in a property?
Hi

The aggregation strategy interface is a bit low-level as you work
directly on the Exchange object.
Doing this you have to be a bit careful whether you set the aggregated
response on OUT or IN.

If you set it on OUT and you do not copy headers from IN then they are lost.

But you are right we could build in failsafe in Camel to safe the headers.
But another solution would be to use exchange properties instead of
headers, then they are newer lost.

I have been wondering if we should migrate Camel 2.0 to use properties
for such thinks as splitter indes, aggregator index, and what else
Camel decorate an exchange with. It kinda belong there in the first place.




>
> Regards,
> Erwin
> --
> View this message in context: http://www.nabble.com/Custom-AggregationStrategy-needs-specific-headers-tp23996092p23996092.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