Return-Path: Delivered-To: apmail-activemq-users-archive@www.apache.org Received: (qmail 47640 invoked from network); 10 May 2010 14:04:31 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 10 May 2010 14:04:31 -0000 Received: (qmail 54232 invoked by uid 500); 10 May 2010 14:04:31 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 54206 invoked by uid 500); 10 May 2010 14:04:31 -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 54198 invoked by uid 99); 10 May 2010 14:04:31 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 May 2010 14:04:31 +0000 X-ASF-Spam-Status: No, hits=1.7 required=10.0 tests=AWL,FREEMAIL_FROM,HTML_FONT_FACE_BAD,HTML_MESSAGE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of tammer.salem@googlemail.com designates 209.85.161.43 as permitted sender) Received: from [209.85.161.43] (HELO mail-fx0-f43.google.com) (209.85.161.43) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 May 2010 14:04:25 +0000 Received: by fxm14 with SMTP id 14so7743629fxm.2 for ; Mon, 10 May 2010 07:04:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=HJMvpuqOxclKJtoH3tSQAFz0+s9XsrlqBTHgbJDCvYs=; b=NJlqdDAmnGetteRfSdKVZGWCd++wntrLI5w3W6/8Ge7jSJA49MwkW63XO0IPyVb5Up NHVxCjYOaR/GRvq8WMLXRcDh6dkWLHXso/fs87Lm1XfHxBCBnaK7P98Vnp8gsOg4JRTY FddGyGuuCXfoUeQLKcuIaCsNUt3MLXu6JCzpo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=wmeUrmYS5ogwLTW6whkDugQeSEpRsOij+OiqDB5dVZKmdxuW8IsJBjyj0GFABVvwpk O2EtpP7EPPhJuugmpVKpCCB79Qo0s31Yy76oAqfudzVF66hh9Jem291MeXIVtC4jF1G+ mByxg6TGD5aMYgXVLZaq0/Z04QO0Dv4RvXUKs= MIME-Version: 1.0 Received: by 10.239.188.193 with SMTP id q1mr281139hbh.33.1273500243571; Mon, 10 May 2010 07:04:03 -0700 (PDT) Received: by 10.239.178.135 with HTTP; Mon, 10 May 2010 07:04:03 -0700 (PDT) Date: Mon, 10 May 2010 15:04:03 +0100 Message-ID: Subject: NMS - cannot recover from connection failure From: Tammer Salem To: users@activemq.apache.org Content-Type: multipart/alternative; boundary=001485f45404a3b63904863de112 --001485f45404a3b63904863de112 Content-Type: text/plain; charset=ISO-8859-1 Hello All, I have an NMS client using the stomp broker on a .netcf device. For the most part it works absolutely fine, but now I'm trying to harden the device (for network failures etc.). I have added an exception listener and specifically look for IOExceptions (which I believe are what .NET throws if the GPRS/3G network connectivity dies). I can successfully capture this exception and then I fire off a thread to restart the connection and add my listeners again. At the moment this method doesn't seem to work - I can never get a connection again. Can anyone advise what is the best way of doing this? I've also attached my code so that you know what I'm trying to do. class AMQMessageHandler { private String myQueue; private String connecturi; //private ISession session; IConnectionFactory factory; IConnection connection; ISession session; IDestination destination; IMessageConsumer messageConsumer; /* * the UI thread within whose context the code will be executed */ private Form uiThread; > /* * function in the UI thread to handle exceptions */ private Delegate exceptionDelegate; > > public AMQMessageHandler(String connectionURI, String driverID, > Delegate exceptionDelegate, Form uiThread) { this.connecturi = connectionURI; this.myQueue = "driver.channel." + driverID; this.uiThread = uiThread; this.exceptionDelegate = exceptionDelegate; } > public void start() { > try { this.factory = new ConnectionFactory(connecturi); this.connection = this.factory.CreateConnection(); this.session = this.connection.CreateSession(); this.destination = SessionUtil.GetDestination(session, > "queue://" + myQueue); this.messageConsumer = session.CreateConsumer(destination); messageConsumer.Listener += new > MessageListener(messageConsumer_Listener); connection.ExceptionListener += new > ExceptionListener(connection_ExceptionListener); connection.Start(); > } catch (Exception ex) { uiThread.Invoke(exceptionDelegate,ex.Message); } } > public delegate void RestartConnectionDelegate(); > private void restartConnection() { new System.Threading.Thread(threadedStartConnection).Start(); } > private void threadedStartConnection() { int retryCount = 1; bool keepTryingtoRestart = true; > while (keepTryingtoRestart == true) { //tsalem - add some kind of logging here //listBox.Items.Add("attempting to reconnect - pass " + > retryCount); System.Threading.Thread.Sleep(3000); > try { this.factory = new ConnectionFactory(connecturi); this.connection = this.factory.CreateConnection(); this.session = this.connection.CreateSession(); this.destination = SessionUtil.GetDestination(session, > "queue://" + myQueue); this.messageConsumer = > session.CreateConsumer(destination); messageConsumer.Listener += new > MessageListener(messageConsumer_Listener); connection.ExceptionListener += new > ExceptionListener(connection_ExceptionListener); connection.Start(); > keepTryingtoRestart = false; } catch (Exception ex) { uiThread.Invoke(exceptionDelegate, ex.Message +"\n" + > ex.StackTrace); //tsalem change this to check for keep retrying rather > than on a counter if (retryCount == 50) { keepTryingtoRestart = false; } > } retryCount++; } } > > public void messageConsumer_Listener(IMessage receivedMessage) { try { ITextMessage message = receivedMessage as ITextMessage; message.Acknowledge(); //tsalem - todo - handle message if (message.Text != null) { AMQUtil.Instance.ResponseAvailable(message.Text, > uiThread); } else { uiThread.Invoke(exceptionDelegate, "ERROR: AMQ Message > is empty"); } } catch (Exception ex) { uiThread.Invoke(exceptionDelegate,ex.Message); } } > > > void connection_ExceptionListener(Exception exception) { uiThread.Invoke(exceptionDelegate,exception.Message); > if (exception is System.IO.IOException) { //Invoke(new > RestartConnectionDelegate(threadedStartConnection)); threadedStartConnection(); } } } regards, Tammer --001485f45404a3b63904863de112--