You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@activemq.apache.org by "JIANPING (JIRA)" <ji...@apache.org> on 2015/09/23 11:14:04 UTC

[jira] [Created] (AMQNET-510) When the topic broker keep coming messages, cannot disconnect

JIANPING created AMQNET-510:
-------------------------------

             Summary: When the topic broker keep coming messages, cannot disconnect
                 Key: AMQNET-510
                 URL: https://issues.apache.org/jira/browse/AMQNET-510
             Project: ActiveMQ .Net
          Issue Type: Bug
          Components: ActiveMQ, NMS
    Affects Versions: 1.7.0
         Environment: Client: Windows 7 32 bit; DotNET framework 4.0
Server: Centos OS 5.6; ActiveMQ 5.10
            Reporter: JIANPING
            Assignee: Jim Gomes


We have a production envrionment like below:
1. Client UI start, subscribe to server, the topic
2. That topic has a lot of messages coming, 60 messages per second
3. But, we want to close the connect before close the UI
4. After we debug into, found the process hang up at the session close portion.

Sample code:

public bool ReceiveUpdateMessageFromServer()
        {
            bool result = false;
            try
            {
                StartConnection();

                Console.WriteLine("Update connection started...");

                sessionUpdate = connectionRec.CreateSession(AcknowledgementMode.AutoAcknowledge);

                Console.WriteLine("Update session created...");

                if (!connectionRec.IsStarted)
                    connectionRec.Start();

                if (this.strTesterID != "")
                {
                    topicConsumer = sessionUpdate.GetTopic(this.strUpdateTopic);
                    string strJMSSelector = "TESTERID='" + this.strTesterID + "'";
                    consumerUpdate = sessionUpdate.CreateConsumer(topicConsumer, strJMSSelector);
                }
                else if (consumerUpdate == null)
                {
                    destinationRec = sessionUpdate.GetTopic(this.strUpdateTopic);
                    consumerUpdate = sessionUpdate.CreateConsumer(destinationRec);
                }
                Console.WriteLine("Consumer started ...");

                Console.WriteLine("Update session started...");

                consumerUpdate.Listener += (message =>
                {
                    OnUpdateMessageReceived(message);
                });
                
                result = true;
            }
            catch (Exception exMsgRec)
            {
                if (!exMsgRec.Message.Contains("already connected"))
                {
                    StopReceiveUpdateMessageFromServer();
                    throw exMsgRec;
                }
            }
            finally
            {
            }

            return result;
        }

	public void StopReceiveUpdateMessageFromServer()
        {
            try
            {
                #region Consumer Close

                if (consumerUpdate != null)
                {
                    try
                    {
                        consumerUpdate.Close();

                        Console.WriteLine("Consumer stopped...");
                    }
                    catch (Exception exClose)
                    {
                        if (exClose.Message != "Object reference not set to an instance of an object.")
                            throw exClose;
                    }

                    consumerUpdate.Dispose();
                    consumerUpdate = null;

                }

                #endregion

                #region Session Close

                if (sessionUpdate != null)
                {
                    try
                    {
                        sessionUpdate.Close();

                        Console.WriteLine("Session stopped...");
                    }
                    catch (Exception exClose)
                    {
                        if (exClose.Message != "Object reference not set to an instance of an object.")
                            throw exClose;
                    }

		    //# The process hang up here, don't why
                    sessionUpdate.Dispose();
                    sessionUpdate = null;

                }

                #endregion

                #region Connection Close

                lock (this)
                {
                    if (connectionRec != null)
                    {
                        try
                        {
                            connectionRec.Close();

                            Console.WriteLine("Connection stopped...");
                        }
                        catch (Exception exClose)
                        {
                            if (exClose.Message != "Object reference not set to an instance of an object.")
                                throw exClose;
                        }

                        connectionRec.Dispose();
                        connectionRec = null;
                    }
                }
                #endregion


                if (destinationRec != null)
                {
                    destinationRec = null;
                }
                if (factoryRec != null)
                {
                    factoryRec = null;
                }
            }
            catch (Exception exRecMessage)
            {
                if (exRecMessage.Message != "Object reference not set to an instance of an object.")
                    throw exRecMessage;
            }
        }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)