public void MethodReceived(AMQStateManager stateManager, AMQMethodEvent evt) { _logger.Debug("ConnectionClose frame received"); ConnectionCloseBody method = (ConnectionCloseBody)evt.Method; int errorCode = method.ReplyCode; String reason = method.ReplyText; // send CloseOK evt.ProtocolSession.WriteFrame(ConnectionCloseOkBody.CreateAMQFrame(evt.ChannelId)); if (errorCode != AMQConstant.REPLY_SUCCESS.Code) { if (errorCode == AMQConstant.NOT_ALLOWED.Code) { _logger.Info("Authentication Error: " + Thread.CurrentThread.Name); evt.ProtocolSession.CloseProtocolSession(); //todo this is a bit of a fudge (could be conssidered such as each new connection needs a new state manager or at least a fresh state. stateManager.ChangeState(AMQState.CONNECTION_NOT_STARTED); throw new AMQAuthenticationException(errorCode, reason); } else { _logger.Info("Connection close received with error code " + errorCode); throw new AMQConnectionClosedException(errorCode, "Error: " + reason); } } // this actually closes the connection in the case where it is not an error. evt.ProtocolSession.CloseProtocolSession(); stateManager.ChangeState(AMQState.CONNECTION_CLOSED); }
private void CloseConnection() { _stateManager.ChangeState(AMQState.CONNECTION_CLOSING); AMQFrame frame = ConnectionCloseBody.CreateAMQFrame( 0, 200, "Qpid.NET client is closing the connection.", 0, 0); ProtocolWriter.Write(frame); _log.Debug("Blocking for connection close ok frame"); Disconnect(); }