You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Johan Haleby <jo...@gmail.com> on 2010/02/16 14:53:07 UTC

NotifyBuilder "intercept" support

Hi,

I've just upgraded to Camel 2.2 since I'd like to use the new NotifyBuilder
in my test class. How ever it doesn't really seem to fit my use case 100%.
What I'm missing is interception or "side-effect" support. In my test case
I'd like to extract an ID that's located in the message body and store it
away temporarily (for synchronization purposes). This means that I don't
need any matching, I just want to perform some operation for each message
that arrives to an endpoint. As a work-around I've created a Predicate that
does exactly this which is defined by:

notifyBuilder.from(outboundEnpoint).filter(extractId()).create(); //
extractId returns the Predicate impl

I figure it would have been better to add e.g. a "filter(Interceptor
interceptor)" method to NotifyBuilder which contains a method like "void
intercept(Exchange exchange)".

Also I've noticed that the "extractId" predicate instance is called twice
for each message. I suppose that's because it gets called once for
"ExchangeCreatedEvent" and once for the "ExchangeCompletedEvent". So I would
also like tge ability to e.g. only filter "ExchangeCompletedEvent" events.
In my case something like:

notifyBuilder.from(outboundEnpoint).filter(extractIdInterceptor()).onExchangeCompletedEvent().create();

Or is there another way to achieve what I'm looking for?

Thanks,
/Johan
-- 
View this message in context: http://old.nabble.com/NotifyBuilder-%22intercept%22-support-tp27608556p27608556.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: NotifyBuilder "intercept" support

Posted by Johan Haleby <jo...@gmail.com>.
Hi,

whenAnyReceivedMatches/whenAnyDoneMatches was indeed what I was looking for,
wasn't aware that they corresponded to the two events. This works very well
as a work-around for me. The only thing is that in my case I wouldn't
actually need a Predicate since my implementation(s) always returns true.

I can see that the channel support would probably be really useful in more
complex scenarios where you would need to hook into places other than start
or end of the exchange. Good thing to have for testing purposes.

Thanks again,
/Johan



Claus Ibsen-2 wrote:
> 
> Hi
> 
> On Tue, Feb 16, 2010 at 2:53 PM, Johan Haleby <jo...@gmail.com>
> wrote:
>>
>> Hi,
>>
>> I've just upgraded to Camel 2.2 since I'd like to use the new
>> NotifyBuilder
>> in my test class. How ever it doesn't really seem to fit my use case
>> 100%.
>> What I'm missing is interception or "side-effect" support. In my test
>> case
>> I'd like to extract an ID that's located in the message body and store it
>> away temporarily (for synchronization purposes). This means that I don't
>> need any matching, I just want to perform some operation for each message
>> that arrives to an endpoint. As a work-around I've created a Predicate
>> that
>> does exactly this which is defined by:
>>
>> notifyBuilder.from(outboundEnpoint).filter(extractId()).create(); //
>> extractId returns the Predicate impl
>>
>> I figure it would have been better to add e.g. a "filter(Interceptor
>> interceptor)" method to NotifyBuilder which contains a method like "void
>> intercept(Exchange exchange)".
>>
> 
> The problem is the notify builder is based on the EventNotifier which
> *only* have a starting and ending event
> for a given Exchange. So if you want to intercept every step the
> Exchange does, then that is not possible.
> 
> However in the future I would like to make that more easily possible.
> We got the foundation in place in the 2.0 line.
> There is a org.apache.camel.Channel concept, which acts as a delegate
> between each node an Exchange undergoes.
> 
> The Channel is currently a bit too static how it delegates, but in the
> future we will make that much more dynamic so you can
> add interceptors and whatnot more easily on the fly, without the need
> for a RouteBuilder.
> 
> 
>> Also I've noticed that the "extractId" predicate instance is called twice
>> for each message. I suppose that's because it gets called once for
>> "ExchangeCreatedEvent" and once for the "ExchangeCompletedEvent". So I
>> would
>> also like tge ability to e.g. only filter "ExchangeCompletedEvent"
>> events.
>> In my case something like:
>>
>> notifyBuilder.from(outboundEnpoint).filter(extractIdInterceptor()).onExchangeCompletedEvent().create();
>>
>> Or is there another way to achieve what I'm looking for?
>>
> 
> Maybe something like should do what you want:
> 
> notifyBuilder.from(outboundEnpoint).whenAnyReceivedMatches(extractId()).create();
> 
> 
> 
>> Thanks,
>> /Johan
>> --
>> View this message in context:
>> http://old.nabble.com/NotifyBuilder-%22intercept%22-support-tp27608556p27608556.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> Claus Ibsen
> Apache Camel Committer
> 
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
> 
> 

-- 
View this message in context: http://old.nabble.com/NotifyBuilder-%22intercept%22-support-tp27608556p27636641.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: NotifyBuilder "intercept" support

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

On Tue, Feb 16, 2010 at 2:53 PM, Johan Haleby <jo...@gmail.com> wrote:
>
> Hi,
>
> I've just upgraded to Camel 2.2 since I'd like to use the new NotifyBuilder
> in my test class. How ever it doesn't really seem to fit my use case 100%.
> What I'm missing is interception or "side-effect" support. In my test case
> I'd like to extract an ID that's located in the message body and store it
> away temporarily (for synchronization purposes). This means that I don't
> need any matching, I just want to perform some operation for each message
> that arrives to an endpoint. As a work-around I've created a Predicate that
> does exactly this which is defined by:
>
> notifyBuilder.from(outboundEnpoint).filter(extractId()).create(); //
> extractId returns the Predicate impl
>
> I figure it would have been better to add e.g. a "filter(Interceptor
> interceptor)" method to NotifyBuilder which contains a method like "void
> intercept(Exchange exchange)".
>

The problem is the notify builder is based on the EventNotifier which
*only* have a starting and ending event
for a given Exchange. So if you want to intercept every step the
Exchange does, then that is not possible.

However in the future I would like to make that more easily possible.
We got the foundation in place in the 2.0 line.
There is a org.apache.camel.Channel concept, which acts as a delegate
between each node an Exchange undergoes.

The Channel is currently a bit too static how it delegates, but in the
future we will make that much more dynamic so you can
add interceptors and whatnot more easily on the fly, without the need
for a RouteBuilder.


> Also I've noticed that the "extractId" predicate instance is called twice
> for each message. I suppose that's because it gets called once for
> "ExchangeCreatedEvent" and once for the "ExchangeCompletedEvent". So I would
> also like tge ability to e.g. only filter "ExchangeCompletedEvent" events.
> In my case something like:
>
> notifyBuilder.from(outboundEnpoint).filter(extractIdInterceptor()).onExchangeCompletedEvent().create();
>
> Or is there another way to achieve what I'm looking for?
>

Maybe something like should do what you want:

notifyBuilder.from(outboundEnpoint).whenAnyReceivedMatches(extractId()).create();



> Thanks,
> /Johan
> --
> View this message in context: http://old.nabble.com/NotifyBuilder-%22intercept%22-support-tp27608556p27608556.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus