示例#1
0
 public void HandleLinkFrame(AmqpFrame frame, ByteBuffer buffer = null)
 {
     lock (stateSyncRoot)
     {
         try
         {
             if (frame is Attach)
                 HandleAttachFrame(frame as Attach);
             else if (frame is Flow)
                 HandleFlowFrame(frame as Flow);
             else if (frame is Transfer)
                 HandleTransferFrame(frame as Transfer, buffer);
             else if (frame is Detach)
                 HandleDetachFrame(frame as Detach);
             else
                 throw new AmqpException(ErrorCode.IllegalState, $"Received frame {frame.Descriptor.ToString()} but link state is {State.ToString()}.");
         }
         catch (AmqpException amqpException)
         {
             trace.Error(amqpException);
             DetachLink(amqpException.Error, destoryLink: true);
         }
         catch (Exception fatalException)
         {
             trace.Fatal(fatalException, "Ending Session due to fatal exception.");
             var error = new Error()
             {
                 Condition = ErrorCode.InternalError,
                 Description = "Ending Session due to fatal exception: " + fatalException.Message,
             };
             DetachLink(error, destoryLink: true);
         }
     }
 }
示例#2
0
 internal void HandleSessionFrame(AmqpFrame frame, ByteBuffer buffer = null)
 {
     lock (stateSyncRoot)
     {
         try
         {
             if (frame is Begin)
                 HandleBeginFrame(frame as Begin);
             else if (frame is Attach)
                 InterceptAttachFrame(frame as Attach);
             else if (frame is Flow)
                 InterceptFlowFrame(frame as Flow);
             else if (frame is Transfer)
                 InterceptTransferFrame(frame as Transfer, buffer);
             else if (frame is Disposition)
                 InterceptDispositionFrame(frame as Disposition);
             else if (frame is Detach)
                 InterceptDetachFrame(frame as Detach);
             else if (frame is End)
                 HandleEndFrame(frame as End);
             else
                 throw new AmqpException(ErrorCode.IllegalState, $"Received frame {frame.Descriptor.ToString()} but session state is {State.ToString()}.");
         }
         catch (AmqpException amqpException)
         {
             trace.Error(amqpException);
             EndSession(amqpException.Error);
         }
         catch (Exception fatalException)
         {
             trace.Fatal(fatalException, "Ending Session due to fatal exception.");
             var error = new Error()
             {
                 Condition = ErrorCode.InternalError,
                 Description = "Ending Session due to fatal exception: " + fatalException.Message,
             };
             EndSession(error);
         }
     }
 }
示例#3
0
 protected void EncodeAndSend(AmqpFrame frame, ushort channelNumber = 0)
 {
     var buffer = new ByteBuffer(512, true);
     AmqpCodec.EncodeFrame(buffer, frame, channelNumber);
     connection.HandleFrame(buffer);
 }
示例#4
0
 public void SendFrame(AmqpFrame frame)
 {
     if (!State.CanSendFrames())
     {
         throw new AmqpException(ErrorCode.IllegalState, $"Cannot send frame when session state is {State.ToString()}.");
     }
     Connection.SendFrame(frame, ChannelNumber);
 }