Esempio n. 1
0
        public async Task <Result> EmptyAsync(Action <QueueEmptyAction> action, CancellationToken cancellationToken = new CancellationToken())
        {
            cancellationToken.RequestCanceled(LogInfo);

            var impl = new QueueEmptyActionImpl();

            action(impl);

            string queue = impl.QueueName.Value;
            string vhost = impl.VirtualHost.Value;

            if (string.IsNullOrWhiteSpace(queue))
            {
                throw new QueueMissingException("The name of the queue is missing.");
            }

            if (string.IsNullOrWhiteSpace(vhost))
            {
                throw new VirtualHostMissingException("The name of the virtual host is missing.");
            }

            string sanitizedVHost = vhost.SanitizeVirtualHostName();

            string url = $"api/queues/{sanitizedVHost}/{queue}/contents";

            HttpResponseMessage response = await HttpDelete(url, cancellationToken);

            Result result = response.GetResponse();

            LogInfo($"Sent request to RabbitMQ server to empty queue '{queue}' on virtual host '{sanitizedVHost}'.");

            return(result);
        }
Esempio n. 2
0
        public async Task <Result> Empty(Action <QueueEmptyAction> action, CancellationToken cancellationToken = default)
        {
            cancellationToken.RequestCanceled();

            var impl = new QueueEmptyActionImpl();

            action(impl);

            string queue = impl.QueueName.Value;
            string vhost = impl.VirtualHost.Value;

            var errors = new List <Error>();

            if (string.IsNullOrWhiteSpace(vhost))
            {
                errors.Add(new ErrorImpl("The name of the virtual host is missing."));
            }

            if (string.IsNullOrWhiteSpace(queue))
            {
                errors.Add(new ErrorImpl("The name of the queue is missing."));
            }

            if (errors.Any())
            {
                return(new FaultedResult(errors));
            }

            string url = $"api/queues/{SanitizeVirtualHostName(vhost)}/{queue}/contents";

            Result result = await Delete(url, cancellationToken);

            return(result);
        }
Esempio n. 3
0
        public async Task <Result> Empty(Action <QueueEmptyAction> action, CancellationToken cancellationToken = default)
        {
            cancellationToken.RequestCanceled();

            var impl = new QueueEmptyActionImpl();

            action(impl);

            impl.Validate();

            string url = $"api/queues/{impl.VirtualHost.Value.ToSanitizedName()}/{impl.QueueName.Value}/contents";

            if (impl.Errors.Value.Any())
            {
                return(new FaultedResult <QueueInfo>(impl.Errors.Value, new DebugInfoImpl(url)));
            }

            return(await Delete(url, cancellationToken).ConfigureAwait(false));
        }