How do I restart embedded broker

 FAQ > Using Apache ActiveMQ Classic > How do I restart embedded broker

Pure restart of the embedded broker is not advisable, since it’s state could be corrupted. Therefore, you’re advised to instantiate the broker again before restarting it.

BrokerService service = BrokerFactory.createBroker("xbean:activemq.xml");
service.start();
service.waitUntilStarted();

service.stop();
service.waitUntilStopped();

service = BrokerFactory.createBroker("xbean:activemq.xml");
service.start();

In 5.3 however, we allowed the force start of the broker that has been stopped for use cases that need this functionality. You can do it by using

BrokerService.start(boolean force);

method.

The following example demonstrates it.

BrokerService service = BrokerFactory.createBroker("xbean:activemq.xml");
service.start();
service.waitUntilStarted();

service.stop();
service.waitUntilStopped();

service.start(true);

However, it’s better (more reliable) to instantiate the broker again if it is possible.

Apache, ActiveMQ, Apache ActiveMQ, the Apache feather logo, and the Apache ActiveMQ project logo are trademarks of The Apache Software Foundation. Copyright © 2024, The Apache Software Foundation. Licensed under Apache License 2.0.