activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "SebastianR." <>
Subject NMS: Strange behavior when re-connecting after connection abort
Date Thu, 14 Aug 2008 12:07:25 GMT


First of all my setup:
NMS: Yesterdays HEAD SVN revision
Broker: external broker running on ActiveMQ 4.1.1 
.Net Framework: 2.0
IDE: MS Visual Studio 2008 with C# as programming language

I recognize very strange behaviour when it comes to a connection failure. To
show this I wrote a little test program, which reproduces this behaviour.
The code is the following:

using System;
using System.Collections.Generic;
using System.Text;
using Apache.NMS;
using Apache.NMS.ActiveMQ;

namespace ExceptionTest
    class Program
        static private IConnectionFactory m_Factory;
        static private IConnection m_Connection;
        static private ISession m_SenderSession;
        static private ISession m_ReceiverSession;
        static private IDestination m_SenderQueue;
        static private IDestination m_ReceiverQueue;
        static private IMessageProducer m_Producer;
        static private IMessageConsumer m_Receiver;

        static void Main(string[] args)
                for (int i = 1; i <= 50; i++)
                    ITextMessage msg =

                    Console.WriteLine("Before Sending: " + i.ToString());
                    Console.WriteLine("After Senden: " + i.ToString());
            catch (Exception e)

            Console.ReadLine(); // Here I plug in the network cable

            //Optional Re-Connect (refered to as variant 1)

            while (true)
                ITextMessage msg = (ITextMessage) m_Receiver.Receive(new
                if(msg != null)
                    Console.WriteLine("Message: " + msg.Text);
                    Console.WriteLine("No Message available !");

        static private void Init()
                m_Factory = new ConnectionFactory(new
                m_Connection = m_Factory.CreateConnection("de", "power");
                m_ReceiverSession =
                m_SenderSession =
                m_SenderQueue = m_SenderSession.GetQueue("outbound");
                m_ReceiverQueue = m_ReceiverSession.GetQueue("outbound");
                m_Producer = m_SenderSession.CreateProducer(m_SenderQueue);
                m_Receiver =
            catch (Exception e)

Basically the program’s application flow is the following:
1.	Initiate NMS components
2.	Send or better try to send 50 messages --> here is where I pull the
network plug to abort the connection
3.	OPTIONAL (variant 1, commented out in the code above): Close the
connection and re-connect (initialize again)
4.	Receive as many messages as possible

The important things are logged to the console (sending and receiving
messages, exceptions).

Now there are the following testcases:

Without step 3. and without manual connection abort, everything is fine. 

Without step 3. and with manual connection abort by pulling the network
plug, I receive an exception (as expected). After going on with the receive
part (without any reconnecting method, as said before), I receive all
messages until the connection abort, even the message on which the exception
(an Apache.NMS.ActiveMQ.BrokerException) is thrown. So although the program
only reaches the “Before Sending ..”-statement, I receive this message -->
very strange

With step 3. and without manual connection abort, everything is fine.

With step 3. and with manual connection abort, I receive no message at all,
although some have been send correctly to the queue before connection abort.
Actually I know they are in the queue, because I wrote a separate Java
programm, a queuebrowser, which lists all correctly sent messages (also
again including the message the exception was thrown on). --> very strange
I recognized however, if I send a message into the queue before the failing
receive try (but after the re-connect) the queuebrowser lists those messages
too, but I still can’t receive any of them. Only way to get out all the
messsages in the queue is restarting the program at let it run without any
connection abort.

Has anyone watched such behavior or knows the reason for this ?

Regards, Sebastian 

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

View raw message