...
Code Block | ||||
---|---|---|---|---|
| ||||
NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
// now use some API to send a message etc. Maybe you cannot use Camel's ProducerTemplate
// now we want to wait until the message has been routed and completed
boolean done = notify.matches(10, TimeUnit.SECONDS);
assertTrue("Should be done", done);
// now maybe use some API to see that the message did as expected
|
This is a very basic example with a simple builder expression. What we said that we want it to match when any Exchange is done. The builder have many more methods to set more complex expressions, which even can be stacked using and, or, not operations. As of
...
title | Available starting with Camel 2.6.0 |
---|
...
.
...
...
NotifyBuilder event = event().whenDone(1).create();
Methods
These methods is for building the expression:
...
Examples
Code Block |
---|
NotifyBuilder eventnotify = new eventNotifyBuilder(context) .from("direct:foo").whenDone(5) .create(); |
Here we want to match when the direct:foo
endpoint have done 5 messages.
Code Block |
---|
NotifyBuilder eventnotify = new eventNotifyBuilder(context) .from("direct:foo").filter(body().contains("test")).whenDone(5) .create(); |
Here we want to match when the direct:foo
endpoint have done 5 messages which contains the word 'test' in the body.
The filter accepts a Predicate so you can use XPath, Bean, Simple and whatnot.
Code Block |
---|
NotifyBuilder eventnotify = new eventNotifyBuilder(context) .from("jms:*").whenDone(1) .create(); |
Here we just say that at least one message should be done received from any JMS endpoint (notice the wildcard matching).
Code Block |
---|
NotifyBuilder eventnotify = eventnew NotifyBuilder(context) .fromRoute("myCoolRoutes*").whenDone(3) .create(); |
Here we just say that at least three message should be done received from any of myCoolRoutes (notice the wildcard matching).
Code Block |
---|
NotifyBuilder eventnotify = new eventNotifyBuilder(context) .from("direct:foo").whenDone(5) .and().from("direct:bar").whenDone(7) .create(); |
Here both 5 foo messages and 7 bar messages must be done. Notice the use of the and operator.
Code Block |
---|
NotifyBuilder eventnotify = eventnew NotifyBuilder(context) .from("direct:foo").whenBodiesReceived("Hello World", "Bye World") .create(); |
Here we expect to receive two messages with Hello World
and Bye World
.
Code Block |
---|
NotifyBuilder eventnotify = new eventNotifyBuilder(context) .whenAnyReceivedMatches(body().contains("Camel")) .create(); |
...
Code Block |
---|
// lets use a mock to set the expressions as it got many great assertions for that // notice we use mock:assert which does NOT exist in the route, its just a pseudo name MockEndpoint mock = getMockEndpoint("mock:assert"); mock.expectedBodiesReceivedInAnyOrder("Hello World", "Bye World", "Hi World"); NotifyBuilder eventnotify = new eventNotifyBuilder(context) .from("direct:foo").whenReceivedSatisfied(mock) .create(); |
...