With the last version of Apache Camel, we provide a
event notifier support class which allow to keep information about what happen on Exchange, Route and Endpoint. One of the benefit of this class is that you can easily audit messages created in Camel Routes, collect information and report that in log by example.
When developing an application, it is very important to calculate/measure elapsed time on the platform to find which part of your code, processor or system integrated which is the bad duck and must be improved.
In three steps, I would show you How to enable this mechanism to report :
Time elapsed to call an endpoint (could be another camel route, web service, …)
Time elapsed on the route exchange
STEP 1 - Create a Class implementing the EventNotifierSupport
Not really complicated and the code is explicit. Check the doStart() method to enable/disable the events for which you would like to gather information.
This example uses only Exchange.CREATED_TIMESTAMP property but the next version of Camel 2.7.0 will provide you the property exchange.RECEIVED_TIMESTAMP and so you will be able to calculate more easily the time spend by the exchange to call the different processors till it arrives at the end of the route.
This example collects Date information but you can imagine to use this mechanism to check if your route processes the message according to SLA, ….
STEP 2 - Instantiate the bean in Camel Spring XML
By adding this bean definition, Camel will automatically register it to the CamelContext created.