You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by dipoody <de...@gmail.com> on 2017/11/07 06:52:52 UTC

ActiveMQ C# implementation - Unable to write data to the transport connection: An existing connection

Hi Team, 

I am getting the following error while try to establish ActiveMQ session 
after creating successful connection. 
*“Unable to write data to the transport connection: An existing connection 
was forcibly closed by the remote host” * 

I am using Apache.NMS.ActiveMQ dll for connecting to queue using C#.net. 

Some days back this was connecting to queue. I am using the URL to connect 
as following 
*"activemq:ssl://<URL>:4443?wireFormat.maxInactivityDuration=0"* 

Please find the code snippet used for connecting the queue: 

try 
            { 
                connecturi = new Uri(connectionURI); 
                try 
                { 
                    factory = new NMSConnectionFactory(connecturi); 
                } 
                catch (Exception ex) 
                { 
                    factory = new 
Apache.NMS.ActiveMQ.ConnectionFactory(connecturi); 
                } 
                //System.Net.ServicePointManager.Expect100Continue = false; 
                using (connection = factory.CreateConnection()) 
                { 
                   using (session = connection.CreateSession()) 
                   { 
                        destination = SessionUtil.GetDestination(session, 
"queue://<QueueName>"); //Name of the Queue 
                        using (consumer = 
session.CreateConsumer(destination)) 
                        {                           
                            connection.Start(); 
                            IMessage message; 
                            Thread.Sleep(1000); 
                            while ((message = 
consumer.Receive(TimeSpan.FromMilliseconds(100))) != null) 
                            { 
                                ITextMessage txtMsg = message as 
ITextMessage; 
                                string body = txtMsg.Text; 
                                resultSet.Add(body);                                 
                            } 
                        } 
                        if (session != null) 
                        { 
                            session.Close(); 
                        } 
                        if (connection != null) 
                        { 
                            connection.Close(); 
                            connection = null; 
                        } 
                        session = null; 
                    } 
                } 

            } 
            catch (Exception ex) 
            { 
                if (session != null) 
                { 
                    session.Close(); 
                } 
                if (connection != null) 
                { 
                    connection.Close(); 
                    connection = null; 
                } 
                session = null; 
                return resultSet; 
            } 

Could you guys please provide a solution for this? 




--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-Dev-f2368404.html