I took a while to test this but the new wereSentTo condition matches too
eagerly, in your above example whenDone matches on any received message on
any endpoint and then the first wereSentTo match forces the whole predicate
to be true. What if you want is to wait for a number of messages just like
whenDone?

Need something like:

Eg:

public NotifyBuilder wereSentTo(final String endpointUri, *final int
number*) {
        stack.push(new EventPredicateSupport() {
            private int current;

            @Override
            public boolean onExchangeSent(Exchange exchange, Endpoint
endpoint, long timeTaken) {
                if (EndpointHelper.matchEndpoint(endpoint.getEndpointUri(),
endpointUri)) {
                    // we should match if matching once
                    current++;
                }
                return false;
            }

            public boolean matches() {
                return current >= number;
            }

            @Override
            public void reset() {
                matches = false;
            }

            @Override
            public String toString() {
                return "wereSentTo(" + endpointUri + ")";
            }
        });
        return this;
    }

Then can do as expected:

        NotifyBuilder notify = new NotifyBuilder(context)
.wereSentTo("jms:queue:CAPTURED.MESSAGES", *5*);

Whilst the current camel 2.9 code with 

        NotifyBuilder notify = new NotifyBuilder(context) 
          .whenDone(5).wereSentTo("jms:queue:CAPTURED.MESSAGES");

Fires on first message reaching CAPTURED.MESSAGES not after the required 5.

Also noticed that variable expansion of urls doesnt seem to happen in the
NotifyBuilder.

--
View this message in context: 
http://camel.465427.n5.nabble.com/NotifyBuilder-condition-fails-to-match-on-an-out-activemq-endpoint-tp4689038p4867857.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to