private IModel CreateChannel(IModel ch) { var connection = _connectionFactory.GetRabbitConnection(); if (connection == null) { //Do nothing - we'll loop around the while loop again with everything null and retry the connection. } else { ch = connection.CreateModel(); } return(ch); }
public void PublishResult(JObject payload) { var json = JsonConvert.SerializeObject(payload); Log.Info("Publishing Check to sensu server {0} \n", json); using (var ch = _connectionFactory.GetRabbitConnection().CreateModel()) { var properties = new BasicProperties { ContentType = "application/octet-stream", Priority = 0, DeliveryMode = 1 }; ch.BasicPublish("", "results", properties, Encoding.UTF8.GetBytes(json)); } }
private IModel CreateChannelAndConsumer(IModel ch, ref QueueingBasicConsumer consumer) { var connection = _sensuRabbitMqConnectionFactory.GetRabbitConnection(); if (connection == null) { //Do nothing - we'll loop around the while loop again with everything null and retry the connection. } else { ch = connection.CreateModel(); var queueName = SensuClientHelper.CreateQueueName(); foreach (var subscription in _sensuClientConfigurationReader.SensuClientConfig.Client.Subscriptions) { Log.Debug("Binding queue {0} to exchange {1}", queueName, subscription); try { ch.ExchangeDeclare(subscription, "fanout"); var q = ch.QueueDeclare(queueName, false, false, true, null); ch.QueueBind(q.QueueName, subscription, ""); } catch (Exception exception) { Log.Warn(exception, "Could not bind to subscription: {0}", subscription); } } consumer = new QueueingBasicConsumer(ch); try { ch.BasicConsume(queueName, true, consumer); } catch (Exception) { Log.Warn("Could not consume queue: {0}", queueName); } } return(ch); }