Esempio n. 1
0
 public static void CloseChannel(RC.IModel channel, ILogger logger = null)
 {
     if (channel != null)
     {
         try
         {
             channel.Close();
         }
         catch (AlreadyClosedException)
         {
             // empty
         }
         catch (ShutdownSignalException sig)
         {
             if (!IsNormalShutdown(sig))
             {
                 logger?.LogDebug(sig, "Unexpected exception on closing RabbitMQ Channel");
             }
         }
         catch (Exception ex)
         {
             logger?.LogDebug(ex, "Unexpected exception on closing RabbitMQ Channel");
         }
     }
 }
        private void SubsManager_OnEventRemoved(object sender, string eventName)
        {
            if (!_persistentConnection.IsConnected)
            {
                _persistentConnection.TryConnect();
            }

            using (var channel = _persistentConnection.CreateModel())
            {
                channel.QueueUnbind(queue: _queueName,
                                    exchange: BROKER_NAME,
                                    routingKey: eventName);

                if (_subsManager.IsEmpty)
                {
                    _queueName = string.Empty;
                    _consumerChannel.Close();
                }
            }
        }
Esempio n. 3
0
        } // MakeNewConnection

        private void DestroyConnection(ref RmqCl.IConnection connection, ref RmqCl.IModel channel)
        {
            // This method disposes the AMQP-connection-related object

            try
            {
                if (channel != null)
                {
                    if (m_messageConsumer != null)
                    {
                        m_messageConsumer.Received -= MessageReceived;
                    }

                    try
                    {
                        channel.ModelShutdown -= ModelShutdown;
                        channel.Close();
                    }
                    catch { }
                    channel.Dispose();
                    channel = null;
                }

                if (connection != null)
                {
                    try
                    {
                        connection.Close();
                    }
                    catch { }
                    connection.Dispose();
                    connection = null;
                }
            }
            catch {}
        } // DestroyConnection