Run as windows service: Need reconnect to establish the connection to the 
ActiveMQ Server
-----------------------------------------------------------------------------------------

                 Key: AMQNET-355
                 URL: https://issues.apache.org/jira/browse/AMQNET-355
             Project: ActiveMQ .Net
          Issue Type: Task
          Components: ActiveMQ, NMS
    Affects Versions: 1.5.2, 1.5.1
         Environment: Windows7 32Bit pro SP1 / Windows XP pro SP3  / Windows 
2003 R2 32Bit Standard SP2
ActiveMQ Version: 5.5.0
            Reporter: Marc Giavarra
            Assignee: Jim Gomes
            Priority: Minor


I am using the latest version of NMS to connect to an ActiveMQ Server (version 
5.5.0).
If you use this snippet in a windows service, you get an 
EndOfStreamException/ConnectionClosedException at the first call of 
"this.connection.Start();". If you call "CreateConnection" and "Start" once 
again, everything works fine.

In a normal windows application you do not need to recall.


Code:
protected override void OnStart(string[] args)
        {
            // Install service
            // c:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe 
C:\Sandbox\CS_2011.483\Unproduktiv\WebSocketTestService\bin\Debug\WWWebSocketService.exe
            try
            {
                Apache.NMS.IConnectionFactory connectionFactory = new 
Apache.NMS.ActiveMQ.ConnectionFactory("ssl://xxxxx");

                System.Diagnostics.Trace.WriteLine("Create connection");
                this.connection = 
connectionFactory.CreateConnection("MessageBrokerUsername", 
"MessageBrokerPassword");
                this.connection.ExceptionListener += new 
Apache.NMS.ExceptionListener(connection_ExceptionListener);

                System.Diagnostics.Trace.WriteLine("Start connection.");
                bool connected = false;
                int connectionCounter = 0;
                while (!connected)
                {
                    try
                    {
                        connectionCounter++;
                        this.connection.Start();
                        connected = this.connection.IsStarted;
                    }
                    catch (System.Exception ex)
                    {
                        this.connection.Dispose();
                        System.Diagnostics.Trace.WriteLine(ex.ToString());
                        System.Diagnostics.Trace.WriteLine("Tries to connect: " 
+ connectionCounter.ToString());
                        System.Threading.Thread.Sleep(3000);
                        // do reconnect
                        this.connection = 
connectionFactory.CreateConnection("MessageBrokerUsername", 
"MessageBrokerPassword");
                    }
                }

                System.Diagnostics.Trace.WriteLine("Tries to connect: " + 
connectionCounter.ToString());

                this.session = connection.CreateSession();
                System.Diagnostics.Trace.WriteLine("Create queue.");
                Apache.NMS.IDestination destination = new 
Apache.NMS.ActiveMQ.Commands.ActiveMQQueue("test");


                System.Diagnostics.Trace.WriteLine("Create consumer.");
                this.consumer = session.CreateConsumer(destination);
                this.consumer.Listener += new 
Apache.NMS.MessageListener(consumer_Listener);

            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
            }
        }



OS: Windows XP pro SP3  // Windows 2003 R2 32Bit Standard SP2
User: Local System  // administrator

Debug output
[3996] Create connection 
[3996] Start connection. 
[3996] Apache.NMS.ActiveMQ.ConnectionClosedException: The connection is already 
closed! 
[3996]    at Apache.NMS.ActiveMQ.Connection.CheckConnected() in 
c:\Sandbox\activemq-dotnet\Apache.NMS.ActiveMQ\trunk\src\main\csharp\Connection.cs:line
 821 
[3996]    at Apache.NMS.ActiveMQ.Connection.Start() in 
c:\Sandbox\activemq-dotnet\Apache.NMS.ActiveMQ\trunk\src\main\csharp\Connection.cs:line
 419 
[3996]    at WebSocketTestService.WebSocketService.OnStart(String[] args) in 
C:\Sandbox\CS_2011.483\Unproduktiv\WebSocketTestService\WebSocketService.cs:line
 44 
