public void CloseSession(AmqChannel channel) { // FIXME: Don't we need FailoverSupport here (as we have SyncWrite). _protocolSession.CloseSession(channel); AMQFrame frame = ChannelCloseBody.CreateAMQFrame( channel.ChannelId, 200, "JMS client closing channel", 0, 0); _log.Debug("Blocking for channel close frame for channel " + channel.ChannelId); _protocolWriter.SyncWrite(frame, typeof(ChannelCloseOkBody)); _log.Debug("Received channel close frame"); // When control resumes at this point, a reply will have been received that // indicates the broker has closed the channel successfully }
/// <summary> /// Convenience method that writes a frame to the protocol session and waits for /// a particular response. Equivalent to calling getProtocolSession().write() then /// waiting for the response. /// </summary> /// <param name="frame">the frame</param> /// <param name="listener">the blocking listener. Note the calling thread will block.</param> /// <param name="timeout">set the number of milliseconds to wait</param> private AMQMethodEvent SyncWrite(AMQFrame frame, BlockingMethodFrameListener listener, int timeout) { try { _protocolListener.AddFrameListener(listener); _protocolWriter.Write(frame); return(listener.BlockForFrame(timeout)); } finally { _protocolListener.RemoveFrameListener(listener); } // When control resumes before this line, a reply will have been received // that matches the criteria defined in the blocking listener }
public void MethodReceived(AMQStateManager stateManager, AMQMethodEvent evt) { _logger.Debug("ChannelClose method received"); ChannelCloseBody method = (ChannelCloseBody)evt.Method; int errorCode = method.ReplyCode; string reason = method.ReplyText; if (_logger.IsDebugEnabled) { _logger.Debug("Channel close reply code: " + errorCode + ", reason: " + reason); } AMQFrame frame = ChannelCloseOkBody.CreateAMQFrame(evt.ChannelId); evt.ProtocolSession.WriteFrame(frame); if (errorCode != AMQConstant.REPLY_SUCCESS.Code) { _logger.Debug("Channel close received with errorCode " + errorCode + ", throwing exception"); if (errorCode == AMQConstant.NO_CONSUMERS.Code) { throw new AMQNoConsumersException(reason); } if (errorCode == AMQConstant.NO_ROUTE.Code) { throw new AMQNoRouteException(reason); } if (errorCode == AMQConstant.INVALID_ARGUMENT.Code) { throw new AMQInvalidArgumentException(reason); } if (errorCode == AMQConstant.INVALID_ROUTING_KEY.Code) { throw new AMQInvalidRoutingKeyException(reason); } // any other throw new AMQChannelClosedException(errorCode, "Error: " + reason); } evt.ProtocolSession.ChannelClosed(evt.ChannelId, errorCode, reason); }
/// <summary> /// Convenience method that writes a frame to the protocol session and waits for /// a particular response. Equivalent to calling getProtocolSession().write() then /// waiting for the response. /// </summary> /// <param name="frame">the frame</param> /// <param name="responseType">the type of method response</param> /// <param name="timeout">set the number of milliseconds to wait</param> /// <returns>set the number of milliseconds to wait</returns> public AMQMethodEvent SyncWrite(AMQFrame frame, Type responseType, int timeout) { return(SyncWrite(frame, new SpecificMethodFrameListener(frame.Channel, responseType), timeout)); }
/// <summary> /// Convenience method that writes a frame to the protocol session and waits for /// a particular response. Equivalent to calling getProtocolSession().write() then /// waiting for the response. /// </summary> /// <param name="frame">the frame</param> /// <param name="responseType">the type of method response</param> public AMQMethodEvent SyncWrite(AMQFrame frame, Type responseType) { // TODO: If each frame knew it's response type, then the responseType argument would // TODO: not be neccesary. return(SyncWrite(frame, responseType, DefaultTimeouts.MaxWaitForSyncWriter)); }
public void OnMessage(IDataBlock message) { // Handle incorrect protocol version. if (message is ProtocolInitiation) { string error = String.Format("Protocol mismatch - {0}", message.ToString()); AMQException e = new AMQProtocolHeaderException(error); _log.Error("Closing connection because of protocol mismatch", e); //_protocolSession.CloseProtocolSession(); _stateManager.Error(e); return; } AMQFrame frame = (AMQFrame)message; // Console.WriteLine(">>> AMQFrame frame received: " + frame); //KHC if (frame.BodyFrame is AMQMethodBody) { if (_log.IsDebugEnabled) { _log.Debug("Method frame received: " + frame); } AMQMethodEvent evt = new AMQMethodEvent(frame.Channel, (AMQMethodBody)frame.BodyFrame, _protocolSession); try { bool wasAnyoneInterested = false; lock (_frameListeners.SyncRoot) { foreach (IAMQMethodListener listener in _frameListeners) { wasAnyoneInterested = listener.MethodReceived(evt) || wasAnyoneInterested; } } if (!wasAnyoneInterested) { throw new AMQException("AMQMethodEvent " + evt + " was not processed by any listener."); } } catch (Exception e) { foreach (IAMQMethodListener listener in _frameListeners) { listener.Error(e); } } } else if (frame.BodyFrame is ContentHeaderBody) { _protocolSession.MessageContentHeaderReceived(frame.Channel, (ContentHeaderBody)frame.BodyFrame); } else if (frame.BodyFrame is ContentBody) { _protocolSession.MessageContentBodyReceived(frame.Channel, (ContentBody)frame.BodyFrame); } else if (frame.BodyFrame is HeartbeatBody) { _log.Debug("HeartBeat received"); } else { Console.WriteLine("***** UNHANDLED FRAME ******"); } }