Esempio n. 1
0
        /// <summary>
        /// Starts receiving a message from a queue
        /// </summary>
        public void Start()
        {
            var consumer = new QueueingBasicConsumer(_model);

            _model.BasicConsume(QueueName, false, consumer);

            while (Enabled)
            {
                // Get next message
                var deliveryArgs = (BasicDeliverEventArgs)consumer.Queue.Dequeue();

                // Serialize message
                var message = Encoding.Default.GetString(deliveryArgs.Body);

                // If running interactively display the message received
                if (Environment.UserInteractive)
                {
                    Console.WriteLine("Message Received - {0}", message);
                }
                // Acknowledge the message
                _model.BasicAck(deliveryArgs.DeliveryTag, false);
                // Create the report request instance
                if (message != "QUIT!")
                {
                    var reportRequest = new ReportGenerate();
                    // Initialize the parameters for the report
                    reportRequest.initParameterValues(message);
                    // Generate the report
                    reportRequest.GenerateReport();
                    // Put it on the disk
                    reportRequest.SaveReportToDisk();
                }
                else
                {
                    Enabled = false;
                    Environment.Exit(0);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Starts receiving a message from a queue
        /// </summary>
        public void Start()
        {
            var consumer = new QueueingBasicConsumer(_model);
            _model.BasicConsume(QueueName, false, consumer);

            while (Enabled)
            {
                // Get next message
                var deliveryArgs = (BasicDeliverEventArgs)consumer.Queue.Dequeue();

                // Serialize message
                var message = Encoding.Default.GetString(deliveryArgs.Body);
                
                // If running interactively display the message received
                if (Environment.UserInteractive)
                {
                    Console.WriteLine("Message Received - {0}", message);
                }
                // Acknowledge the message
                _model.BasicAck(deliveryArgs.DeliveryTag, false);
                // Create the report request instance
                if (message != "QUIT!")
                    {
                    var reportRequest = new ReportGenerate();
                    // Initialize the parameters for the report
                    reportRequest.initParameterValues(message);
                    // Generate the report
                    reportRequest.GenerateReport();
                    // Put it on the disk
                    reportRequest.SaveReportToDisk();
                    }
                else
                {
                    Enabled = false;
                    Environment.Exit(0);
                }

            }
        }