[3996] Tries to connect: 1 
[3996] Apache.NMS.NMSException: Unable to read beyond the end of the stream. 
---> System.IO.EndOfStreamException: Unable to read beyond the end of the 
stream. 
[3996]    at System.IO.__Error.EndOfFile() 
[3996]    at System.IO.BinaryReader.FillBuffer(Int32 numBytes) 
[3996]    at System.IO.BinaryReader.ReadInt32() 
[3996]    at Apache.NMS.Util.EndianBinaryReader.ReadInt32() in 
c:\Sandbox\activemq-dotnet\Apache.NMS\trunk\src\main\csharp\Util\EndianBinaryReader.cs:line
 135 
[3996]    at Apache.NMS.ActiveMQ.OpenWire.OpenWireFormat.Unmarshal(BinaryReader 
dis) in 
c:\Sandbox\activemq-dotnet\Apache.NMS.ActiveMQ\trunk\src\main\csharp\OpenWire\OpenWireFormat.cs:line
 226 
[3996]    at Apache.NMS.ActiveMQ.Transport.Tcp.TcpTransport.ReadLoop() in 
c:\Sandbox\activemq-dotnet\Apache.NMS.ActiveMQ\trunk\src\main\csharp\Transport\Tcp\TcpTransport.cs:line
 281 
[3996]    --- End of inner exception stack trace --- 
[3996] Tries to connect: 2 
[3996] Create queue. 
[3996] Create consumer. 



OS: Windows7 32Bit pro SP1
User: Local System

Debug output
[7300] Create connection 
[7300] Start connection. 
[7300] Tries to connect: 1 
[7300] Create queue. 
[7300] Create consumer. 


User: administrator

Debug output
[4128] Create connection 
[4128] Start connection. 
[4128] Apache.NMS.NMSException: Über das Ende des Streams hinaus kann nicht 
gelesen werden. ---> System.IO.EndOfStreamException: Über das Ende des Streams 
hinaus kann nicht gelesen werden. 
[4128]    bei System.IO.__Error.EndOfFile() 
[4128]    bei System.IO.BinaryReader.FillBuffer(Int32 numBytes) 
[4128]    bei System.IO.BinaryReader.ReadInt32() 
[4128]    bei Apache.NMS.Util.EndianBinaryReader.ReadInt32() in 
c:\Sandbox\activemq-dotnet\Apache.NMS\trunk\src\main\csharp\Util\EndianBinaryReader.cs:Zeile
 135. 
[4128]    bei 
Apache.NMS.ActiveMQ.OpenWire.OpenWireFormat.Unmarshal(BinaryReader dis) in 
c:\Sandbox\activemq-dotnet\Apache.NMS.ActiveMQ\trunk\src\main\csharp\OpenWire\OpenWireFormat.cs:Zeile
 226. 
[4128]    bei Apache.NMS.ActiveMQ.Transport.Tcp.TcpTransport.ReadLoop() in 
c:\Sandbox\activemq-dotnet\Apache.NMS.ActiveMQ\trunk\src\main\csharp\Transport\Tcp\TcpTransport.cs:Zeile
 281. 
[4128]    --- Ende der internen Ausnahmestapelüberwachung --- 
[4128] Apache.NMS.ActiveMQ.ConnectionClosedException: The connection is already 
closed! 
[4128]    bei Apache.NMS.ActiveMQ.Connection.CheckConnected() in 
c:\Sandbox\activemq-dotnet\Apache.NMS.ActiveMQ\trunk\src\main\csharp\Connection.cs:Zeile
 821. 
[4128]    bei Apache.NMS.ActiveMQ.Connection.Start() in 
c:\Sandbox\activemq-dotnet\Apache.NMS.ActiveMQ\trunk\src\main\csharp\Connection.cs:Zeile
 419. 
[4128]    bei WebSocketTestService.WebSocketService.OnStart(String[] args) in 
C:\Sandbox\CS_2011.483\Unproduktiv\WebSocketTestService\WebSocketService.cs:Zeile
 44. 
[4128] Tries to connect: 1 
[4128] Tries to connect: 2 
[4128] Create queue. 
[4128] Create consumer. 


OS: An other Windows7 32Bit pro SP1
the opposite: administrator is ok; Local System throws the exception




--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


Reply via email to