public async Task Bind(ILinkExchange destination, ILinkExchange 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}"))}"); }
private void Dispose(bool byChannel) { if (State == LinkConsumerState.Disposed) { return; } lock (_sync) { if (State == LinkConsumerState.Disposed) { return; } _logger.Debug($"Disposing ( by channel: {byChannel} )"); _channel.Disposed -= ChannelOnDisposed; if (!byChannel) { _channel.Dispose(); } var ex = new ObjectDisposedException(GetType().Name); ChangeState(LinkConsumerState.Disposed); _readyCompletion.TrySetException(ex); _logger.Debug("Disposed"); _logger.Dispose(); Disposed?.Invoke(this, EventArgs.Empty); } }
public LinkChannel(ILinkConnection connection, LinkStateHandler <LinkChannelState> stateHandler, TimeSpan recoveryInterval) : base(LinkChannelState.Init) { _connection = connection ?? throw new ArgumentNullException(nameof(connection)); _logger = connection.Configuration.LoggerFactory.CreateLogger($"{GetType().Name}({Id:D})") ?? throw new ArgumentException("Cannot create logger", nameof(connection.Configuration.LoggerFactory)); if (recoveryInterval <= TimeSpan.Zero) { throw new ArgumentOutOfRangeException(nameof(recoveryInterval), "Must be greater than zero"); } _stateHandler = stateHandler ?? throw new ArgumentNullException(nameof(stateHandler)); _recoveryInterval = recoveryInterval; _disposeCts = new CancellationTokenSource(); _disposeCancellation = _disposeCts.Token; _connection.Disposed += ConnectionOnDisposed; _logger.Debug($"Created(connectionId: {_connection.Id:D})"); }
private void Dispose(bool byConnection) { if (State == LinkChannelState.Disposed) { return; } lock (_sync) { if (State == LinkChannelState.Disposed) { return; } _logger.Debug($"Disposing ( by connection: {byConnection} )"); _disposeCts.Cancel(); _disposeCts.Dispose(); try { _loopTask?.Wait(CancellationToken.None); } catch { // no op } _connection.Disposed -= ConnectionOnDisposed; ChangeState(LinkChannelState.Disposed); Disposed?.Invoke(this, EventArgs.Empty); _logger.Debug("Disposed"); _logger.Dispose(); } }
protected override void OnStateChange(LinkProducerState newState) { _logger.Debug($"State change {State} -> {newState}"); try { _configuration.StateHandler(State, newState); } catch (Exception ex) { _logger.Warning($"Exception in state handler: {ex}"); } base.OnStateChange(newState); }
public LinkProducer( LinkProducerConfiguration configuration, ILinkChannel channel ) : base(LinkProducerState.Init) { _configuration = configuration; _channel = channel ?? throw new ArgumentNullException(nameof(channel)); _logger = _channel.Connection.Configuration.LoggerFactory.CreateLogger($"{GetType().Name}({Id:D})") ?? throw new InvalidOperationException("Cannot create logger"); _topologyRunner = new LinkTopologyRunner <ILinkExchange>(_logger, _configuration.TopologyHandler.Configure); _appId = _channel.Connection.Configuration.AppId; _channel.Disposed += ChannelOnDisposed; _logger.Debug($"Created(channelId: {_channel.Id})"); _channel.Initialize(this); }
public LinkTopology(ILinkChannel channel, LinkTopologyConfiguration configuration) : base(LinkTopologyState.Init) { _channel = channel ?? throw new ArgumentNullException(nameof(channel)); _configuration = configuration; _logger = _channel.Connection.Configuration.LoggerFactory.CreateLogger($"{GetType().Name}({Id:D})") ?? throw new InvalidOperationException("Cannot create logger"); _topologyRunner = new LinkTopologyRunner <object>(_logger, async cfg => { await _configuration.TopologyHandler.Configure(cfg) .ConfigureAwait(false); return(null); }); _channel.Disposed += ChannelOnDisposed; _logger.Debug($"Created(channelId: {_channel.Id})"); _channel.Initialize(this); }
public LinkConnection(LinkConfiguration configuration) : base(LinkConnectionState.Init) { _configuration = configuration; _logger = _configuration.LoggerFactory.CreateLogger($"{GetType().Name}({Id:D})") ?? throw new ArgumentException("Cannot create logger", nameof(configuration.LoggerFactory)); _connectionFactory = new LinkConnectionFactory( _configuration.ConnectionName, _configuration.AppId, _configuration.ConnectionString, _configuration.Timeout, _configuration.UseBackgroundThreadsForConnection ); _disposeCts = new CancellationTokenSource(); _disposeCancellation = _disposeCts.Token; _logger.Debug($"Created ( name: {_configuration.ConnectionName})"); if (_configuration.AutoStart) { Initialize(); } }
public void Dispose() { if (State == LinkConnectionState.Disposed) { return; } lock (_sync) { if (State == LinkConnectionState.Disposed) { return; } _logger.Debug("Disposing"); _disposeCts.Cancel(); _disposeCts.Dispose(); try { _loopTask?.Wait(CancellationToken.None); } catch { // no op } _storage.Dispose(); ChangeState(LinkConnectionState.Disposed); Disposed?.Invoke(this, EventArgs.Empty); _logger.Debug("Disposed"); _logger.Dispose(); } }
protected override void OnStateChange(LinkTopologyState newState) { _logger.Debug($"State change {State} -> {newState}"); base.OnStateChange(newState); }
public LinkChannel(LinkConfiguration configuration, ILinkConnection connection) { if (configuration == null) throw new ArgumentNullException(nameof(configuration)); if (connection == null) throw new ArgumentNullException(nameof(connection)); _configuration = configuration; _logger = _configuration.LoggerFactory.CreateLogger($"{GetType().Name}({Id:D})"); if (_logger == null) throw new ArgumentException("Cannot create logger", nameof(configuration.LoggerFactory)); _disposedCancellationSource = new CancellationTokenSource(); _disposedCancellation = _disposedCancellationSource.Token; Connection = connection; Connection.Disposed += ConnectionOnDisposed; Connection.Connected += ConnectionOnConnected; _logger.Debug($"Created(connectionId: {Connection.Id:D})"); ScheduleReopen(false); }