public void Consumer <T>(ConnectionFactory factory, string queueName, T consume, bool noAck) where T : IBaseConsumer { try { QueueName = queueName; BaseConsumer = consume; Publish(factory, string.Empty); NoAck = noAck; BaseConsumer handle = consume as BaseConsumer; if (handle != null) { handle.Consumer = Channel; handle.NoAck = noAck; } Channel.BasicConsume(queueName, noAck, consume); Logger.Info("QUEUE {0} connected! {1}", queueName, DateTime.Now); } catch (Exception exception) { IsConnected = false; Logger.Debug(exception); } }
public void RecoveryDisconnectedConsumer() { if (Terminal == false) { try { CloseRabbitMqConnection(); IsConnected = true; if (string.IsNullOrEmpty(Uri)) { Publish(new ConnectionFactory { UserName = Username, Password = Password, VirtualHost = VirtualHost, HostName = HostName, Port = Port }, FileName); } else { Publish(new ConnectionFactory { Uri = new Uri(Uri) }, FileName); } BaseConsumer handle = BaseConsumer as BaseConsumer; if (handle != null) { handle.Consumer = Channel; handle.NoAck = NoAck; } Channel.BasicConsume(QueueName, NoAck, BaseConsumer); } catch (Exception exception) { IsConnected = false; Logger.Info("CONSUMER {0} {1} {2}", Uri, HostName, QueueName); Logger.Info(exception); } } }