activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Suchitha Koneru \(sukoneru\)" <>
Subject FW: active mq broker start up issue.
Date Tue, 24 Jul 2007 18:19:07 GMT
Any suggestions in this regard ? Please let me know,
Thank you,
-----Original Message-----
From: Suchitha Koneru (sukoneru) 
Sent: Monday, July 23, 2007 12:57 PM
Subject: active mq broker start up issue.

Hello Active MQ users , 
We use Tomcat server 5.5.20 with two web applications , namely Webapp A
and Web App. B.
The inter web app communication is via the active mq broker.  The active
mq version is 4..0.2 . 
As of now, the web app A is always started before B. Hence the broker is
specified as a Servlet Context Listener in web.xml of the web app A.
The problem we have  is to start the broker irrespective of the order of
initialization of  web apps .
  We would be adding a new web app called Webapp C . In this scenario, I
will not have a control on the order in which the web apps are
initialized by Tomcat. The code to start the broker , takes into
account, that if the broker port is already occupied, it will  attempt
to start the broker at a randomly generated  port for 5 times.
 Tomcat does not give us the flexibility of starting the web apps in
particular order.  The web.xml of Webapp A is as follows 
<!-- starting active mq broker -->




<!-- starting the rest of services in web app   A -->







// code for ActiveMQBrokerStartListener

BrokerService broker = new BrokerService();

int counter = 0;

Properties activeMQProperties = new Properties() ;


int portNum ;

public void contextInitialized(ServletContextEvent arg0) {

System.out.println("Starting ActiveMQ Broker Service...");

//for the broker URI , do not have leading or trailing spaces

File dir = new File("../../activemq");

Logger logger = Logger.getLogger(ActiveMQBrokerStartListener.class);


InetAddress ipAdress ;



ipAdress = InetAddress.getLocalHost();

}catch(UnknownHostException e){

logger.error("error in obtaining Local Host address "+e.getMessage());

return ;


// getting the port number from the active mq properties file


FileInputStream(MessagingConstants.ACTIVEMQ_PORT_FILE_PATH ));

portNum =

if(portNum == -1){

logger.error("active mq port not configured via the proeprties file
using the default port value as

portNum = MessagingConstants.DEFAULT_PORT_VALUE ;


}catch(Exception e){

logger.error("exception while getting port properties "+e.getMessage());


while(counter < 5){ // 5 attempts to start the broker 


// broker url is


broker.start();"Active MQ Broker Started at local host port "+ portNum);


}catch(Exception e){

// System.out.println(e.getMessage());

if(e instanceof{ //broker port is already
occupied by another process, try to start the broker at different 

// port number

portNum = getRandomPortNumber() ;"trying to start the broker at port "+portNum);

counter ++;


logger.error("exception while starting broker : ",e);





Please let me know, if there is a way to ensure that the broker is
started first , irrespective of the order of initilization of web apps.
I'll also do a  google search on this issue.



View raw message