Exemple #1
0
        private static void PublishKeepAlive()
        {
            try
            {
                List <string> m_redactlist = null;
                var           keepAlive    = m_configsettings["client"];

                keepAlive["timestamp"] = SensuClientHelper.CreateTimeStamp();
                keepAlive["version"]   = m_version_string;
                keepAlive["plugins"]   = "";

                m_redactlist = SensuClientHelper.GetRedactlist((JObject)keepAlive);

                var payload = SensuClientHelper.RedactSensitiveInformaton(keepAlive, m_redactlist);

                Log.Debug("Publishing keepalive");

                var properties = new BasicProperties
                {
                    ContentType  = "application/octet-stream",
                    Priority     = 0,
                    DeliveryMode = 1
                };

                lock (m_lock_pulish)
                {
                    RabbitMQChannel.BasicPublish("", "keepalives", properties, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload)));
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to publish KeepAlive!");
            }
        }
Exemple #2
0
        private static void Subscribe(CancellationToken m_tokenl)
        {
            EventingBasicConsumer m_rabbit_consumer = null;

            if (!RabbitMQChannel.IsOpen)
            {
                throw new Exception("RabbitMQ Channel not open!");
            }

            try
            {
                var m_my_queue = RabbitMQChannel.QueueDeclare(SensuClientHelper.CreateQueueName(), false, false, true, null);

                foreach (var subscription in m_configsettings["client"]["subscriptions"])
                {
                    Log.Debug("Declaring Exchange...");
                    RabbitMQChannel.ExchangeDeclare(subscription.ToString(), "fanout", false, false, null);
                    Log.Debug("Done");

                    Log.Info("Binding queue {0} to exchange {1}", m_my_queue.QueueName, subscription);
                    RabbitMQChannel.QueueBind(m_my_queue.QueueName, subscription.ToString(), "");
                    m_rabbit_consumer = new EventingBasicConsumer(RabbitMQChannel);

                    m_rabbit_consumer.Received          += SubscriptionReceived;
                    m_rabbit_consumer.Shutdown          += SubscriptionShutdown;
                    m_rabbit_consumer.ConsumerCancelled += SubscriptionCancelled;

                    RabbitMQChannel.BasicConsume(m_my_queue.QueueName, true, m_rabbit_consumer);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, ex.Message);
            }
        }
Exemple #3
0
 public RabbitMQConsumer(RabbitMQChannel channel, ConsumeConf conf)
 {
     _consume           = conf;
     _scheduler         = PipeScheduler.Inline;
     Channel            = channel;
     _bodyReader        = new BodyFrameChunkedReader(Channel.ChannelId);
     _contentFullReader = new ContentHeaderFullReader(Channel.ChannelId);
 }
Exemple #4
0
        async Task StartFloodAsync(RabbitMQChannel channel, string queue, byte[] body, int count)
        {
            var propertiesConsume = new ContentHeaderProperties();

            for (int i = 0; i < count; i++)
            {
                await channel.Publish(string.Empty, queue, false, false, propertiesConsume, body);
            }
        }
Exemple #5
0
 public void Return(RabbitMQChannel channel)
 {
     if (channel.Channel.IsOpen)
     {
         _channels.Add(channel);
     }
     else
     {
         CloseChannel(channel);
     }
 }
Exemple #6
0
 private void CloseChannel(RabbitMQChannel channel)
 {
     try
     {
         channel.Connection.CloseChannel(channel.Channel);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Channel closure failed", ex);
         //_logger.Error("Channel closure failed", ex);
     }
 }
Exemple #7
0
        private static void PublishResult(JObject check)
        {
            var payload = new JObject();

            payload["check"]  = check;
            payload["client"] = m_configsettings["client"]["name"];

            try
            {
                Log.Info("Publishing Check Result {0}", JsonConvert.SerializeObject(payload, SerializerSettings));

                Task.Factory.StartNew(() =>
                {
                    var properties = new BasicProperties
                    {
                        ContentType  = "application/octet-stream",
                        Priority     = 0,
                        DeliveryMode = 1
                    };

                    lock (m_lock_pulish)
                    {
                        RabbitMQChannel.BasicPublish("", "results", properties, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload)));
                    }
                });
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    Log.Error(ex, "Publishing Check Result failed: {0}", ex.InnerException.Message);
                }
                else
                {
                    Log.Error(ex, "Publishing Check Result failed: {0}", ex.Message);
                }
            }
            finally
            {
                Log.Debug("Check Result successfully published!");

                lock (m_lock_checkinprogress)
                {
                    if (ChecksInProgress.Contains(check["name"].ToString()))
                    {
                        ChecksInProgress.Remove(check["name"].ToString());
                    }
                }
            }
        }
Exemple #8
0
        protected override void OnStop()
        {
            Log.Info("Service OnStop called: Shutting Down");
            m_cancelationtokensrc.Cancel();

            lock (m_lock_pulish)
            {
                RabbitMQChannel.Close(200, "Bye");
            }

            RabbitMQConnection.Close();

            Log.Info("Unloading Plugins...");

            m_program_base.UnloadPlugins();

            Log.Info("Done!");

            base.OnStop();
        }
 public async Task Send(RabbitMQChannel channel, object channelId, string methodName, object[] args, IReadOnlyList <string> excludedConnectionIds = null)
 {
     await Task.Run(() =>
     {
         var list = channelId as IReadOnlyList <string>;
         if (list != null)
         {
             channelId = _Protocol.WriteList(list);
         }
         var message    = _Protocol.WriteInvocation(methodName, args, excludedConnectionIds);
         var properties = new BasicProperties
         {
             Headers = new Dictionary <string, object>
             {
                 { "channel", channel.ToString() },
                 { "channelId", channelId }
             }
         };
         _PublishModel.BasicPublish(_RabbitMQOptions.ExchangeName, "", properties, message);
     });
 }