示例#1
0
            public void Close()
            {
                if (_session != null)
                {
                    _act();

                    var maxWait = RabbitClock.GetNow().AddSeconds(_parameters.MaxTimeWaitingToClose);
                    while (Interlocked.Read(ref _count) > 0)
                    {
                        if (maxWait < RabbitClock.GetNow())
                        {
                            Trace.WriteLine($"interrupt waiting closure subcriber {_parameters.Name}");
                            break;
                        }
                    }

                    try
                    {
                        RabbitInterceptor.Instance?.DisposeSessionRun(_broker, _session);
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine(e.Message);
                    }

                    _session.Close();
                    _session = null;
                }
            }
示例#2
0
            private async void _consumer_Received(object sender, BasicDeliverEventArgs e)
            {
                lock (_lock)
                    _nextWarnTime = RabbitClock.GetNow().AddSeconds((_watcher * 2) + 1);

                Interlocked.Increment(ref _count);

                IBrokerContext context = _factoryContext();

                if (context is IRabbitMessage message)
                {
                    message.Parameters = _parameters;
                    message.Broker     = _broker;
                    message.Message    = e;
                    message.Session    = _session;
                }

                try
                {
                    await _callback(context);
                }
                finally
                {
                    Interlocked.Decrement(ref _count);
                }
            }
示例#3
0
            public Session(int watcher, RabbitBroker broker, BrokerSubscriptionParameter parameters, Func <IBrokerContext, Task> callback, Func <IBrokerContext> factoryContext)
            {
                _nextWarnTime   = RabbitClock.GetNow().AddSeconds((watcher * 2) + 1);
                _broker         = broker;
                _parameters     = parameters;
                _callback       = callback;
                _watcher        = watcher;
                _factoryContext = factoryContext;
                _callback       = callback;
                _session        = broker.GetChannel();
                _session.BasicQos(0, (ushort)parameters.MaxParallelism, false);

                var _consumer = new EventingBasicConsumer(_session);

                _consumer.Received += _consumer_Received;

                _act = () =>
                {
                    _consumer.Received -= _consumer_Received;
                };


                if (broker.Configuration.ConfigAllowed)
                {
                    SetUpBindings(parameters, _session);
                }

                _session.BasicConsume(parameters.StorageQueueName, false, _consumer);
            }
示例#4
0
        /// <summary>
        /// AsyncMethod to append/send logs to rabbitMQ. Adds a new Task for each message to be published
        /// and commits and waits for all to finish. The maximum amount of publish per queue is set to 1000.
        /// </summary>
        /// <returns>Empty Task</returns>
        private async void Append(object state = null)
        {
            if (_session != null)
            {
                var status = _session.Status();
                if (status.Item1 < RabbitClock.GetNow())
                {
                    var count = await _broker.GetQueueDepth(_parameters.StorageQueueName);

                    if (count > 0)
                    {
                        Trace.WriteLine("network cut detected", TraceLevel.Error.ToString());
                    }
                }
            }
        }