예제 #1
0
        protected override void Write(AsyncLogEventInfo logEvent)
        {
            AsyncContinuation continuation    = logEvent.Continuation;
            IBasicProperties  basicProperties = GetBasicProperties(logEvent);

            byte[] numArray = CompressMessage(GetMessage(logEvent));
            string topic    = GetTopic(logEvent.LogEvent);

            if (_model == null || !_model.IsOpen)
            {
                StartConnection();
            }
            if (_model != null)
            {
                if (_model.IsOpen)
                {
                    try
                    {
                        CheckUnsent();
                        Publish(numArray, basicProperties, topic);
                        return;
                    }
                    catch (IOException ex)
                    {
                        AddUnsent(topic, basicProperties, numArray);
                        continuation.Invoke(ex);
                    }
                    catch (ObjectDisposedException ex)
                    {
                        AddUnsent(topic, basicProperties, numArray);
                        continuation.Invoke(ex);
                    }
                    ShutdownAmqp(_connection, new ShutdownEventArgs(0, 504, "Could not talk to RabbitMQ instance"));
                    return;
                }
            }
            AddUnsent(topic, basicProperties, numArray);
        }
예제 #2
0
        protected void EndRequest(AsyncContinuation asyncContinuation, Exception pendingException)
        {
            lock (_pendingRequests)
            {
                _asyncOperationInProgress = false;

                if (pendingException != null)
                {
                    _pendingError = pendingException;
                }

                asyncContinuation?.Invoke(pendingException);    // Will attempt to close socket on error

                ProcessNextQueuedItem();
            }
        }