예제 #1
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);
                }
            }
예제 #2
0
        private Task Callback(IBrokerContext context)
        {
            ActionOrder order = ActionOrder.Unserialize(context.Utf8Data);

            if (_actionRepositories.Execute(order))
            {
                string Result = string.Empty;
                switch (order.Name)
                {
                case "business1.PushScan":
                    Result = ((Guid)order.Result).ToString("B");
                    break;

                default:
                    Result.ToString();
                    break;
                }

                _acknowledgeQueue.Publish(
                    new
                {
                    Order = order,
                    order.ExecutedAt,
                    Result
                }
                    );

                context.Commit();
            }
            else
            {
                if (context.CanBeRequeued())
                {
                    context.RequeueLast();
                }

                else
                {
                    var Exception = order.Result as Exception;
                    _deadQueue.Publish(
                        new
                    {
                        Order = order,
                        order.ExecutedAt,
                        order.PushedAt,
                        Exception
                    }
                        );

                    context.Reject();
                }
            }

            return(Task.CompletedTask);
        }
예제 #3
0
        private Task Callback(IBrokerContext context)
        {
            if (context.Headers.TryGetValue(_domainHeader, out object header))
            {
                var domain         = System.Text.Encoding.ASCII.GetString((byte[])header);
                var workflowEngine = _provider.Get(domain);

                try
                {
                    workflowEngine.EvaluateEvent(context.Utf8Data);

                    context.Commit();
                }
                catch (System.Exception exception)
                {
                    if (context.CanBeRequeued())
                    {
                        context.RequeueLast();
                    }

                    else
                    {
                        Dictionary <string, object> _headers = new Dictionary <string, object>();
                        foreach (var item in context.Headers)
                        {
                            _headers.Add(item.Key, System.Text.Encoding.ASCII.GetString((byte[])item.Value));
                        }

                        _deadQueue.Publish(
                            new
                        {
                            RepushedAt       = WorkflowClock.Now(),
                            OriginExchange   = context.Exchange,
                            OriginRoutingKey = context.RoutingKey,
                            context.Utf8Data,
                            Exception = exception,
                        },
                            _headers
                            );

                        context.Commit();
                    }
                }

                return(Task.CompletedTask);
            }

            throw new System.Exception($"missing domain header {_domainHeader}");
        }
예제 #4
0
        private Task Callback(IBrokerContext context)
        {
            var ctx = (ActionBusContext)_action.Evaluate(context.Utf8Data);

            if (ctx.Exception == null)
            {
                _acknowledgeQueue.Publish(
                    new
                {
                    context.Utf8Data,
                    Exception = ctx.Exception
                }
                    );

                context.Commit();
            }
            else
            {
                if (context.CanBeRequeued())
                {
                    context.RequeueLast();
                }

                else
                {
                    Dictionary <string, object> _headers = new Dictionary <string, object>();
                    foreach (var item in context.Headers)
                    {
                        _headers.Add(item.Key, System.Text.Encoding.ASCII.GetString((byte[])item.Value));
                    }

                    _deadQueue.Publish(
                        new
                    {
                        RepushedAt       = ClockActionBus.Now(),
                        OriginExchange   = context.Exchange,
                        OriginRoutingKey = context.RoutingKey,
                        ctx.Exception
                    },
                        _headers
                        );

                    context.Commit();
                }
            }

            return(Task.CompletedTask);
        }
예제 #5
0
 public MaxReplayException(int count, IBrokerContext context)
 {
     this.MaxReplay = count;
     this.Context   = context;
 }