activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spitfire_ch <pesch...@bluewin.ch>
Subject NMS Active MQ: Error handling and debuggin in C#
Date Tue, 25 Jun 2013 16:28:15 GMT
Hi

We are trying to develop a tool in C# to read records from SQL Server,
convert them to XML and send them to ActiveMQ. The SQL Server -> XML part
works perfectly, but the NMS ActiveMQ library causes a lot of problems.

We are using ApacheNMS_160 in Visual Studio 2008 (.NET 3.5 SP1).

Problem 1: Debugging does not work properly. Attempts to debug the program
result in „There is no source code available for the current location“.
Often, after all the messages have been sent sucessfully, the following
error occurs:

System.IO.EndOfStreamException occurred
  Message="Über das Ende des Streams hinaus kann nicht gelesen werden."
(Unable to read beyond the end of the stream.)
  Source="mscorlib"
  StackTrace:
       bei System.IO.__Error.EndOfFile()
       bei System.IO.BinaryReader.FillBuffer(Int32 numBytes)
       bei System.IO.BinaryReader.ReadInt32()
       bei Apache.NMS.Util.EndianBinaryReader.ReadInt32() in
c:\dev\NMS\src\main\csharp\Util\EndianBinaryReader.cs:Zeile 135.
  InnerException: 
  
This seems to be caused by the ActiveMQ library, namely the
Apache.NMS.Util.EndianBinaryReader. Without proper debugging it is really
hard to figure out, what part of our code causes this issue.

 
Problem 2: Error handling does not work the way we would expect. When we
trigger an execption while executing the code in VisualStudio - for example
by using an invalid urlQueue for the connectionFactory - a corresponding
connection error pops up. However, if we put the connection code inside a
try -> catch block, it will not switch to the catch block as it should; the
exception does not seem to be catched. When we build the program and start
the executable file, the behaviour is even worse: the program simply hangs,
but does not throw an error. We need to use the task manager in order to
kill the process.

We have already tried the ExceptionListener and OnException events, but to
no avail. The corresponding part of our code is shown below.

Any help is greatly appretiated!

Thank you very much!

HP


 try
            {
                // Create the connection factory which will be used to
create new connections to the queue.  We set the URI to that of the ActiveMQ
server.
                var connectionFactory = new ConnectionFactory(this.uri);

                connectionFactory.OnException += new
ExceptionListener(connectionFactory_OnException);

                // Create and open a new connection to ActiveMQ.
                connection = connectionFactory.CreateConnection(userName,
password);
                connection.RequestTimeout = new TimeSpan(0, 0, 30);
                connection.ExceptionListener += new
ExceptionListener(connection_ExceptionListener);
         

                // amh@20130618
                connection.AcknowledgementMode =
AcknowledgementMode.AutoAcknowledge;
                connection.Start();

                // Create a new session.
                this.session =
connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
     
                // Get a handle to the destination queue by its queue name.
                var destination = session.GetDestination(destinationQueue);
     
                // Setup a message producer to send message to the queue the
server is consuming from.
                this.producer = session.CreateProducer(destination);

                // amh@20130618
                this.producer.DeliveryMode = MsgDeliveryMode.Persistent;
     
                // Create a temporary queue for this session.  This queue
will survive until the connection is closed, and then it
                // is automatically deleted by ActiveMQ.  This temporary
queue will be used by the consumer (server) to send response
                // messages to.
                this.temporaryQueue = session.CreateTemporaryQueue();
     
                // Create a consumer to listen for messages on the temporary
queue we just created.
                var responseConsumer =
session.CreateConsumer(temporaryQueue);
                
                // Wire up an event which will be fired upon receipt of
response messages.
                responseConsumer.Listener += new
MessageListener(responseConsumer_Listener);
            }
            //catch (Apache.NMS.NMSConnectionException ex)
            catch (Exception ex)
            {
                Console.WriteLine("Verbindungsfehler mit ActiveMQ:
"+ex.Message);
                //EventLog.WriteEntry("SQLActiveMQ.RiskScoreTask",
String.Format("{0} {1} {2}", ex.Source, ex.Message, (ex.InnerException !=
null) ? ex.InnerException.ToString() : ""));
                throw ex;
            }
        }

        void connectionFactory_OnException(Exception exception)
        {
            throw exception;
        }

        void connection_ExceptionListener(Exception exception)
        {
            throw exception;
        }




--
View this message in context: http://activemq.2283324.n4.nabble.com/NMS-Active-MQ-Error-handling-and-debuggin-in-C-tp4668567.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Mime
View raw message