Exemplo n.º 1
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);
        }
Exemplo n.º 2
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}");
        }
Exemplo n.º 3
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);
        }