Beispiel #1
0
        public async Task <Result <QueueInfo> > Peek(Action <QueuePeekAction> action, CancellationToken cancellationToken = default)
        {
            cancellationToken.RequestCanceled();

            var impl = new QueuePeekActionImpl();

            action(impl);

            DefinedQueuePeek definition = impl.Definition.Value;

            Debug.Assert(definition != null);

            var errors = new List <Error>();

            if (definition.Take < 1)
            {
                errors.Add(new ErrorImpl("Must be set a value greater than 1."));
            }

            if (string.IsNullOrWhiteSpace(definition.Encoding))
            {
                errors.Add(new ErrorImpl("Encoding must be set to auto or base64."));
            }

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

            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 <QueueInfo>(errors));
            }

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

            Result <QueueInfo> result = await Post <DefinedQueuePeek, QueueInfo>(url, definition, cancellationToken);

            return(result);
        }
Beispiel #2
0
        public async Task <Result> PeekAsync(Action <QueuePeekAction> action, CancellationToken cancellationToken = new CancellationToken())
        {
            cancellationToken.RequestCanceled(LogInfo);

            var impl = new QueuePeekActionImpl();

            action(impl);

            DefinedQueuePeek definition = impl.Definition.Value;

            if (definition.Take < 1)
            {
                throw new QueuePeekConfigurationException("Must be set a value greater than 1.");
            }

            if (string.IsNullOrWhiteSpace(definition.Encoding))
            {
                throw new QueuePeekConfigurationException("Encoding must be set to auto or base64.");
            }

            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}/get";

            HttpResponseMessage response = await HttpPost(url, definition, cancellationToken);

            Result result = response.GetResponse();

            LogInfo($"Sent request to RabbitMQ server to peek into queue '{queue}' on virtual host '{sanitizedVHost}' and pop {definition.Take} messages.");

            return(result);
        }