activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neek <>
Subject Stopping an embedded Broker (due to webapp reload)
Date Fri, 02 Sep 2011 05:41:14 GMT
Hi guys,

I have an embedded broker, created in a servlet's init() method with:

				BrokerService brokerService = BrokerFactory.createBroker(
					new URI("xbean:broker.xml"));

I use this servlet to manage lifetime of various services used by the web
application.  I'm finding that reloading the web app causes the broker to
fail to start because it's already running:

nested exception is
org.apache.activemq:BrokerName=bikesbroker,Type=Broker (Error creating bean
with name 'org.apache.activemq.xbean.XBeanBrokerService#0' defined in class
path resource [broker.xml]:

So it seems I must manually get hold of, and stop, the broker instance in my
servlet's destroy() method, to match the startup operation performed in

I've read
which addresses this situation, but I'm unclear what to do when a
potentially long period of time may have passed between making the start()
and stop() calls.

How should I get hold of the broker?  Should I call createBroker again, in
the same way as in init()?  From the how-do-i-restart-embedded-broker page,
with a "NEW LINE" added:

public void init(ServletConfig config) throws ServletException {
    BrokerService service =

public void destroy() {
    BrokerService service =
BrokerFactory.createBroker("xbean:activemq.xml"); // NEW LINE

I'm presuming I shouldn't simply hold on to the BrokerService instance
created in init() and re-use it in destroy().  Would that be safe?  I've
tried it, and it does stop the broker, and the broker then start
successfully as the webapp reloads, so this seems to work but I'd like
advice on whether it's safe.

Thanks for any advice.

View this message in context:
Sent from the ActiveMQ - User mailing list archive at

View raw message