Ejemplo n.º 1
0
        public async Task Bind(ILinkExchage destination, ILinkExchage source, string routingKey = null,
                               IDictionary <string, object> arguments = null)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            if (routingKey == null)
            {
                routingKey = string.Empty;
            }

            if (arguments == null)
            {
                arguments = new Dictionary <string, object>();
            }

            await _invoker
            .InvokeAsync(model => model.ExchangeBind(destination.Name, source.Name, routingKey, arguments))
            .ConfigureAwait(false);

            _logger.Debug(
                $"Bound destination exchange {destination.Name} to source exchange {source.Name} with routing key {routingKey} and arguments: {string.Join(", ", arguments.Select(x => $"{x.Key} = {x.Value}"))}");
        }
Ejemplo n.º 2
0
        public async Task Bind(ILinkQueue queue, ILinkExchage exchange, string routingKey = null,
                               IDictionary <string, object> arguments = null)
        {
            if (exchange == null)
            {
                throw new ArgumentNullException(nameof(exchange));
            }

            if (queue == null)
            {
                throw new ArgumentNullException(nameof(queue));
            }

            if (routingKey == null)
            {
                routingKey = string.Empty;
            }

            if (arguments == null)
            {
                arguments = new Dictionary <string, object>();
            }

            await _invoker
            .InvokeAsync(model => model.QueueBind(queue.Name, exchange.Name, routingKey, arguments))
            .ConfigureAwait(false);

            _logger.Debug(
                $"Bound queue {queue.Name} to exchange {exchange.Name} with routing key {routingKey} and arguments: {string.Join(", ", arguments.Select(x => $"{x.Key} = {x.Value}"))}");
        }
Ejemplo n.º 3
0
        public async Task ExchangeDelete(ILinkExchage exchange, bool ifUnused = false)
        {
            if (exchange == null)
            {
                throw new ArgumentNullException(nameof(exchange));
            }

            await _invoker
            .InvokeAsync(model => model.ExchangeDelete(exchange.Name, ifUnused))
            .ConfigureAwait(false);

            _logger.Debug($"Deleted exchange \"{exchange.Name}\", unused: {ifUnused}");
        }
Ejemplo n.º 4
0
        private async Task <bool> ConfigureAsync(IModel model, bool retry, CancellationToken cancellation)
        {
            if (retry)
            {
                try
                {
                    _logger.Debug($"Retrying in {_configuration.RecoveryInterval.TotalSeconds:0.###}s");
                    await Task.Delay(_configuration.RecoveryInterval, cancellation)
                    .ConfigureAwait(false);
                }
                catch
                {
                    return(false);
                }
            }

            _logger.Debug("Configuring topology");

            try
            {
                _exchage = await _topologyRunner
                           .RunAsync(model, cancellation)
                           .ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _logger.Warning($"Exception on topology configuration: {ex}");

                try
                {
                    await _configuration.TopologyHandler.ConfigurationError(ex)
                    .ConfigureAwait(false);
                }
                catch (Exception handlerException)
                {
                    _logger.Error($"Exception in topology error handler: {handlerException}");
                }

                return(false);
            }

            _logger.Debug("Topology configured");

            return(true);
        }