Exemplo n.º 1
0
        private void RetryPublishData(StoredSubject subject, Exception exception)
        {
            try
            {
                if (subject != null && Setting.RetryTimes > 0 && subject.AcceptRetries < Setting.RetryTimes)
                {
                    if (_notification != null)
                    {
                        var context = new SubscribeNotificationContext(subject.Name, subject.Body, exception);
                        _notification.OnConsumeError(context);
                        if (!context.CanRetry)
                        {
                            return;
                        }
                    }

                    Task.Run(() =>
                    {
                        Thread.Sleep((int)Setting.RetryDelayTime.TotalMilliseconds);
                        try
                        {
                            var client = GetConnection(null);
                            subject.AcceptRetries++;
                            PublishSubject(client, subject);
                        }
                        catch (Exception exp)
                        {
                            PersistSubject(subject, exp);
                        }
                    });
                }
            }
            catch { }
        }
Exemplo n.º 2
0
        private void PersistSubject(StoredSubject subject, Exception exception)
        {
            if (_persistance != null && subject.PublishRetries == 0)
            {
                if (_notification != null)
                {
                    var context = new SubscribeNotificationContext(subject.Name, subject.Body, exception);
                    _notification.OnPublishError(context);
                    if (!context.CanRetry)
                    {
                        return;
                    }
                }

                if (_persistance.SaveSubject("rabbit", subject))
                {
                    Tracer.Debug($"{_persistance} was persisted of '{subject.Name}'.");
                }
            }
        }
Exemplo n.º 3
0
        private void RetryPublishData(CustomEventingBasicConsumer consumer, BasicDeliverEventArgs args, StoredSubject subject, Exception exception)
        {
            try
            {
                if (!consumer.Model.IsOpen)
                {
                    return;
                }

                consumer.Model.BasicNack(args.DeliveryTag, false, false);

                if (subject != null && Setting.RetryTimes > 0 && subject.AcceptRetries < Setting.RetryTimes)
                {
                    if (_notification != null)
                    {
                        var context = new SubscribeNotificationContext(subject.Name, subject.Body, exception);
                        _notification.OnConsumeError(context);
                        if (!context.CanRetry)
                        {
                            return;
                        }
                    }

                    Task.Run(() =>
                    {
                        Thread.Sleep((int)Setting.RetryDelayTime.TotalMilliseconds);
                        try
                        {
                            subject.AcceptRetries++;
                            PublishSubject(subject);
                        }
                        catch (Exception exp)
                        {
                            PersistSubject(subject, exp);
                        }
                    });
                }
            }
            catch { }
        }