Beispiel #1
0
        public void MethodReceived(AMQStateManager stateManager, AMQMethodEvent evt)
        {
            _logger.Debug("ConnectionTune frame received");
            ConnectionTuneBody frame   = (ConnectionTuneBody)evt.Method;
            AMQProtocolSession session = evt.ProtocolSession;

            ConnectionTuneParameters parameters = session.ConnectionTuneParameters;

            if (parameters == null)
            {
                parameters = new ConnectionTuneParameters();
            }

            _logger.Debug(String.Format("ConnectionTune.heartbeat = {0}.", frame.Heartbeat));

            parameters.FrameMax              = frame.FrameMax;
            parameters.Heartbeat             = frame.Heartbeat;
            session.ConnectionTuneParameters = parameters;

            stateManager.ChangeState(AMQState.CONNECTION_NOT_OPENED);
            session.WriteFrame(ConnectionTuneOkBody.CreateAMQFrame(
                                   evt.ChannelId, frame.ChannelMax, frame.FrameMax, frame.Heartbeat));
            session.WriteFrame(ConnectionOpenBody.CreateAMQFrame(
                                   evt.ChannelId, session.AMQConnection.VirtualHost, null, true));

            if (frame.Heartbeat > 0)
            {
                evt.ProtocolSession.AMQConnection.StartHeartBeatThread(frame.Heartbeat);
            }
        }
        public void MethodReceived(AMQStateManager stateManager, AMQMethodEvent evt)
        {
            ConnectionStartBody body = (ConnectionStartBody)evt.Method;
            AMQProtocolSession  ps   = evt.ProtocolSession;

            try
            {
                if (body.Mechanisms == null)
                {
                    throw new AMQException("mechanism not specified in ConnectionStart method frame");
                }
                string mechanisms        = Encoding.UTF8.GetString(body.Mechanisms);
                string selectedMechanism = ChooseMechanism(mechanisms);
                if (selectedMechanism == null)
                {
                    throw new AMQException("No supported security mechanism found, passed: " + mechanisms);
                }

                byte[] saslResponse = DoAuthentication(selectedMechanism, ps);

                if (body.Locales == null)
                {
                    throw new AMQException("Locales is not defined in Connection Start method");
                }
                string   allLocales = Encoding.ASCII.GetString(body.Locales);
                string[] locales    = allLocales.Split(' ');
                string   selectedLocale;
                if (locales != null && locales.Length > 0)
                {
                    selectedLocale = locales[0];
                }
                else
                {
                    throw new AMQException("No locales sent from server, passed: " + locales);
                }

                stateManager.ChangeState(AMQState.CONNECTION_NOT_TUNED);
                FieldTable clientProperties = new FieldTable();
                clientProperties["product"]  = "Apache.Qpid.NET";
                clientProperties["version"]  = "1.0";
                clientProperties["platform"] = GetFullSystemInfo();
                clientProperties["instance"] = ps.ClientID;
                AMQFrame frame = ConnectionStartOkBody.CreateAMQFrame(
                    evt.ChannelId, clientProperties, selectedMechanism,
                    saslResponse, selectedLocale);
                ps.WriteFrame(frame);
            }
            catch (Exception e)
            {
                throw new AMQException(_log, "Unable to decode data: " + e, e);
            }
        }