public void Listen(Action <LogSeverity, string> onReceived)
        {
            var consumer = new EventingBasicConsumer(_channel);

            consumer.Received += (model, ea) =>
            {
                var body     = ea.Body;
                var message  = Encoding.UTF8.GetString(body);
                var severity = LogSeverity.Values().First(s => s.Value == ea.RoutingKey);
                onReceived(severity, message);
            };
            _channel.BasicConsume(queue: _queueName, autoAck: true, consumer: consumer);
        }
Exemplo n.º 2
0
        private const int RefreshRate = 1000;  // 1sec

        static void Main(string[] args)
        {
            ILogReceiver receiver = new RabbitMQReceiver();

            receiver.Init();
            foreach (var severity in LogSeverity.Values())
            {
                receiver.BindRoute(severity);
            }
            receiver.Listen((severity, message) => {
                LogAnalysis[severity]++;
            });
            new Task(WriteLogStats).Start();

            Console.ReadKey();
            receiver.Close();
        }