コード例 #1
0
        public void Execute()
        {
            int messagesRetrieved = 0;

            QueueHandler.InitializeQueue();

            DateTime startTime = DateTime.Now;

            Console.WriteLine($"Starting to retrieve {_numberOfMessages} messages to queue.");

            while (messagesRetrieved < _numberOfMessages)
            {
                Message message = QueueHandler.Receive();
                Console.WriteLine($"Starting to receive message {messagesRetrieved + 1}: {message.Id}");

                string bodyString = (string)message.Body;
                if (bodyString.Length > 50)
                {
                    bodyString = bodyString.Substring(0, 49);
                }

                string bodyStartsWith = $"Message: {bodyString}...";
                Console.WriteLine(bodyStartsWith);

                messagesRetrieved++;
            }

            Console.WriteLine($"Retrieved all {_numberOfMessages} to the queue.");
            DateTime endTime = DateTime.Now;

            Console.WriteLine($"Started {startTime} and Ended {endTime}.  Duration = {endTime - startTime}");

            QueueHandler.CloseAndDispose();
        }