示例#1
0
        public async Task <Result> Create(Action <ExchangeCreateAction> action, CancellationToken cancellationToken = new CancellationToken())
        {
            cancellationToken.RequestCanceled();

            var impl = new ExchangeCreateActionImpl();

            action(impl);

            DefinedExchange definition = impl.Definition.Value;

            Debug.Assert(definition != null);

            string exchange = impl.ExchangeName.Value;
            string vhost    = impl.VirtualHost.Value;

            var errors = new List <Error>();

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

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

            if (string.IsNullOrWhiteSpace(definition?.RoutingType))
            {
                errors.Add(new ErrorImpl("The routing type of the exchange is missing."));
            }

            if (!impl.Errors.Value.IsNull())
            {
                errors.AddRange(impl.Errors.Value);
            }

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

            string url = $"api/exchanges/{SanitizeVirtualHostName(vhost)}/{exchange}";

            Result result = await Put(url, definition, cancellationToken);

            return(result);
        }
示例#2
0
        public async Task <Result> CreateAsync(Action <ExchangeCreateAction> action, CancellationToken cancellationToken = new CancellationToken())
        {
            cancellationToken.RequestCanceled(LogInfo);

            var impl = new ExchangeCreateActionImpl();

            action(impl);

            DefinedExchange definition = impl.Definition.Value;

            string exchange = impl.ExchangeName.Value;
            string vhost    = impl.VirtualHost.Value;

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

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

            if (string.IsNullOrWhiteSpace(definition?.RoutingType))
            {
                throw new ExchangeRoutingTypeMissingException("The routing type of the exchange is missing.");
            }

            string sanitizedVHost = vhost.SanitizeVirtualHostName();

            string url = $"api/exchanges/{sanitizedVHost}/{exchange}";

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

            Result result = response.GetResponse();

            LogInfo($"Sent request to RabbitMQ server to create exchange '{exchange}' in virtual host '{sanitizedVHost}'.");

            return(result);
        }
示例#3
0
        public async Task <Result> Create(Action <ExchangeCreateAction> action, CancellationToken cancellationToken = new CancellationToken())
        {
            cancellationToken.RequestCanceled();

            var impl = new ExchangeCreateActionImpl();

            action(impl);

            impl.Validate();

            ExchangeDefinition definition = impl.Definition.Value;

            Debug.Assert(definition != null);

            string url = $"api/exchanges/{impl.VirtualHost.Value.ToSanitizedName()}/{impl.ExchangeName.Value}";

            if (impl.Errors.Value.Any())
            {
                return(new FaultedResult(impl.Errors.Value, new DebugInfoImpl(url, definition.ToJsonString(Deserializer.Options))));
            }

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