When initializing an embedded broker, you must provide a broker event listener. This listener is an instance of a class that implements the BrokerEventListener interface. This interface specifies two methods:
public void brokerEvent(BrokerEvent brokerEvent), which is called when the broker starts and stops. This method is not required to perform any specific actions, so you can implement an empty method.
public boolean exitRequested(BrokerEvent event, Throwable thr), which is called when a fatal error has been encountered and the broker is seeking permission to terminate. This method should return true. If it returns false, the broker will not shut down, but it may then cease to respond correctly.
The following listing shows an example class that implements the BrokerEventListener interface.
class EmbeddedBrokerEventListener implements BrokerEventListener { public void brokerEvent(BrokerEvent brokerEvent) { System.out.println ("Received broker event:"+brokerEvent); } public boolean exitRequested(BrokerEvent event, Throwable thr) { System.out.println ("Broker is requesting a shutdown because of:"+event+" with "+thr); // return true to allow the broker to shutdown return true; } }