Sample 651: Using Synapse Observers
Introduction
This sample demonstrates how you can use the SynapseObserver interface to monitor the Synapse configuration at runtime.
Prerequisites
For a list of prerequisites, see Prerequisites to Start the ESB Samples.
Building the sample
To define the simple logging Synapse observer, open the
<ESB_HOME>/repository/conf/synapse.propertiesfile and add the following line:
synapse.observers=samples.userguide.SimpleLoggingObserver
To set the log level of the
samples.userguidepackage toINFO, open the<ESB_HOME>/repository/conf/log4j.propertiesfile and add the following line:
log4j.category.samples.userguide=INFO
Executing the sample
Start the ESB with any sample configuration. For instructions on starting a sample ESB configuration, see Starting the ESB with a sample configuration.
Analyzing the output
You will see that the SimpleLoggingObserver captures events that occur while constructing the Synapse configuration and logs them on the console as follows:
2009-08-06 14:30:24,578 [-] [main] INFO SimpleLoggingObserver Simple logging observer initialized...Capturing Synapse events...
2009-08-06 14:30:24,604 [-] [main] INFO SimpleLoggingObserver Endpoint : a3 was added to the Synapse configuration successfully
2009-08-06 14:30:24,605 [-] [main] INFO SimpleLoggingObserver Endpoint : a2 was added to the Synapse configuration successfully
2009-08-06 14:30:24,606 [-] [main] INFO SimpleLoggingObserver Endpoint : null was added to the Synapse configuration successfully
2009-08-06 14:30:24,611 [-] [main] INFO SimpleLoggingObserver Local entry : a1 was added to the Synapse configuration successfully
2009-08-06 14:30:24,649 [-] [main] INFO SimpleLoggingObserver Proxy service : StockQuoteProxy2 was added to the Synapse configuration successfully
2009-08-06 14:30:24,661 [-] [main] INFO SimpleLoggingObserver Proxy service : StockQuoteProxy1 was added to the Synapse configuration successfully
2009-08-06 14:30:24,664 [-] [main] INFO SimpleLoggingObserver Sequence : main was added to the Synapse configuration successfully
2009-08-06 14:30:24,701 [-] [main] INFO SimpleLoggingObserver Sequence : fault was added to the Synapse configuration successfullyThe SimpleLoggingObserver is implemented as follows:
package samples.userguide;
import org.apache.synapse.config.AbstractSynapseObserver;
public class SimpleLoggingObserver extends AbstractSynapseObserver {
public SimpleLoggingObserver() {
super();
log.info("Simple logging observer initialized...Capturing Synapse events...");
}
}It does not override any of the event handler implementations in the AbstractSynapseObserver class. The AbstractSynapseObserver logs all the received events by default.