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/01/12 17:56:01 UTC

Intercept a processor?

Hi,

I'm configuring routes using the Java DSL and it works very well. However
during testing I'd like to somehow hook into the end of an already defined
route to add notification support. The reason is that in my test I'm
creating a message and pass it to a queue using Camel and this message is
handled by a processor. After this processor has finished executing I'd like
to receive some sort of notification but only during testing. The reason is
that I'd like my test to wait until the processor has finished executing in
my test case so that I can verify the result of the processor. For example:

public void test() {
  1. send a message to queue // just as you would in production
  2. wait for the processor to finish // this is where I'd like to get a
notification that the processor has finished so that it's ok to continue to
the next step
  3. verify result
}

The route may look something like:
from("jms:queue:myqueue).process(new MyProcessor()); // A simplification of
the production route

Is there a preferred way of doing this in Camel without changing the code
making up the "production route"? Or is there a better way to achieve it?

/Johan

-- 
View this message in context: http://old.nabble.com/Intercept-a-processor--tp27130672p27130672.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Intercept a processor?

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

Ah forgot about the producer template which got methods for callback
when an Exchange is done.

For example this one where onDone is invoked when the Exchange is
done, which allows you to know when its complete and continue your
test.


        final CountDownLatch latch = new CountDownLatch(1);

        template.asyncCallbackSendBody("direct:start", "Hello", new
SynchronizationAdapter() {
            @Override
            public void onDone(Exchange exchange) {
                order += "B";
                assertEquals("Hello World", exchange.getIn().getBody());
                latch.countDown();
            }
        });

        order += "A";
        latch.await(10, TimeUnit.SECONDS);
        order += "C";



On Tue, Jan 12, 2010 at 5:56 PM, Johan Haleby <jo...@gmail.com> wrote:
>
> Hi,
>
> I'm configuring routes using the Java DSL and it works very well. However
> during testing I'd like to somehow hook into the end of an already defined
> route to add notification support. The reason is that in my test I'm
> creating a message and pass it to a queue using Camel and this message is
> handled by a processor. After this processor has finished executing I'd like
> to receive some sort of notification but only during testing. The reason is
> that I'd like my test to wait until the processor has finished executing in
> my test case so that I can verify the result of the processor. For example:
>
> public void test() {
>  1. send a message to queue // just as you would in production
>  2. wait for the processor to finish // this is where I'd like to get a
> notification that the processor has finished so that it's ok to continue to
> the next step
>  3. verify result
> }
>
> The route may look something like:
> from("jms:queue:myqueue).process(new MyProcessor()); // A simplification of
> the production route
>
> Is there a preferred way of doing this in Camel without changing the code
> making up the "production route"? Or is there a better way to achieve it?
>
> /Johan
>
> --
> View this message in context: http://old.nabble.com/Intercept-a-processor--tp27130672p27130672.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

Re: Intercept a processor?

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Jan 12, 2010 at 7:06 PM, Johan Haleby <jo...@gmail.com> wrote:
>
> Hi,
>
> Thanks for your quick response. Sorry for not mentioning it in the previous
> mail but I'm using Camel 2.1 just as you suspected. Unfortunately the first
> solution you posted (using async send and latches) won't work "out of the
> box" for me because the producer template is wrapped in an anti-corruption
> layer and the test should use this anti-corruption layer to send the
> message.
>
> I'll look into your suggestion by subscribing to the ExchangeDoneEvent. Is
> there anywhere I can find some documentation or example of how to do this?
> Or was it this that you went through in chapter 6 in the book?
>

EventNotifer is not document to well currently as its not a very
elaborate feature in 2.1
However as always use the search box on the Camel front page to find
links with info.

Basically just set your own EventNotifer on the
contxt.getManagementStrategy().setEventNotifier(myNotifier);
which you can do from the unit test.

If using Spring XML then just declare a <bean> in Spring XML with your
custom EventNotifier then Camel will automatic pick it up and use it.

> I look forward to the changes you mention in version 2.2, seems really
> useful and looks to fit very well with what I'm trying to do here. Is there
> an expected date when 2.2 may be available?
>

I do think we should get a release out in start of Feb. But this is
open source and community driven so time schedules can drift.


> Regards,
> /Johan
>
> The first option won't work
>
> Claus Ibsen-2 wrote:
>>
>> On Tue, Jan 12, 2010 at 5:56 PM, Johan Haleby <jo...@gmail.com>
>> wrote:
>>>
>>> Hi,
>>>
>>> I'm configuring routes using the Java DSL and it works very well. However
>>> during testing I'd like to somehow hook into the end of an already
>>> defined
>>> route to add notification support. The reason is that in my test I'm
>>> creating a message and pass it to a queue using Camel and this message is
>>> handled by a processor. After this processor has finished executing I'd
>>> like
>>> to receive some sort of notification but only during testing. The reason
>>> is
>>> that I'd like my test to wait until the processor has finished executing
>>> in
>>> my test case so that I can verify the result of the processor. For
>>> example:
>>>
>>> public void test() {
>>>  1. send a message to queue // just as you would in production
>>>  2. wait for the processor to finish // this is where I'd like to get a
>>> notification that the processor has finished so that it's ok to continue
>>> to
>>> the next step
>>>  3. verify result
>>> }
>>>
>>> The route may look something like:
>>> from("jms:queue:myqueue).process(new MyProcessor()); // A simplification
>>> of
>>> the production route
>>>
>>> Is there a preferred way of doing this in Camel without changing the code
>>> making up the "production route"? Or is there a better way to achieve it?
>>>
>>
>> Chapter 6 in the book go over this issue and how to address that:
>> http://www.manning.com/ibsen/ (will be updated in next MEAP due this
>> month)
>>
>> However we made it easier to do nice and easy from an unit test in 2.2
>> which I assume is not the version of Camel you are using.
>> In 2.2 you can advice and route by adding additional cross cutting
>> concerns such as onCompletion, interceptors etc. which you would then
>> be able to use to know when its done.
>>
>> In Camel 2.1 you got the EventNotification which you actually can use
>> for that to get notified when an Exchange is done as it emits a
>> ExchangeDoneEvent.
>> I am currently improving that for 2.2 to let you filter out of the box
>> the notifier so you only receive interesting events. But that should
>> not hold you back from using that in 2.1.
>>
>> We may improve this situation even more to make it easy as it can get
>> for testing production routes with test methods. So kinda inject mocks
>> at end of routes etc. so you can use that to verify behavior etc.
>>
>>
>>> /Johan
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Intercept-a-processor--tp27130672p27130672.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/Intercept-a-processor--tp27130672p27131142.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

Re: Intercept a processor?

Posted by Johan Haleby <jo...@gmail.com>.
Thanks!

It would be great to have some filtering functionality as well. I've added
an example as a comment on the blog.

Regards,
/Johan


Claus Ibsen-2 wrote:
> 
> Hi
> 
> I posted a blog entry about the new feature in 2.2
> http://davsclaus.blogspot.com/2010/01/apache-camel-22-improved-test-kit.html
> 
> 
> 
> On Wed, Jan 13, 2010 at 8:14 PM, Johan Haleby <jo...@gmail.com>
> wrote:
>>
>> That looks really neat and would as far as I can see really help. It
>> would be
>> simple for me to wrap this in a test base class exposing something like
>> "awaitCompletion("direct:foo")".
>>
>> Would be desirable/possible to have something similar to modify or extend
>> an
>> already defined route? Something like:
>> RouteModificationBuilder builder = new
>> RouteModificationBuilder(camelContext);
>> builder.from("direct:foo").append(new Processor(..)).apply();
>>
>> Or can you do this already?
>>
>> Thanks,
>> /Johan
>>
>>
>> Claus Ibsen-2 wrote:
>>>
>>> Hi
>>>
>>> I think CAMEL-2357 is what you are looking for
>>> https://issues.apache.org/activemq/browse/CAMEL-2357
>>>
>>> If you could take a look and maybe if you got some ideas or how you
>>> would like the API to be to support your use-case.
>>> There are some code snippets of my prototype in there.
>>>
>>>
>>> On Wed, Jan 13, 2010 at 9:11 AM, Johan Haleby <jo...@gmail.com>
>>> wrote:
>>>>
>>>> Hi,
>>>>
>>>> Thank you very much your suggestion with event notifiers worked! But I
>>>> hope
>>>> the changes in 2.2 can make it even better since now the
>>>> ExchangeCompletedEvent is sent several times (once per "from" in the
>>>> route
>>>> definition") and thus it's hard to know the count in the latch when
>>>> you're
>>>> not sure to which endpoint the users sends the first message.
>>>>
>>>> Would you recommend using a snapshot of version 2.2 right now? (We'd
>>>> also
>>>> like to use Spring 3 in our project).
>>>>
>>>> /Johan
>>>>
>>>>
>>>> Johan Haleby wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> Thanks for your quick response. Sorry for not mentioning it in the
>>>>> previous mail but I'm using Camel 2.1 just as you suspected.
>>>>> Unfortunately
>>>>> the first solution you posted (using async send and latches) won't
>>>>> work
>>>>> "out of the box" for me because the producer template is wrapped in an
>>>>> anti-corruption layer and the test should use this anti-corruption
>>>>> layer
>>>>> to send the message.
>>>>>
>>>>> I'll look into your suggestion by subscribing to the
>>>>> ExchangeDoneEvent.
>>>>> Is
>>>>> there anywhere I can find some documentation or example of how to do
>>>>> this?
>>>>> Or was it this that you went through in chapter 6 in the book?
>>>>>
>>>>> I look forward to the changes you mention in version 2.2, seems really
>>>>> useful and looks to fit very well with what I'm trying to do here. Is
>>>>> there an expected date when 2.2 may be available?
>>>>>
>>>>> Regards,
>>>>> /Johan
>>>>>
>>>>> The first option won't work
>>>>>
>>>>> Claus Ibsen-2 wrote:
>>>>>>
>>>>>> On Tue, Jan 12, 2010 at 5:56 PM, Johan Haleby
>>>>>> <jo...@gmail.com>
>>>>>> wrote:
>>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> I'm configuring routes using the Java DSL and it works very well.
>>>>>>> However
>>>>>>> during testing I'd like to somehow hook into the end of an already
>>>>>>> defined
>>>>>>> route to add notification support. The reason is that in my test I'm
>>>>>>> creating a message and pass it to a queue using Camel and this
>>>>>>> message
>>>>>>> is
>>>>>>> handled by a processor. After this processor has finished executing
>>>>>>> I'd
>>>>>>> like
>>>>>>> to receive some sort of notification but only during testing. The
>>>>>>> reason
>>>>>>> is
>>>>>>> that I'd like my test to wait until the processor has finished
>>>>>>> executing
>>>>>>> in
>>>>>>> my test case so that I can verify the result of the processor. For
>>>>>>> example:
>>>>>>>
>>>>>>> public void test() {
>>>>>>>  1. send a message to queue // just as you would in production
>>>>>>>  2. wait for the processor to finish // this is where I'd like to
>>>>>>> get
>>>>>>> a
>>>>>>> notification that the processor has finished so that it's ok to
>>>>>>> continue
>>>>>>> to
>>>>>>> the next step
>>>>>>>  3. verify result
>>>>>>> }
>>>>>>>
>>>>>>> The route may look something like:
>>>>>>> from("jms:queue:myqueue).process(new MyProcessor()); // A
>>>>>>> simplification
>>>>>>> of
>>>>>>> the production route
>>>>>>>
>>>>>>> Is there a preferred way of doing this in Camel without changing the
>>>>>>> code
>>>>>>> making up the "production route"? Or is there a better way to
>>>>>>> achieve
>>>>>>> it?
>>>>>>>
>>>>>>
>>>>>> Chapter 6 in the book go over this issue and how to address that:
>>>>>> http://www.manning.com/ibsen/ (will be updated in next MEAP due this
>>>>>> month)
>>>>>>
>>>>>> However we made it easier to do nice and easy from an unit test in
>>>>>> 2.2
>>>>>> which I assume is not the version of Camel you are using.
>>>>>> In 2.2 you can advice and route by adding additional cross cutting
>>>>>> concerns such as onCompletion, interceptors etc. which you would then
>>>>>> be able to use to know when its done.
>>>>>>
>>>>>> In Camel 2.1 you got the EventNotification which you actually can use
>>>>>> for that to get notified when an Exchange is done as it emits a
>>>>>> ExchangeDoneEvent.
>>>>>> I am currently improving that for 2.2 to let you filter out of the
>>>>>> box
>>>>>> the notifier so you only receive interesting events. But that should
>>>>>> not hold you back from using that in 2.1.
>>>>>>
>>>>>> We may improve this situation even more to make it easy as it can get
>>>>>> for testing production routes with test methods. So kinda inject
>>>>>> mocks
>>>>>> at end of routes etc. so you can use that to verify behavior etc.
>>>>>>
>>>>>>
>>>>>>> /Johan
>>>>>>>
>>>>>>> --
>>>>>>> View this message in context:
>>>>>>> http://old.nabble.com/Intercept-a-processor--tp27130672p27130672.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/Intercept-a-processor--tp27130672p27140999.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/Intercept-a-processor--tp27130672p27148815.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/Intercept-a-processor--tp27130672p27173286.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Intercept a processor?

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

I posted a blog entry about the new feature in 2.2
http://davsclaus.blogspot.com/2010/01/apache-camel-22-improved-test-kit.html



On Wed, Jan 13, 2010 at 8:14 PM, Johan Haleby <jo...@gmail.com> wrote:
>
> That looks really neat and would as far as I can see really help. It would be
> simple for me to wrap this in a test base class exposing something like
> "awaitCompletion("direct:foo")".
>
> Would be desirable/possible to have something similar to modify or extend an
> already defined route? Something like:
> RouteModificationBuilder builder = new
> RouteModificationBuilder(camelContext);
> builder.from("direct:foo").append(new Processor(..)).apply();
>
> Or can you do this already?
>
> Thanks,
> /Johan
>
>
> Claus Ibsen-2 wrote:
>>
>> Hi
>>
>> I think CAMEL-2357 is what you are looking for
>> https://issues.apache.org/activemq/browse/CAMEL-2357
>>
>> If you could take a look and maybe if you got some ideas or how you
>> would like the API to be to support your use-case.
>> There are some code snippets of my prototype in there.
>>
>>
>> On Wed, Jan 13, 2010 at 9:11 AM, Johan Haleby <jo...@gmail.com>
>> wrote:
>>>
>>> Hi,
>>>
>>> Thank you very much your suggestion with event notifiers worked! But I
>>> hope
>>> the changes in 2.2 can make it even better since now the
>>> ExchangeCompletedEvent is sent several times (once per "from" in the
>>> route
>>> definition") and thus it's hard to know the count in the latch when
>>> you're
>>> not sure to which endpoint the users sends the first message.
>>>
>>> Would you recommend using a snapshot of version 2.2 right now? (We'd also
>>> like to use Spring 3 in our project).
>>>
>>> /Johan
>>>
>>>
>>> Johan Haleby wrote:
>>>>
>>>> Hi,
>>>>
>>>> Thanks for your quick response. Sorry for not mentioning it in the
>>>> previous mail but I'm using Camel 2.1 just as you suspected.
>>>> Unfortunately
>>>> the first solution you posted (using async send and latches) won't work
>>>> "out of the box" for me because the producer template is wrapped in an
>>>> anti-corruption layer and the test should use this anti-corruption layer
>>>> to send the message.
>>>>
>>>> I'll look into your suggestion by subscribing to the ExchangeDoneEvent.
>>>> Is
>>>> there anywhere I can find some documentation or example of how to do
>>>> this?
>>>> Or was it this that you went through in chapter 6 in the book?
>>>>
>>>> I look forward to the changes you mention in version 2.2, seems really
>>>> useful and looks to fit very well with what I'm trying to do here. Is
>>>> there an expected date when 2.2 may be available?
>>>>
>>>> Regards,
>>>> /Johan
>>>>
>>>> The first option won't work
>>>>
>>>> Claus Ibsen-2 wrote:
>>>>>
>>>>> On Tue, Jan 12, 2010 at 5:56 PM, Johan Haleby <jo...@gmail.com>
>>>>> wrote:
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I'm configuring routes using the Java DSL and it works very well.
>>>>>> However
>>>>>> during testing I'd like to somehow hook into the end of an already
>>>>>> defined
>>>>>> route to add notification support. The reason is that in my test I'm
>>>>>> creating a message and pass it to a queue using Camel and this message
>>>>>> is
>>>>>> handled by a processor. After this processor has finished executing
>>>>>> I'd
>>>>>> like
>>>>>> to receive some sort of notification but only during testing. The
>>>>>> reason
>>>>>> is
>>>>>> that I'd like my test to wait until the processor has finished
>>>>>> executing
>>>>>> in
>>>>>> my test case so that I can verify the result of the processor. For
>>>>>> example:
>>>>>>
>>>>>> public void test() {
>>>>>>  1. send a message to queue // just as you would in production
>>>>>>  2. wait for the processor to finish // this is where I'd like to get
>>>>>> a
>>>>>> notification that the processor has finished so that it's ok to
>>>>>> continue
>>>>>> to
>>>>>> the next step
>>>>>>  3. verify result
>>>>>> }
>>>>>>
>>>>>> The route may look something like:
>>>>>> from("jms:queue:myqueue).process(new MyProcessor()); // A
>>>>>> simplification
>>>>>> of
>>>>>> the production route
>>>>>>
>>>>>> Is there a preferred way of doing this in Camel without changing the
>>>>>> code
>>>>>> making up the "production route"? Or is there a better way to achieve
>>>>>> it?
>>>>>>
>>>>>
>>>>> Chapter 6 in the book go over this issue and how to address that:
>>>>> http://www.manning.com/ibsen/ (will be updated in next MEAP due this
>>>>> month)
>>>>>
>>>>> However we made it easier to do nice and easy from an unit test in 2.2
>>>>> which I assume is not the version of Camel you are using.
>>>>> In 2.2 you can advice and route by adding additional cross cutting
>>>>> concerns such as onCompletion, interceptors etc. which you would then
>>>>> be able to use to know when its done.
>>>>>
>>>>> In Camel 2.1 you got the EventNotification which you actually can use
>>>>> for that to get notified when an Exchange is done as it emits a
>>>>> ExchangeDoneEvent.
>>>>> I am currently improving that for 2.2 to let you filter out of the box
>>>>> the notifier so you only receive interesting events. But that should
>>>>> not hold you back from using that in 2.1.
>>>>>
>>>>> We may improve this situation even more to make it easy as it can get
>>>>> for testing production routes with test methods. So kinda inject mocks
>>>>> at end of routes etc. so you can use that to verify behavior etc.
>>>>>
>>>>>
>>>>>> /Johan
>>>>>>
>>>>>> --
>>>>>> View this message in context:
>>>>>> http://old.nabble.com/Intercept-a-processor--tp27130672p27130672.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/Intercept-a-processor--tp27130672p27140999.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/Intercept-a-processor--tp27130672p27148815.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

Re: Intercept a processor?

Posted by Johan Haleby <jo...@gmail.com>.
That looks really neat and would as far as I can see really help. It would be
simple for me to wrap this in a test base class exposing something like
"awaitCompletion("direct:foo")". 

Would be desirable/possible to have something similar to modify or extend an
already defined route? Something like: 
RouteModificationBuilder builder = new
RouteModificationBuilder(camelContext);
builder.from("direct:foo").append(new Processor(..)).apply();

Or can you do this already?

Thanks,
/Johan


Claus Ibsen-2 wrote:
> 
> Hi
> 
> I think CAMEL-2357 is what you are looking for
> https://issues.apache.org/activemq/browse/CAMEL-2357
> 
> If you could take a look and maybe if you got some ideas or how you
> would like the API to be to support your use-case.
> There are some code snippets of my prototype in there.
> 
> 
> On Wed, Jan 13, 2010 at 9:11 AM, Johan Haleby <jo...@gmail.com>
> wrote:
>>
>> Hi,
>>
>> Thank you very much your suggestion with event notifiers worked! But I
>> hope
>> the changes in 2.2 can make it even better since now the
>> ExchangeCompletedEvent is sent several times (once per "from" in the
>> route
>> definition") and thus it's hard to know the count in the latch when
>> you're
>> not sure to which endpoint the users sends the first message.
>>
>> Would you recommend using a snapshot of version 2.2 right now? (We'd also
>> like to use Spring 3 in our project).
>>
>> /Johan
>>
>>
>> Johan Haleby wrote:
>>>
>>> Hi,
>>>
>>> Thanks for your quick response. Sorry for not mentioning it in the
>>> previous mail but I'm using Camel 2.1 just as you suspected.
>>> Unfortunately
>>> the first solution you posted (using async send and latches) won't work
>>> "out of the box" for me because the producer template is wrapped in an
>>> anti-corruption layer and the test should use this anti-corruption layer
>>> to send the message.
>>>
>>> I'll look into your suggestion by subscribing to the ExchangeDoneEvent.
>>> Is
>>> there anywhere I can find some documentation or example of how to do
>>> this?
>>> Or was it this that you went through in chapter 6 in the book?
>>>
>>> I look forward to the changes you mention in version 2.2, seems really
>>> useful and looks to fit very well with what I'm trying to do here. Is
>>> there an expected date when 2.2 may be available?
>>>
>>> Regards,
>>> /Johan
>>>
>>> The first option won't work
>>>
>>> Claus Ibsen-2 wrote:
>>>>
>>>> On Tue, Jan 12, 2010 at 5:56 PM, Johan Haleby <jo...@gmail.com>
>>>> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I'm configuring routes using the Java DSL and it works very well.
>>>>> However
>>>>> during testing I'd like to somehow hook into the end of an already
>>>>> defined
>>>>> route to add notification support. The reason is that in my test I'm
>>>>> creating a message and pass it to a queue using Camel and this message
>>>>> is
>>>>> handled by a processor. After this processor has finished executing
>>>>> I'd
>>>>> like
>>>>> to receive some sort of notification but only during testing. The
>>>>> reason
>>>>> is
>>>>> that I'd like my test to wait until the processor has finished
>>>>> executing
>>>>> in
>>>>> my test case so that I can verify the result of the processor. For
>>>>> example:
>>>>>
>>>>> public void test() {
>>>>>  1. send a message to queue // just as you would in production
>>>>>  2. wait for the processor to finish // this is where I'd like to get
>>>>> a
>>>>> notification that the processor has finished so that it's ok to
>>>>> continue
>>>>> to
>>>>> the next step
>>>>>  3. verify result
>>>>> }
>>>>>
>>>>> The route may look something like:
>>>>> from("jms:queue:myqueue).process(new MyProcessor()); // A
>>>>> simplification
>>>>> of
>>>>> the production route
>>>>>
>>>>> Is there a preferred way of doing this in Camel without changing the
>>>>> code
>>>>> making up the "production route"? Or is there a better way to achieve
>>>>> it?
>>>>>
>>>>
>>>> Chapter 6 in the book go over this issue and how to address that:
>>>> http://www.manning.com/ibsen/ (will be updated in next MEAP due this
>>>> month)
>>>>
>>>> However we made it easier to do nice and easy from an unit test in 2.2
>>>> which I assume is not the version of Camel you are using.
>>>> In 2.2 you can advice and route by adding additional cross cutting
>>>> concerns such as onCompletion, interceptors etc. which you would then
>>>> be able to use to know when its done.
>>>>
>>>> In Camel 2.1 you got the EventNotification which you actually can use
>>>> for that to get notified when an Exchange is done as it emits a
>>>> ExchangeDoneEvent.
>>>> I am currently improving that for 2.2 to let you filter out of the box
>>>> the notifier so you only receive interesting events. But that should
>>>> not hold you back from using that in 2.1.
>>>>
>>>> We may improve this situation even more to make it easy as it can get
>>>> for testing production routes with test methods. So kinda inject mocks
>>>> at end of routes etc. so you can use that to verify behavior etc.
>>>>
>>>>
>>>>> /Johan
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>> http://old.nabble.com/Intercept-a-processor--tp27130672p27130672.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/Intercept-a-processor--tp27130672p27140999.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/Intercept-a-processor--tp27130672p27148815.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Intercept a processor?

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

I think CAMEL-2357 is what you are looking for
https://issues.apache.org/activemq/browse/CAMEL-2357

If you could take a look and maybe if you got some ideas or how you
would like the API to be to support your use-case.
There are some code snippets of my prototype in there.


On Wed, Jan 13, 2010 at 9:11 AM, Johan Haleby <jo...@gmail.com> wrote:
>
> Hi,
>
> Thank you very much your suggestion with event notifiers worked! But I hope
> the changes in 2.2 can make it even better since now the
> ExchangeCompletedEvent is sent several times (once per "from" in the route
> definition") and thus it's hard to know the count in the latch when you're
> not sure to which endpoint the users sends the first message.
>
> Would you recommend using a snapshot of version 2.2 right now? (We'd also
> like to use Spring 3 in our project).
>
> /Johan
>
>
> Johan Haleby wrote:
>>
>> Hi,
>>
>> Thanks for your quick response. Sorry for not mentioning it in the
>> previous mail but I'm using Camel 2.1 just as you suspected. Unfortunately
>> the first solution you posted (using async send and latches) won't work
>> "out of the box" for me because the producer template is wrapped in an
>> anti-corruption layer and the test should use this anti-corruption layer
>> to send the message.
>>
>> I'll look into your suggestion by subscribing to the ExchangeDoneEvent. Is
>> there anywhere I can find some documentation or example of how to do this?
>> Or was it this that you went through in chapter 6 in the book?
>>
>> I look forward to the changes you mention in version 2.2, seems really
>> useful and looks to fit very well with what I'm trying to do here. Is
>> there an expected date when 2.2 may be available?
>>
>> Regards,
>> /Johan
>>
>> The first option won't work
>>
>> Claus Ibsen-2 wrote:
>>>
>>> On Tue, Jan 12, 2010 at 5:56 PM, Johan Haleby <jo...@gmail.com>
>>> wrote:
>>>>
>>>> Hi,
>>>>
>>>> I'm configuring routes using the Java DSL and it works very well.
>>>> However
>>>> during testing I'd like to somehow hook into the end of an already
>>>> defined
>>>> route to add notification support. The reason is that in my test I'm
>>>> creating a message and pass it to a queue using Camel and this message
>>>> is
>>>> handled by a processor. After this processor has finished executing I'd
>>>> like
>>>> to receive some sort of notification but only during testing. The reason
>>>> is
>>>> that I'd like my test to wait until the processor has finished executing
>>>> in
>>>> my test case so that I can verify the result of the processor. For
>>>> example:
>>>>
>>>> public void test() {
>>>>  1. send a message to queue // just as you would in production
>>>>  2. wait for the processor to finish // this is where I'd like to get a
>>>> notification that the processor has finished so that it's ok to continue
>>>> to
>>>> the next step
>>>>  3. verify result
>>>> }
>>>>
>>>> The route may look something like:
>>>> from("jms:queue:myqueue).process(new MyProcessor()); // A simplification
>>>> of
>>>> the production route
>>>>
>>>> Is there a preferred way of doing this in Camel without changing the
>>>> code
>>>> making up the "production route"? Or is there a better way to achieve
>>>> it?
>>>>
>>>
>>> Chapter 6 in the book go over this issue and how to address that:
>>> http://www.manning.com/ibsen/ (will be updated in next MEAP due this
>>> month)
>>>
>>> However we made it easier to do nice and easy from an unit test in 2.2
>>> which I assume is not the version of Camel you are using.
>>> In 2.2 you can advice and route by adding additional cross cutting
>>> concerns such as onCompletion, interceptors etc. which you would then
>>> be able to use to know when its done.
>>>
>>> In Camel 2.1 you got the EventNotification which you actually can use
>>> for that to get notified when an Exchange is done as it emits a
>>> ExchangeDoneEvent.
>>> I am currently improving that for 2.2 to let you filter out of the box
>>> the notifier so you only receive interesting events. But that should
>>> not hold you back from using that in 2.1.
>>>
>>> We may improve this situation even more to make it easy as it can get
>>> for testing production routes with test methods. So kinda inject mocks
>>> at end of routes etc. so you can use that to verify behavior etc.
>>>
>>>
>>>> /Johan
>>>>
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/Intercept-a-processor--tp27130672p27130672.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/Intercept-a-processor--tp27130672p27140999.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

Re: Intercept a processor?

Posted by Willem Jiang <wi...@gmail.com>.
Johan Haleby wrote:
> Hi,
> 
> Thank you very much your suggestion with event notifiers worked! But I hope
> the changes in 2.2 can make it even better since now the
> ExchangeCompletedEvent is sent several times (once per "from" in the route
> definition") and thus it's hard to know the count in the latch when you're
> not sure to which endpoint the users sends the first message. 
> 
> Would you recommend using a snapshot of version 2.2 right now? (We'd also
> like to use Spring 3 in our project).

For most camel case, you can upgrade to Spring from 2.5.6 to 3.0.0 
without change anything.
If you are using camel-jms or some advance feature of camel-spring, you 
may meet some minor issue.

In Camel 2.2-SNAPSHOT, you can build camel with the profile "spring-3.x" 
  which will replace the spring version from default 2.5.6 to 
3.0.0.RELEASE, and run the test with Spring 3.0.0.

> 
> /Johan
> 
> 
> Johan Haleby wrote:
>> Hi,
>>
>> Thanks for your quick response. Sorry for not mentioning it in the
>> previous mail but I'm using Camel 2.1 just as you suspected. Unfortunately
>> the first solution you posted (using async send and latches) won't work
>> "out of the box" for me because the producer template is wrapped in an
>> anti-corruption layer and the test should use this anti-corruption layer
>> to send the message.
>>
>> I'll look into your suggestion by subscribing to the ExchangeDoneEvent. Is
>> there anywhere I can find some documentation or example of how to do this?
>> Or was it this that you went through in chapter 6 in the book?
>>
>> I look forward to the changes you mention in version 2.2, seems really
>> useful and looks to fit very well with what I'm trying to do here. Is
>> there an expected date when 2.2 may be available?
>>
>> Regards,
>> /Johan
>>
>> The first option won't work 
>>
>> Claus Ibsen-2 wrote:
>>> On Tue, Jan 12, 2010 at 5:56 PM, Johan Haleby <jo...@gmail.com>
>>> wrote:
>>>> Hi,
>>>>
>>>> I'm configuring routes using the Java DSL and it works very well.
>>>> However
>>>> during testing I'd like to somehow hook into the end of an already
>>>> defined
>>>> route to add notification support. The reason is that in my test I'm
>>>> creating a message and pass it to a queue using Camel and this message
>>>> is
>>>> handled by a processor. After this processor has finished executing I'd
>>>> like
>>>> to receive some sort of notification but only during testing. The reason
>>>> is
>>>> that I'd like my test to wait until the processor has finished executing
>>>> in
>>>> my test case so that I can verify the result of the processor. For
>>>> example:
>>>>
>>>> public void test() {
>>>>  1. send a message to queue // just as you would in production
>>>>  2. wait for the processor to finish // this is where I'd like to get a
>>>> notification that the processor has finished so that it's ok to continue
>>>> to
>>>> the next step
>>>>  3. verify result
>>>> }
>>>>
>>>> The route may look something like:
>>>> from("jms:queue:myqueue).process(new MyProcessor()); // A simplification
>>>> of
>>>> the production route
>>>>
>>>> Is there a preferred way of doing this in Camel without changing the
>>>> code
>>>> making up the "production route"? Or is there a better way to achieve
>>>> it?
>>>>
>>> Chapter 6 in the book go over this issue and how to address that:
>>> http://www.manning.com/ibsen/ (will be updated in next MEAP due this
>>> month)
>>>
>>> However we made it easier to do nice and easy from an unit test in 2.2
>>> which I assume is not the version of Camel you are using.
>>> In 2.2 you can advice and route by adding additional cross cutting
>>> concerns such as onCompletion, interceptors etc. which you would then
>>> be able to use to know when its done.
>>>
>>> In Camel 2.1 you got the EventNotification which you actually can use
>>> for that to get notified when an Exchange is done as it emits a
>>> ExchangeDoneEvent.
>>> I am currently improving that for 2.2 to let you filter out of the box
>>> the notifier so you only receive interesting events. But that should
>>> not hold you back from using that in 2.1.
>>>
>>> We may improve this situation even more to make it easy as it can get
>>> for testing production routes with test methods. So kinda inject mocks
>>> at end of routes etc. so you can use that to verify behavior etc.
>>>
>>>
>>>> /Johan
>>>>
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/Intercept-a-processor--tp27130672p27130672.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
>>>
>>>
>>
> 


Re: Intercept a processor?

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jan 13, 2010 at 9:11 AM, Johan Haleby <jo...@gmail.com> wrote:
>
> Hi,
>
> Thank you very much your suggestion with event notifiers worked! But I hope
> the changes in 2.2 can make it even better since now the
> ExchangeCompletedEvent is sent several times (once per "from" in the route
> definition") and thus it's hard to know the count in the latch when you're
> not sure to which endpoint the users sends the first message.
>

I got an idea to introduce a builder so you can build expressions
where you tell when the test is supposed to be completed.
Then you got some callback object back you can await later to be
notified when the condition is triggered.

This helps the problem you described with using a custom client to
send in the messages where you cannot use the producer template
with the async callback parameter.


> Would you recommend using a snapshot of version 2.2 right now? (We'd also
> like to use Spring 3 in our project).
>

We did some changes in Camel 2.2 to let it support Spring 3.0. So you
need 2.2 for Spring 3.0. 2.1 does not work with Spring 3.0.
However we use Spring 2.5.6 by default so its not throughly tested
with 3.0. But please try it out on your end.

I would recon staying on 2.1 if you already use it and is about to go
in production etc.
But if you still have 1-2 months development time you may want to try
using the 2.2 snapshot and then use 2.2 GA when its out next month.



> /Johan
>
>
> Johan Haleby wrote:
>>
>> Hi,
>>
>> Thanks for your quick response. Sorry for not mentioning it in the
>> previous mail but I'm using Camel 2.1 just as you suspected. Unfortunately
>> the first solution you posted (using async send and latches) won't work
>> "out of the box" for me because the producer template is wrapped in an
>> anti-corruption layer and the test should use this anti-corruption layer
>> to send the message.
>>
>> I'll look into your suggestion by subscribing to the ExchangeDoneEvent. Is
>> there anywhere I can find some documentation or example of how to do this?
>> Or was it this that you went through in chapter 6 in the book?
>>
>> I look forward to the changes you mention in version 2.2, seems really
>> useful and looks to fit very well with what I'm trying to do here. Is
>> there an expected date when 2.2 may be available?
>>
>> Regards,
>> /Johan
>>
>> The first option won't work
>>
>> Claus Ibsen-2 wrote:
>>>
>>> On Tue, Jan 12, 2010 at 5:56 PM, Johan Haleby <jo...@gmail.com>
>>> wrote:
>>>>
>>>> Hi,
>>>>
>>>> I'm configuring routes using the Java DSL and it works very well.
>>>> However
>>>> during testing I'd like to somehow hook into the end of an already
>>>> defined
>>>> route to add notification support. The reason is that in my test I'm
>>>> creating a message and pass it to a queue using Camel and this message
>>>> is
>>>> handled by a processor. After this processor has finished executing I'd
>>>> like
>>>> to receive some sort of notification but only during testing. The reason
>>>> is
>>>> that I'd like my test to wait until the processor has finished executing
>>>> in
>>>> my test case so that I can verify the result of the processor. For
>>>> example:
>>>>
>>>> public void test() {
>>>>  1. send a message to queue // just as you would in production
>>>>  2. wait for the processor to finish // this is where I'd like to get a
>>>> notification that the processor has finished so that it's ok to continue
>>>> to
>>>> the next step
>>>>  3. verify result
>>>> }
>>>>
>>>> The route may look something like:
>>>> from("jms:queue:myqueue).process(new MyProcessor()); // A simplification
>>>> of
>>>> the production route
>>>>
>>>> Is there a preferred way of doing this in Camel without changing the
>>>> code
>>>> making up the "production route"? Or is there a better way to achieve
>>>> it?
>>>>
>>>
>>> Chapter 6 in the book go over this issue and how to address that:
>>> http://www.manning.com/ibsen/ (will be updated in next MEAP due this
>>> month)
>>>
>>> However we made it easier to do nice and easy from an unit test in 2.2
>>> which I assume is not the version of Camel you are using.
>>> In 2.2 you can advice and route by adding additional cross cutting
>>> concerns such as onCompletion, interceptors etc. which you would then
>>> be able to use to know when its done.
>>>
>>> In Camel 2.1 you got the EventNotification which you actually can use
>>> for that to get notified when an Exchange is done as it emits a
>>> ExchangeDoneEvent.
>>> I am currently improving that for 2.2 to let you filter out of the box
>>> the notifier so you only receive interesting events. But that should
>>> not hold you back from using that in 2.1.
>>>
>>> We may improve this situation even more to make it easy as it can get
>>> for testing production routes with test methods. So kinda inject mocks
>>> at end of routes etc. so you can use that to verify behavior etc.
>>>
>>>
>>>> /Johan
>>>>
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/Intercept-a-processor--tp27130672p27130672.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/Intercept-a-processor--tp27130672p27140999.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

Re: Intercept a processor?

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

Thank you very much your suggestion with event notifiers worked! But I hope
the changes in 2.2 can make it even better since now the
ExchangeCompletedEvent is sent several times (once per "from" in the route
definition") and thus it's hard to know the count in the latch when you're
not sure to which endpoint the users sends the first message. 

Would you recommend using a snapshot of version 2.2 right now? (We'd also
like to use Spring 3 in our project).

/Johan


Johan Haleby wrote:
> 
> Hi,
> 
> Thanks for your quick response. Sorry for not mentioning it in the
> previous mail but I'm using Camel 2.1 just as you suspected. Unfortunately
> the first solution you posted (using async send and latches) won't work
> "out of the box" for me because the producer template is wrapped in an
> anti-corruption layer and the test should use this anti-corruption layer
> to send the message.
> 
> I'll look into your suggestion by subscribing to the ExchangeDoneEvent. Is
> there anywhere I can find some documentation or example of how to do this?
> Or was it this that you went through in chapter 6 in the book?
> 
> I look forward to the changes you mention in version 2.2, seems really
> useful and looks to fit very well with what I'm trying to do here. Is
> there an expected date when 2.2 may be available?
> 
> Regards,
> /Johan
> 
> The first option won't work 
> 
> Claus Ibsen-2 wrote:
>> 
>> On Tue, Jan 12, 2010 at 5:56 PM, Johan Haleby <jo...@gmail.com>
>> wrote:
>>>
>>> Hi,
>>>
>>> I'm configuring routes using the Java DSL and it works very well.
>>> However
>>> during testing I'd like to somehow hook into the end of an already
>>> defined
>>> route to add notification support. The reason is that in my test I'm
>>> creating a message and pass it to a queue using Camel and this message
>>> is
>>> handled by a processor. After this processor has finished executing I'd
>>> like
>>> to receive some sort of notification but only during testing. The reason
>>> is
>>> that I'd like my test to wait until the processor has finished executing
>>> in
>>> my test case so that I can verify the result of the processor. For
>>> example:
>>>
>>> public void test() {
>>>  1. send a message to queue // just as you would in production
>>>  2. wait for the processor to finish // this is where I'd like to get a
>>> notification that the processor has finished so that it's ok to continue
>>> to
>>> the next step
>>>  3. verify result
>>> }
>>>
>>> The route may look something like:
>>> from("jms:queue:myqueue).process(new MyProcessor()); // A simplification
>>> of
>>> the production route
>>>
>>> Is there a preferred way of doing this in Camel without changing the
>>> code
>>> making up the "production route"? Or is there a better way to achieve
>>> it?
>>>
>> 
>> Chapter 6 in the book go over this issue and how to address that:
>> http://www.manning.com/ibsen/ (will be updated in next MEAP due this
>> month)
>> 
>> However we made it easier to do nice and easy from an unit test in 2.2
>> which I assume is not the version of Camel you are using.
>> In 2.2 you can advice and route by adding additional cross cutting
>> concerns such as onCompletion, interceptors etc. which you would then
>> be able to use to know when its done.
>> 
>> In Camel 2.1 you got the EventNotification which you actually can use
>> for that to get notified when an Exchange is done as it emits a
>> ExchangeDoneEvent.
>> I am currently improving that for 2.2 to let you filter out of the box
>> the notifier so you only receive interesting events. But that should
>> not hold you back from using that in 2.1.
>> 
>> We may improve this situation even more to make it easy as it can get
>> for testing production routes with test methods. So kinda inject mocks
>> at end of routes etc. so you can use that to verify behavior etc.
>> 
>> 
>>> /Johan
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Intercept-a-processor--tp27130672p27130672.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/Intercept-a-processor--tp27130672p27140999.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Intercept a processor?

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

Thanks for your quick response. Sorry for not mentioning it in the previous
mail but I'm using Camel 2.1 just as you suspected. Unfortunately the first
solution you posted (using async send and latches) won't work "out of the
box" for me because the producer template is wrapped in an anti-corruption
layer and the test should use this anti-corruption layer to send the
message.

I'll look into your suggestion by subscribing to the ExchangeDoneEvent. Is
there anywhere I can find some documentation or example of how to do this?
Or was it this that you went through in chapter 6 in the book?

I look forward to the changes you mention in version 2.2, seems really
useful and looks to fit very well with what I'm trying to do here. Is there
an expected date when 2.2 may be available?

Regards,
/Johan

The first option won't work 

Claus Ibsen-2 wrote:
> 
> On Tue, Jan 12, 2010 at 5:56 PM, Johan Haleby <jo...@gmail.com>
> wrote:
>>
>> Hi,
>>
>> I'm configuring routes using the Java DSL and it works very well. However
>> during testing I'd like to somehow hook into the end of an already
>> defined
>> route to add notification support. The reason is that in my test I'm
>> creating a message and pass it to a queue using Camel and this message is
>> handled by a processor. After this processor has finished executing I'd
>> like
>> to receive some sort of notification but only during testing. The reason
>> is
>> that I'd like my test to wait until the processor has finished executing
>> in
>> my test case so that I can verify the result of the processor. For
>> example:
>>
>> public void test() {
>>  1. send a message to queue // just as you would in production
>>  2. wait for the processor to finish // this is where I'd like to get a
>> notification that the processor has finished so that it's ok to continue
>> to
>> the next step
>>  3. verify result
>> }
>>
>> The route may look something like:
>> from("jms:queue:myqueue).process(new MyProcessor()); // A simplification
>> of
>> the production route
>>
>> Is there a preferred way of doing this in Camel without changing the code
>> making up the "production route"? Or is there a better way to achieve it?
>>
> 
> Chapter 6 in the book go over this issue and how to address that:
> http://www.manning.com/ibsen/ (will be updated in next MEAP due this
> month)
> 
> However we made it easier to do nice and easy from an unit test in 2.2
> which I assume is not the version of Camel you are using.
> In 2.2 you can advice and route by adding additional cross cutting
> concerns such as onCompletion, interceptors etc. which you would then
> be able to use to know when its done.
> 
> In Camel 2.1 you got the EventNotification which you actually can use
> for that to get notified when an Exchange is done as it emits a
> ExchangeDoneEvent.
> I am currently improving that for 2.2 to let you filter out of the box
> the notifier so you only receive interesting events. But that should
> not hold you back from using that in 2.1.
> 
> We may improve this situation even more to make it easy as it can get
> for testing production routes with test methods. So kinda inject mocks
> at end of routes etc. so you can use that to verify behavior etc.
> 
> 
>> /Johan
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Intercept-a-processor--tp27130672p27130672.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/Intercept-a-processor--tp27130672p27131142.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Intercept a processor?

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Jan 12, 2010 at 5:56 PM, Johan Haleby <jo...@gmail.com> wrote:
>
> Hi,
>
> I'm configuring routes using the Java DSL and it works very well. However
> during testing I'd like to somehow hook into the end of an already defined
> route to add notification support. The reason is that in my test I'm
> creating a message and pass it to a queue using Camel and this message is
> handled by a processor. After this processor has finished executing I'd like
> to receive some sort of notification but only during testing. The reason is
> that I'd like my test to wait until the processor has finished executing in
> my test case so that I can verify the result of the processor. For example:
>
> public void test() {
>  1. send a message to queue // just as you would in production
>  2. wait for the processor to finish // this is where I'd like to get a
> notification that the processor has finished so that it's ok to continue to
> the next step
>  3. verify result
> }
>
> The route may look something like:
> from("jms:queue:myqueue).process(new MyProcessor()); // A simplification of
> the production route
>
> Is there a preferred way of doing this in Camel without changing the code
> making up the "production route"? Or is there a better way to achieve it?
>

Chapter 6 in the book go over this issue and how to address that:
http://www.manning.com/ibsen/ (will be updated in next MEAP due this
month)

However we made it easier to do nice and easy from an unit test in 2.2
which I assume is not the version of Camel you are using.
In 2.2 you can advice and route by adding additional cross cutting
concerns such as onCompletion, interceptors etc. which you would then
be able to use to know when its done.

In Camel 2.1 you got the EventNotification which you actually can use
for that to get notified when an Exchange is done as it emits a
ExchangeDoneEvent.
I am currently improving that for 2.2 to let you filter out of the box
the notifier so you only receive interesting events. But that should
not hold you back from using that in 2.1.

We may improve this situation even more to make it easy as it can get
for testing production routes with test methods. So kinda inject mocks
at end of routes etc. so you can use that to verify behavior etc.


> /Johan
>
> --
> View this message in context: http://old.nabble.com/Intercept-a-processor--tp27130672p27130672.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