17.7. Use Exchange Properties
As only one instance of auditor is created by default and there is no guarantee for dispatching order, ensure that the custom auditors do not preserve state inside any of the fields. If you want to store values, use exchange properties or message headers. Here is an example of how to count processing time using Exchange properties as temporary storage:
@Named("custom auditor") public class SimpleAuditor implements Auditor { private Logger _logger = Logger.getLogger(SimpleAuditor.class); @Override public void beforeCall(Processors processor, Exchange exchange) { exchange.setProperty("time", System.currentTimeMillis()); } @Override public void afterCall(Processors processor, Exchange exchange) { long time = System.currentTimeMillis() - exchange.getProperty("time", 0, Long.class); _logger.info("Step " + processor.name() + " took " + time + "ms"); } }