SwitchYard provides a low-level auditing mechanism intended for application debugging. Using Auditors to implement application logic is generally discouraged as the set and order of processors which auditors bind to is subject to change at any time. Auditing support requires a CDI environment to run, so your application must include META-INF/beans.xml.
Important notes
Custom auditors should not preserve state inside any fields because dispatching order is not guaranteed and only one instance of auditor is created by default. If you would like store some values please use exchange properties or message headers. Example below shows 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");
}
}