/// <summary> /// Connect to the specified broker /// </summary> /// <param name="broker">The broker to connect to</param> /// <param name="connection">The AMQ connection</param> public void Connect(IBrokerInfo broker, AMQConnection connection) { _stopEvent = new ManualResetEvent(false); _protocolListener = connection.ProtocolListener; _ioHandler = MakeBrokerConnection(broker, connection); // todo: get default read size from config! IProtocolDecoderOutput decoderOutput = new ProtocolDecoderOutput(_protocolListener); _amqpChannel = new AmqpChannel(new ByteChannel(_ioHandler), decoderOutput); // post an initial async read _amqpChannel.BeginRead(new AsyncCallback(OnAsyncReadDone), this); }
private void OnAsyncReadDone(IAsyncResult result) { try { _amqpChannel.EndRead(result); bool stopping = _stopEvent.WaitOne(0, false); if (!stopping) { _amqpChannel.BeginRead(new AsyncCallback(OnAsyncReadDone), null); } } catch (Exception e) { // ignore any errors during closing bool stopping = _stopEvent.WaitOne(0, false); if (!stopping) { _protocolListener.OnException(e); } } }