public void Abort() { lock (connectionFactory) { aborting = true; consumer = null; model?.Abort(); model = null; connection?.Abort(); connection = null; } }
private void AbortIfErrors(IModel model, object userData) { if (model.HasErrors()) { model.Abort(); } }
private void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { _cancellationSource.Cancel(); _cancellationSource.Dispose(); if (_model != null) { if (_model.IsOpen) { _model.Abort(); } _model.Dispose(); } if (_connection != null) { if (_connection.IsOpen) { _connection.Close(); } _connection.Dispose(); } } _disposed = true; }
private void DisconnectFromRabbitMQ() { _isConsuming = false; try { if (_rabbitMQSubscription != null) { _rabbitMQSubscription.Close(); } } catch { } try { if (_rabbitMQConnection != null) { _rabbitMQConnection.Close(); } } catch { } try { if (_rabbitMQModel != null) { _rabbitMQModel.Abort(); } } catch { } _rabbitMQQueueName = null; }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { if (consumer != null && channel != null) { channel.BasicCancel(consumer.ConsumerTags.FirstOrDefault()); consumer = null; } if (channel != null) { channel.Abort(); channel.Dispose(); channel = null; } if (connection != null) { connection.Abort(); connection.Dispose(); connection = null; } } disposedValue = true; } }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { if (consumer != null && channel != null) { foreach (var tag in consumer.ConsumerTags) { channel.BasicCancel(tag); } consumer = null; } if (channel != null) { channel.Abort(); channel.Dispose(); channel = null; } if (connection != null) { connection.Abort(); connection.Dispose(); connection = null; } } disposedValue = true; } }
private void CreateChannel() { lock (ConsumerLock) { if (_channel != null && _channel.IsOpen && _connection.IsOpen) { return; } if (_channel != null && _channel.IsOpen) { _channel.Abort(); } if (!_connection.IsOpen) { _connection = _factory.CreateConnection(); } _channel = _connection.CreateModel(); _channel.BasicQos(0, 1, false); var properties = _channel.CreateBasicProperties(); properties.SetPersistent(true); // QueueDeclare is idempotent foreach (var queue in _queues) { _channel.QueueDeclare(queue, true, false, false, null); } } }
public static void stop() { channel.Close(200, "Goodbye"); channel.Abort(); connection.Close(); connection.Abort(); }
void CleanUpVirtualHost(IRabbitMqHost host) { try { _nameFormatter = new RabbitMqMessageNameFormatter(); ConnectionFactory connectionFactory = host.Settings.GetConnectionFactory(); using (IConnection connection = connectionFactory.CreateConnection()) using (IModel model = connection.CreateModel()) { model.ExchangeDelete("input_queue"); model.QueueDelete("input_queue"); model.ExchangeDelete("input_queue_skipped"); model.QueueDelete("input_queue_skipped"); model.ExchangeDelete("input_queue_error"); model.QueueDelete("input_queue_error"); model.ExchangeDelete("input_queue_delay"); model.QueueDelete("input_queue_delay"); OnCleanupVirtualHost(model); model.Abort(200, "Cleanup complete"); connection.Abort(200, "Cleanup complete"); } } catch (Exception exception) { Console.WriteLine(exception); } }
private void ShutdownAmqp(object sender, ShutdownEventArgs reason) { // I can't make this NOT hang when RMQ goes down // and then a log message is sent... var connection = sender as IConnection; try { if (_Model != null && _Model.IsOpen && reason.ReplyCode != Constants.ChannelError && reason.ReplyCode != Constants.ConnectionForced) { _Model.Abort(); //_Model.Close(); } } catch (Exception e) { InternalLogger.Error("could not close model, {0}", e); } try { if (connection != null && connection.IsOpen) { connection.ConnectionShutdown -= ShutdownAmqp; connection.Close(reason.ReplyCode, reason.ReplyText, 1000); connection.Abort(1000); // you get 2 seconds to shut down! } } catch (Exception e) { InternalLogger.Error("could not close connection, {0}", e); } }
public void Dispose() { isConsuming = false; if (consumer != null) { consumer = null; } if (Connection != null) { Connection.Close(); } if (channel != null) { channel.Abort(); } if (connectionFactory != null) { connectionFactory = null; } if (Connection != null) { Connection.Abort(); } if (e != null) { e = null; } }
private void ShutdownAmqp(IConnection connection, ShutdownEventArgs reason) { if (reason.ReplyCode != 200 /* Constants.ReplySuccess*/) { InternalLogger.Warn("RabbitMQTarget(Name={0}): Connection shutdown. ReplyCode={1}, ReplyText={2}", Name, reason.ReplyCode, reason.ReplyText); } else { InternalLogger.Info("RabbitMQTarget(Name={0}): Connection shutdown. ReplyCode={1}, ReplyText={2}", Name, reason.ReplyCode, reason.ReplyText); } lock (_sync) { if (connection != null) { IModel model = null; if (ReferenceEquals(connection, _Connection)) { model = _Model; _Connection = null; _Model = null; } try { if (reason.ReplyCode == 200 /* Constants.ReplySuccess*/ && connection.IsOpen) { model?.Close(); } else { model?.Abort(); // Abort is close without throwing Exceptions } } catch (Exception e) { InternalLogger.Error(e, "RabbitMQTarget(Name={0}): Could not close model: {1}", Name, e.Message); } try { // you get 1.5 seconds to shut down! if (reason.ReplyCode == 200 /* Constants.ReplySuccess*/ && connection.IsOpen) { connection.Close(reason.ReplyCode, reason.ReplyText, TimeSpan.FromMilliseconds(1500)); } else { connection.Abort(reason.ReplyCode, reason.ReplyText, TimeSpan.FromMilliseconds(1500)); } } catch (Exception e) { InternalLogger.Error(e, "RabbitMQTarget(Name={0}): Could not close connection: {1}", Name, e.Message); } } } }
public void Dispose() { lock (_lock) if (_model != null) { _model.Abort(); } }
protected override bool PublishInternal(CronusMessage message) { try { if (ReferenceEquals(null, connection) || connection.IsOpen == false) { lock (connectionFactory) { if (ReferenceEquals(null, connection) || connection.IsOpen == false) { connection?.Abort(); connection = connectionFactory.CreateConnection(); connection.AutoClose = false; } } } if (publishModel == null || publishModel.IsClosed) { publishModel = connection.CreateModel(); } IBasicProperties props = publishModel.CreateBasicProperties(); props.Headers = new Dictionary <string, object>() { { message.Payload.GetType().GetContractId(), string.Empty } }; props.Persistent = true; props.Priority = 9; byte[] body = this.serializer.SerializeToBytes(message); var publishDelayInMiliseconds = message.GetPublishDelay(); if (publishDelayInMiliseconds < 1000) { var exchangeName = RabbitMqNamer.GetExchangeName(message.Payload.GetType()); publishModel.BasicPublish(exchangeName, string.Empty, false, props, body); } else { var exchangeName = RabbitMqNamer.GetExchangeName(message.Payload.GetType()) + ".Scheduler"; props.Headers.Add("x-delay", message.GetPublishDelay()); publishModel.BasicPublish(exchangeName, string.Empty, false, props, body); } return(true); } catch (Exception ex) { publishModel?.Abort(); connection?.Abort(); connection = null; publishModel = null; return(false); } }
protected virtual void Dispose(bool disposing) { if (disposing) { Channel?.Abort(); Channel?.Dispose(); Channel = null; } }
private void Close() { isStopped = true; publishModel?.Abort(); connection?.Abort(); connection = null; publishModel = null; }
/// <inheritdoc /> public void EndConsume() { if (_channel != null) { _channel.Abort(); _channel.Dispose(); } _connection?.Dispose(); }
public TResponse CallRemoteProcedure <TResponse>(byte[] requestBytes, string channelName) { if (requestBytes == null) { throw new ArgumentNullException("Request bytes can't be null!"); } using (IModel channel = Connection.CreateModel()) { string replyQueueName = channel.QueueDeclare().QueueName; EventingBasicConsumer _consumer = new EventingBasicConsumer(channel); string correlationId = Guid.NewGuid().ToString(); IBasicProperties props = channel.CreateBasicProperties(); props.CorrelationId = correlationId; props.ReplyTo = replyQueueName; BlockingCollection <byte[]> respQueue = new BlockingCollection <byte[]>(); _consumer.Received += (model, ea) => { if (ea.BasicProperties.CorrelationId == correlationId) { respQueue.Add(ea.Body.ToArray()); } }; channel.BasicPublish("", channelName, props, requestBytes); channel.BasicConsume(_consumer, replyQueueName, true); byte[] data = new byte[0]; if (Timeout == 0) { data = respQueue.Take(); } else { DateTime started = DateTime.Now; DateTime expired = started.AddMilliseconds(Timeout); while (!respQueue.TryTake(out data)) { if (DateTime.Now > expired) { channel.Abort(); channel.Close(); throw new MqRpcResponseTimeout(); } } } return(data.ToObject <TResponse>()); } }
public virtual void Dispose() { if (disposed) { return; } channel.Abort(); channel.Dispose(); disposed = true; }
protected virtual void Dispose(bool disposing) { if (disposing) { Channel?.Abort(); Channel?.Dispose(); Channel = null; new RMQMessageGatewayConnectionPool(Connection.Name, Connection.Heartbeat).RemoveConnection(_connectionFactory); } }
public void Dispose() { if (Connection != null) { Connection.Close(); } if (Model != null) { Model.Abort(); } }
public void Dispose() { if (Connection != null && Connection.IsOpen) { Connection.Close(); } if (Channel != null) { Channel.Abort(); } }
public void Dispose() { if ((_connection != null) && _connection.IsOpen) { _connection.Close(); } if (_model != null) { _model.Abort(); } }
public void Dispose() { isConsuming = false; if (Connection != null) { Connection.Close(); } if (Model != null) { Model.Abort(); } }
public void Dispose() { if (connection != null && connection.IsOpen) { connection.Close(); } connection.Abort(); if (channel != null && channel.IsOpen) { channel.Close(); } channel.Abort(); }
public void CallToChildThread() { Console.WriteLine("Enter 'end' to stop"); string input = ""; while (input != "end") { input = Console.ReadLine(); } _kinectSensor.Close(); _channel.Abort(); connection.Close(); }
public void Dispose() { if (_consumer != null) { _consumer.Received -= ConsumerOnReceived; _consumer = null; } if (_model != null) { _model.Abort(); _model = null; } }
// // Channels // internal void WithTemporaryModel(Action <IModel> action) { IModel model = _conn.CreateModel(); try { action(model); } finally { model.Abort(); } }
protected void WithTemporaryModel(Action <IModel> action) { IModel model = Conn.CreateModel(); try { action(model); } finally { model.Abort(); } }
public void StopAndDispose() { if (_connection != null) { _connection.Close(); } if (_channel != null && _channel.IsOpen) { _channel.Abort(); } GC.SuppressFinalize(this); }
/// <summary> /// Called when [message]. /// </summary> /// <param name="message">The message.</param> /// <param name="channel">The channel.</param> /// <remarks></remarks> public void OnMessage(Message message, IModel channel) { var value = Encoding.UTF8.GetString(message.Body); logger.Debug("Receiving: " + value); if (this.failed.CompareAndSet(false, true)) { // intentional error (causes exception on connection thread): channel.Abort(); } else { this.latch.Signal(); } }
/// <summary>Called when [message].</summary> /// <param name="message">The message.</param> /// <param name="channel">The channel.</param> public void OnMessage(Message message, IModel channel) { var value = Encoding.UTF8.GetString(message.Body); Logger.Debug(m => m("Receiving: {0}", value)); if (this.failed.CompareAndSet(false, true)) { // intentional error (causes exception on connection thread): channel.Abort(); } else { if (this.latch.CurrentCount > 0) { this.latch.Signal(); Logger.Debug(m => m("Latch Count: {0}", this.latch.CurrentCount)); } } }
protected virtual void Close(IModel channel, ConnectionState state, Exception exception = null) { this.CurrentState = ConnectionState.Closing; if (channel != null) { Log.Debug("Aborting operations on temporary channel."); channel.Abort(); } if (this.connection != null) { Log.Debug("Blocking up to {0} ms before forcing the existing connection to close.", this.shutdownTimeout); // calling connection.TryDispose() can thrown while connection.Abort() closes without throwing this.connection.Abort(this.shutdownTimeout); } this.connection = null; this.CurrentState = state; if (exception != null) throw new ChannelConnectionException(exception.Message, exception); }
protected virtual void Close(IModel channel, ConnectionState state, Exception exception = null) { this.CurrentState = ConnectionState.Closing; if (channel != null) { Log.Debug("Aborting operations on temporary channel."); channel.Abort(); } this.TryAbortConnection(); this.connection = null; this.CurrentState = state; if (exception != null) throw new ChannelConnectionException(exception.Message, exception); }