concept NotifyBuilder in category camel

appears as: NotifyBuilder, NotifyBuilder, The NotifyBuilder, The NotifyBuilder
Camel in Action

This is an excerpt from Manning's book Camel in Action.

Camel provides the NotifyBuilder, which provides such insight. We’ll cover the NotifyBuilder in more detail in section 6.4.2, but the following code shows how to have NotifyBuilder notify you when Camel is finished processing the message:

NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();

OrderClient client = new OrderClient("tcp://localhost:61616");
client.sendOrder(123, date, "4444", "5555");

boolean matches = notify.matches(5, TimeUnit.SECONDS);
assertTrue(matches);

First, you configure NotifyBuilder to notify you when one message is done. Then you use the client to send the message. Invoking the matches method on the notify instance will cause the test to wait until the condition applies, or the 5-second timeout occurs.

6.4.2. Using NotifyBuilder

NotifyBuilder is located in the org.apache.camel.builder package. It uses the Builder pattern, which means you stack methods on it to build an expression. You use it to define conditions for messages being routed in Camel. Then it offers methods to test whether the conditions have been meet. We already used it in the previous section, but this time we’ll raise the bar and show how you can build more complex conditions.

NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();