You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by Timothy Bish <ta...@gmail.com> on 2013/07/02 15:07:23 UTC

Re: NMS Active MQ: Error handling and debuggin in C#

The source code for the release is in a separate downloadable zip file 
on the release page.  Grab that and configure your studio project to 
know where to look and you should be in business.

On 06/25/2013 12:28 PM, spitfire_ch wrote:
> 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.
>


-- 
Tim Bish
Sr Software Engineer | RedHat Inc.
tim.bish@redhat.com | www.fusesource.com | www.redhat.com
skype: tabish121 | twitter: @tabish121
blog: http://timbish.blogspot.com/

www.camelone.org : The open source integration conference:


Re: NMS Active MQ: Error handling and debuggin in C#

Posted by Timothy Bish <ta...@gmail.com>.
Have a look at the failover documentation, the answer lies there: 
http://activemq.apache.org/nms/activemq-uri-configuration.html

On 10/21/2016 12:14 PM, ravican09 wrote:
> True
>
> activemq:failover:(tcp://brtuxjmsap02d.xxxx.net:61616)?transport.reconnectDelay=15000&transport.initialReconnectDelay=1000&connection.dispatchAsync=true
>
> is there any way i can get exception ,so that we can avoid program hang
>
> Thank you
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/NMS-Active-MQ-Error-handling-and-debuggin-in-C-tp4668567p4718245.html
> Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
>


-- 
Tim Bish
twitter: @tabish121
blog: http://timbish.blogspot.com/


Re: NMS Active MQ: Error handling and debuggin in C#

Posted by ravican09 <ra...@gmail.com>.
True 

activemq:failover:(tcp://brtuxjmsap02d.xxxx.net:61616)?transport.reconnectDelay=15000&transport.initialReconnectDelay=1000&connection.dispatchAsync=true

is there any way i can get exception ,so that we can avoid program hang

Thank you 



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

Re: NMS Active MQ: Error handling and debuggin in C#

Posted by Timothy Bish <ta...@gmail.com>.
You'd need to share the URI for anyone to know for sure, my guess would 
be you gave it a failover URI and it's sitting there trying to connect 
to a host that doesn't exist which is expected behavior

On 10/21/2016 11:20 AM, ravican09 wrote:
> Error handling does not work the way we would expect for some reason tester
> given  invalid urlQueue for the connectionFactory , the program simply
> hangs,
>
> below is the sample code
>
>
>   try
>                      {
>                          var connectionUri = new Uri(ConnectionUri);
>                          IConnectionFactory connectionFactory = new
> NMSConnectionFactory(connectionUri);
>                          Log.Debug(string.Format("NMS Event: Creating
> Connection: {0}", connectionUri));
>                          _connection =
> connectionFactory.CreateConnection(_userName, _password);
>                         Log.Debug(string.Format("NMS Event: Created
> Connection: {0}", connectionUri));
>                          if (_connection.IsStarted == false)
>                          {
>                              Log.Debug(string.Format("NMS Event: Starting
> Connection: {0}", connectionUri));
>                              _connection.Start();
>                              Log.Debug(string.Format("NMS Event: Started
> Connection: {0}", connectionUri));
>                          }
>                          _connection.ExceptionListener += ExceptionListener;
>                          _connection.ConnectionInterruptedListener +=
> ConnectionInterruptedListener;
>                          _connection.ConnectionResumedListener +=
> ConnectionResumedListener;
>                      }
>                      catch (Exception ex)
>                      {
>                          Log.Error("Error creating NMS Connection.", ex);
>                          throw;
>                      }
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/NMS-Active-MQ-Error-handling-and-debuggin-in-C-tp4668567p4718243.html
> Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
>


-- 
Tim Bish
twitter: @tabish121
blog: http://timbish.blogspot.com/


NMS Active MQ: Error handling and debuggin in C#

Posted by ravican09 <ra...@gmail.com>.
Error handling does not work the way we would expect for some reason tester
given  invalid urlQueue for the connectionFactory , the program simply
hangs,

below is the sample code 


 try
                    {
                        var connectionUri = new Uri(ConnectionUri);
                        IConnectionFactory connectionFactory = new
NMSConnectionFactory(connectionUri);
                        Log.Debug(string.Format("NMS Event: Creating
Connection: {0}", connectionUri));
                        _connection =
connectionFactory.CreateConnection(_userName, _password);
                       Log.Debug(string.Format("NMS Event: Created
Connection: {0}", connectionUri));
                        if (_connection.IsStarted == false)
                        {
                            Log.Debug(string.Format("NMS Event: Starting
Connection: {0}", connectionUri));
                            _connection.Start();
                            Log.Debug(string.Format("NMS Event: Started
Connection: {0}", connectionUri));
                        }
                        _connection.ExceptionListener += ExceptionListener;
                        _connection.ConnectionInterruptedListener +=
ConnectionInterruptedListener;
                        _connection.ConnectionResumedListener +=
ConnectionResumedListener;
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Error creating NMS Connection.", ex);
                        throw;
                    }



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

Re: NMS Active MQ: Error handling and debuggin in C#

Posted by spitfire_ch <pe...@bluewin.ch>.
Great, thanks for the hint, we will try that!



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