Hmm... I took a look at the code but looks confusing to me.

At first, direct:route2 and direct:route3 invocation doesn't produce 
ExchangeCompleted event, as DirectProducer doesn't create new Exchange but 
invoke consumer Processor directly.
However when from()'s predicate is evaluated in matches(), it always returns 
true, so ExchangeCompleted event for the direct:route1 exchange is also counted 
for route2 and route3.
https://github.com/apache/camel/blob/master/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java#L126

ExchangeCompleted event increments the count in the predicate added by 
whenExactlyDone() here
https://github.com/apache/camel/blob/master/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java#L568

Second however, if from()'s predicate is put prior to whenExactlyDone(), 
ExchangeCompleted event is not delivered to the whenExactlyDone()'s predicate
https://github.com/apache/camel/blob/master/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java#L1576

That's the reason why #2 and #3 are false.

So, at least whenExactlyDone() doesn't work for internal(direct) routing right 
now. As it seems ExchangeSent event is sent for internal routing as well, 
wereSentTo() would work for that purpose instead.

According to the comment, that's intended to always return true on matches() in 
from()'s predicate, so I'm not exactly sure how it should be. I think 
ExchangeCompleted event should be delivered to all the predicates regardless of 
the previous result though.

Would anyone else help?

Thanks,
Tomo

On 11/11/2016 01:18 PM, Tomohisa Igarashi wrote:
Hi,

Hmm this looks weird. The predicates order shouldn't matter. Would you file a 
JIRA?

Thanks,
Tomo

On 11/10/2016 06:13 PM, sohrab wrote:
I've read the page on NotifyBuilder but I don't think I really understood how
it works. So I wrote below test case to verify it. The results confound me.

(The Groovy script is standalone and fully functioning so feel free to run
it locally.)

Code
===

@Grab(group='org.apache.camel', module = 'camel-core', version='2.15.1')
import java.util.concurrent.TimeUnit
import org.apache.camel.builder.*
import org.apache.camel.impl.DefaultCamelContext

def context = new DefaultCamelContext()
context.addRoutes(new RouteBuilder() {
        void configure() {
            from('direct:route1').routeId('route1')
                .log('route 1 started')
                .to('direct:route2')
                .log('route 1 ended')
            from('direct:route2').routeId('route2')
                .log('route 2 started')
                .to('direct:route3')
                .log('route 2 ended')
            from('direct:route3').routeId('route3')
                .log('route 3 started and ended')
        }
    })
context.start()

def notifies = [
    new
NotifyBuilder(context).from('direct:route1').whenExactlyDone(1).create(),
    new
NotifyBuilder(context).from('direct:route2').whenExactlyDone(1).create(),
    new
NotifyBuilder(context).from('direct:route3').whenExactlyDone(1).create(),
    new
NotifyBuilder(context).whenExactlyDone(1).from('direct:route1').create(),
    new
NotifyBuilder(context).whenExactlyDone(1).from('direct:route2').create(),
    new
NotifyBuilder(context).whenExactlyDone(1).from('direct:route3').create()
]
context.createProducerTemplate().requestBody 'direct:route1', 'something'
notifies.eachWithIndex { it, i -> println "$i: ${it.matches()}"  }


STDOUT
===

0: true
1: false
2: false
3: true
4: true
5: true


I understand the predicates are stacked but can someone please explain the
above behaviour to me?



--
View this message in context: 
http://camel.465427.n5.nabble.com/NotifyBuilder-Behaviour-tp5789988.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to