Ejemplo n.º 1
0
        /// <inheritdoc />
        public RemoveMessageStatus Remove(IMessageContext context, RemoveMessageReason reason)
        {
            if (!_configuration.Options().EnableHoldTransactionUntilMessageCommitted)
            {
                return(Remove(context.MessageId, reason));
            }

            var connection = context.Get(_headers.Connection);

            //if transaction held
            if (connection.Connection == null || connection.Transaction == null)
            {
                var counter = _deleteMessageCommand.Handle(new DeleteMessageCommand <long>((long)context.MessageId.Id.Value));
                return(counter > 0 ? RemoveMessageStatus.Removed : RemoveMessageStatus.NotFound);
            }

            //delete the message, and then commit the transaction
            var count = _deleteTransactionalMessageCommand.Handle(new DeleteTransactionalMessageCommand((long)context.MessageId.Id.Value, context));

            connection.Transaction.Commit();
            connection.Transaction = null;

            if (_configuration.Options().EnableStatusTable)
            {
                _deleteStatusCommandHandler.Handle(new DeleteStatusTableStatusCommand <long>((long)context.MessageId.Id.Value));
            }
            return(count > 0 ? RemoveMessageStatus.Removed : RemoveMessageStatus.NotFound);
        }
        /// <inheritdoc />
        public RemoveMessageStatus Remove(IMessageId id, RemoveMessageReason reason)
        {
            var header = _getHeader.GetHeaders(id);

            if (header != null)
            {
                var spanContext = header.Extract(_tracer, _headers);
                if (spanContext != null)
                {
                    using (IScope scope = _tracer.BuildSpan("Remove").AddReference(References.FollowsFrom, spanContext).StartActive(finishSpanOnDispose: true))
                    {
                        scope.Span.SetTag("RemovedBecause", reason.ToString());
                        return(_handler.Remove(id, reason));
                    }
                }
                else
                {
                    using (IScope scope = _tracer.BuildSpan("Remove").StartActive(finishSpanOnDispose: true))
                    {
                        scope.Span.AddMessageIdTag(id);
                        scope.Span.SetTag("RemovedBecause", reason.ToString());
                        return(_handler.Remove(id, reason));
                    }
                }
            }
            else
            {
                using (IScope scope = _tracer.BuildSpan("Remove").StartActive(finishSpanOnDispose: true))
                {
                    scope.Span.AddMessageIdTag(id);
                    scope.Span.SetTag("RemovedBecause", reason.ToString());
                    return(_handler.Remove(id, reason));
                }
            }
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public RemoveMessageStatus Remove(IMessageId id, RemoveMessageReason reason)
        {
            if (id == null || !id.HasValue)
            {
                return(RemoveMessageStatus.NotFound);
            }

            var result = _deleteMessage.Handle(new DeleteMessageCommand <string>(id.Id.Value.ToString()));

            return(result ? RemoveMessageStatus.Removed : RemoveMessageStatus.NotFound);
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public RemoveMessageStatus Remove(IMessageContext context, RemoveMessageReason reason)
        {
            var activityContext = context.Extract(_tracer, _headers);

            using (var scope = _tracer.StartActivity("Remove", ActivityKind.Internal, parentContext: activityContext))
            {
                scope?.AddMessageIdTag(context);
                scope?.SetTag("RemovedBecause", reason.ToString());
                return(_handler.Remove(context, reason));
            }
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        public RemoveMessageStatus Remove(IMessageId id, RemoveMessageReason reason)
        {
            if (id == null || !id.HasValue)
            {
                return(RemoveMessageStatus.NotFound);
            }

            var result = _deleteMessage.Handle(new DeleteMessageCommand((RedisQueueId)id));

            return(result ? RemoveMessageStatus.Removed : RemoveMessageStatus.NotFound);
        }
Ejemplo n.º 6
0
        /// <inheritdoc />
        public RemoveMessageStatus Remove(IMessageId id, RemoveMessageReason reason)
        {
            if (id != null && id.HasValue)
            {
                var result = _deleteMessageCommandHandler.Handle(new DeleteMessageCommand((long)id.Id.Value));
                if (result > 0)
                {
                    return(RemoveMessageStatus.Removed);
                }
            }

            return(RemoveMessageStatus.NotFound);
        }
Ejemplo n.º 7
0
        /// <inheritdoc />
        public RemoveMessageStatus Remove(IMessageId id, RemoveMessageReason reason)
        {
            if (id == null || !id.HasValue)
            {
                return(RemoveMessageStatus.NotFound);
            }
            var found = _dataStorage.DeleteMessage((Guid)id.Id.Value);

            if (found)
            {
                return(RemoveMessageStatus.Removed);
            }

            return(RemoveMessageStatus.NotFound);
        }
Ejemplo n.º 8
0
        /// <inheritdoc />
        public RemoveMessageStatus Remove(IMessageId id, RemoveMessageReason reason)
        {
            if (_configuration.Options().EnableHoldTransactionUntilMessageCommitted&& reason == RemoveMessageReason.Complete)
            {
                throw new DotNetWorkQueueException("Cannot use a transaction without the message context");
            }

            if (id == null || !id.HasValue)
            {
                return(RemoveMessageStatus.NotFound);
            }

            var count = _deleteMessageCommand.Handle(new DeleteMessageCommand <long>((long)id.Id.Value));

            return(count > 0 ? RemoveMessageStatus.Removed : RemoveMessageStatus.NotFound);
        }
Ejemplo n.º 9
0
        /// <inheritdoc />
        public RemoveMessageStatus Remove(IMessageContext context, RemoveMessageReason reason)
        {
            if (!_configuration.Options().EnableHoldTransactionUntilMessageCommitted)
            {
                return(Remove(context.MessageId, reason));
            }

            var connection = context.Get(_headers.Connection);

            //if transaction held
            if (connection.Connection == null || connection.Transaction == null)
            {
                var counter = _deleteMessageCommand.Handle(new DeleteMessageCommand((long)context.MessageId.Id.Value));
                return(counter > 0 ? RemoveMessageStatus.Removed : RemoveMessageStatus.NotFound);
            }

            //delete the message, and then commit the transaction
            var count = _deleteTransactionalMessageCommand.Handle(new DeleteTransactionalMessageCommand((long)context.MessageId.Id.Value, context));

            try
            {
                connection.Transaction.Commit();
            }
            catch (Exception e)
            {
                _log.ErrorException("Failed to commit a transaction; this might be due to a DB timeout", e);

                //don't attempt to use the transaction again at this point.
                connection.Transaction = null;

                throw;
            }

            //ensure that transaction won't be used anymore
            connection.Transaction.Dispose();
            connection.Transaction = null;

            if (_configuration.Options().EnableStatusTable)
            {
                _deleteStatusCommandHandler.Handle(new DeleteStatusTableStatusCommand((long)context.MessageId.Id.Value));
            }
            return(count > 0 ? RemoveMessageStatus.Removed : RemoveMessageStatus.NotFound);
        }
Ejemplo n.º 10
0
        /// <inheritdoc />
        public RemoveMessageStatus Remove(IMessageId id, RemoveMessageReason reason)
        {
            var header = _getHeader.GetHeaders(id);

            if (header != null)
            {
                var activityContext = header.Extract(_tracer, _headers);
                using (var scope = _tracer.StartActivity("Remove", ActivityKind.Internal, parentContext: activityContext))
                {
                    scope?.AddMessageIdTag(id);
                    scope?.SetTag("RemovedBecause", reason.ToString());
                    return(_handler.Remove(id, reason));
                }
            }
            using (var scope = _tracer.StartActivity("Remove"))
            {
                scope?.AddMessageIdTag(id);
                scope?.SetTag("RemovedBecause", reason.ToString());
                return(_handler.Remove(id, reason));
            }
        }
Ejemplo n.º 11
0
 /// <inheritdoc />
 public RemoveMessageStatus Remove(IMessageContext context, RemoveMessageReason reason)
 {
     return(Remove(context.MessageId, reason));
 }