Esempio n. 1
0
 private void InvokeChannelActionInternal(Action <IModel> channelAction, DateTime startTime)
 {
     if (IsTimedOut(startTime))
     {
         logger.ErrorWrite("Channel action timed out. Throwing exception to client.");
         throw new TimeoutException("The operation requested on PersistentChannel timed out.");
     }
     try
     {
         channelAction(Channel);
     }
     catch (OperationInterruptedException exception)
     {
         try
         {
             var amqpException = AmqpExceptionGrammar.ParseExceptionString(exception.Message);
             if (amqpException.Code == AmqpException.ConnectionClosed)
             {
                 OnConnectionDisconnected(null);
                 WaitForReconnectionOrTimeout(startTime);
                 InvokeChannelActionInternal(channelAction, startTime);
             }
             else
             {
                 throw;
             }
         }
         catch (Sprache.ParseException)
         {
             throw exception;
         }
     }
 }
Esempio n. 2
0
        public void Should_fail_on_badly_formatted_exception()
        {
            Assert.Throws <Sprache.ParseException>(() => {
                const string originalException = "Do be do od be do do = something else, that I don't know=hello";

                AmqpExceptionGrammar.ParseExceptionString(originalException);
            });
        }
Esempio n. 3
0
 private static bool NeedRethrow(OperationInterruptedException exception)
 {
     try
     {
         var amqpException = AmqpExceptionGrammar.ParseExceptionString(exception.Message);
         return(amqpException.Code != AmqpException.ConnectionClosed);
     }
     catch (ParseException)
     {
         return(true);
     }
 }
Esempio n. 4
0
        public void Should_parse_first_Amqp_exception_example()
        {
            const string originalException =
                "The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=320, " +
                "text=\"CONNECTION_FORCED - Closed via management plugin\", classId=0, methodId=0, cause=";

            var amqpException = AmqpExceptionGrammar.ParseExceptionString(originalException);

            amqpException.Preface.Text.ShouldEqual("The AMQP operation was interrupted");
            amqpException.Code.ShouldEqual(320);
            amqpException.MethodId.ShouldEqual(0);
            amqpException.ClassId.ShouldEqual(0);
        }
Esempio n. 5
0
        public void Should_parse_second_Amqp_exception_example()
        {
            const string originalException =
                "The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=406, " +
                "text=\"PRECONDITION_FAILED - cannot redeclare exchange 'myExchange' in vhost '/' " +
                "with different type, durable, internal or autodelete value\", classId=40, methodId=10, cause=";

            var amqpException = AmqpExceptionGrammar.ParseExceptionString(originalException);

            amqpException.Preface.Text.ShouldEqual("The AMQP operation was interrupted");
            amqpException.Code.ShouldEqual(406);
            amqpException.MethodId.ShouldEqual(10);
            amqpException.ClassId.ShouldEqual(40);
        }
Esempio n. 6
0
 private void InvokeChannelActionInternal(Action <IModel> channelAction, DateTime startTime)
 {
     if (this.IsTimedOut(startTime))
     {
         ConsoleLogger.ErrorWrite("Channel action timed out. Throwing exception to client.");
         throw new TimeoutException("The operation requested on PersistentChannel timed out.");
     }
     try
     {
         channelAction(this.Channel);//执行这个方法,ClientCommandDispatcherSingleton类的Invoke<T>方法中定义的cs.SetResult(channelAction(channel));话会被执行。
     }
     catch (OperationInterruptedException exception)
     {
         try
         {
             AmqpException amqpException = AmqpExceptionGrammar.ParseExceptionString(exception.Message);//将AMQP错误信息,转成C#定义的异常类型
             if (amqpException.Code == AmqpException.ConnectionClosed)
             {
                 this.OnConnectionDisconnected(null);
                 this.WaitForReconnectionOrTimeout(startTime);
                 this.InvokeChannelActionInternal(channelAction, startTime);
             }
             else
             {
                 this.OpenChannel();
                 throw;
             }
         }
         catch (Sprache.ParseException)
         {
             throw exception;
         }
     }
     catch (Exception)
     {
         this.OnConnectionDisconnected(null);
         this.WaitForReconnectionOrTimeout(startTime);
         this.InvokeChannelActionInternal(channelAction, startTime);
     }
 }