Return-Path: Delivered-To: apmail-activemq-users-archive@www.apache.org Received: (qmail 68363 invoked from network); 24 Jul 2007 18:20:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 24 Jul 2007 18:20:09 -0000 Received: (qmail 78314 invoked by uid 500); 24 Jul 2007 18:20:06 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 78288 invoked by uid 500); 24 Jul 2007 18:20:06 -0000 Mailing-List: contact users-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@activemq.apache.org Delivered-To: mailing list users@activemq.apache.org Received: (qmail 78275 invoked by uid 99); 24 Jul 2007 18:20:06 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Jul 2007 11:20:06 -0700 X-ASF-Spam-Status: No, hits=0.8 required=10.0 tests=INFO_TLD,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of sukoneru@cisco.com designates 171.71.176.71 as permitted sender) Received: from [171.71.176.71] (HELO sj-iport-2.cisco.com) (171.71.176.71) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Jul 2007 11:20:04 -0700 Received: from sj-dkim-3.cisco.com ([171.71.179.195]) by sj-iport-2.cisco.com with ESMTP; 24 Jul 2007 11:19:09 -0700 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aj0KAK7fpUarR7PD/2dsb2JhbACDFw X-IronPort-AV: i="4.16,575,1175497200"; d="scan'208"; a="387815966:sNHT430524016" Received: from sj-core-2.cisco.com (sj-core-2.cisco.com [171.71.177.254]) by sj-dkim-3.cisco.com (8.12.11/8.12.11) with ESMTP id l6OIJ830003043 for ; Tue, 24 Jul 2007 11:19:08 -0700 Received: from xbh-sjc-211.amer.cisco.com (xbh-sjc-211.cisco.com [171.70.151.144]) by sj-core-2.cisco.com (8.12.10/8.12.6) with ESMTP id l6OIIx6e029081 for ; Tue, 24 Jul 2007 18:19:08 GMT Received: from xmb-sjc-21a.amer.cisco.com ([171.70.151.152]) by xbh-sjc-211.amer.cisco.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 24 Jul 2007 11:19:07 -0700 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: FW: active mq broker start up issue. Date: Tue, 24 Jul 2007 11:19:07 -0700 Message-ID: <5BD9FA70F5EDAC43AB816A5FDE30F6AC04C30E0F@xmb-sjc-21a.amer.cisco.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: active mq broker start up issue. Thread-Index: AcfNY6XBORBbC4+3Te6Ahs54X/yItwAu19tg From: "Suchitha Koneru \(sukoneru\)" To: X-OriginalArrivalTime: 24 Jul 2007 18:19:07.0937 (UTC) FILETIME=[1FFD9910:01C7CE1F] DKIM-Signature: v=0.5; a=rsa-sha256; q=dns/txt; l=3970; t=1185301148; x=1186165148; c=relaxed/simple; s=sjdkim3002; h=Content-Type:From:Subject:Content-Transfer-Encoding:MIME-Version; d=cisco.com; i=sukoneru@cisco.com; z=From:=20=22Suchitha=20Koneru=20\(sukoneru\)=22=20 |Subject:=20FW=3A=20active=20mq=20broker=20start=20up=20issue. |Sender:=20; bh=fHa2E2SYpTvdqV3FgFdro0Bx8ArHpeQFLi8Zaz/6eTU=; b=tYEon9FcURaa8nOQpYs8KwPi/bqwmrsrJ1qVhiskwsgRzi8t+s8NzIHBTLx3HMEOgQyapEzf spFclMe5Gr1psTRzWa3UzRbE/J6WBj6UpuklAZ6RCHZBjH6iIkpvJ5m8; Authentication-Results: sj-dkim-3; header.From=sukoneru@cisco.com; dkim=pass ( sig from cisco.com/sjdkim3002 verified; ); X-Virus-Checked: Checked by ClamAV on apache.org =20 Any suggestions in this regard ? Please let me know, Thank you, Suchitha. -----Original Message----- From: Suchitha Koneru (sukoneru)=20 Sent: Monday, July 23, 2007 12:57 PM To: users@activemq.apache.org Subject: active mq broker start up issue. Hello Active MQ users ,=20 =20 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 .=20 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. =20 Tomcat does not give us the flexibility of starting the web apps in particular order. The web.xml of Webapp A is as follows=20 =20 com.messaging.ActiveMQBrokerStartListener com.context.ApplicationInitListener =20 // code for ActiveMQBrokerStartListener BrokerService broker =3D new BrokerService(); int counter =3D 0; Properties activeMQProperties =3D new Properties() ; =20 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 =3D new File("../../activemq"); Logger logger =3D Logger.getLogger(ActiveMQBrokerStartListener.class); dir.mkdir(); InetAddress ipAdress ; broker.setDataDirectory(dir); try{ ipAdress =3D 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 try{ activeMQProperties.load(new FileInputStream(MessagingConstants.ACTIVEMQ_PORT_FILE_PATH )); portNum =3D Integer.parseInt(activeMQProperties.getProperty(MessagingConstants.Activ eMQPort,"-1")); if(portNum =3D=3D -1){ logger.error("active mq port not configured via the proeprties file using the default port value as "+MessagingConstants.DEFAULT_PORT_VALUE); portNum =3D 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=20 try{=20 // broker url is tcp://171.69.155.137:61716?trace=3Dtrue&wireFormat.maxInactivityDuration=3D= - 1 broker.addConnector(MessagingConstants.CONNECTOR+ ipAdress.getHostAddress()+":"+portNum+MessagingConstants.ACTIVEMQ_URL_SU FFIX); broker.start(); logger.info("Active MQ Broker Started at local host port "+ portNum); break; }catch(Exception e){ // System.out.println(e.getMessage()); if(e instanceof java.net.BindException){ //broker port is already occupied by another process, try to start the broker at different=20 // port number portNum =3D getRandomPortNumber() ; logger.info("trying to start the broker at port "+portNum); counter ++; }else{ logger.error("exception while starting broker : ",e); e.printStackTrace(); } } } 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. thanks, Suchitha.