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(); }
public void Execute() { QueueHandler.InitializeQueue(); DateTime startTime = DateTime.Now; Console.WriteLine($"Starting to upload {_numberOfMessages} messages to queue."); for (int messagesSent = 1; messagesSent <= _numberOfMessages; messagesSent++) { Message message = new Message(); message.Body = SettingsProvider.GetMessageBody(); message.Label = "Sent from MsmqTester"; message.TimeToReachQueue = new TimeSpan(0, 5, 0); message.UseDeadLetterQueue = true; message.Recoverable = SettingsProvider.GetWillPersist(); message.UseJournalQueue = false; QueueHandler.SendMessage(message); Console.WriteLine($"Uploaded message {messagesSent}"); } Console.WriteLine($"Uploaded all {_numberOfMessages} to the queue."); DateTime endTime = DateTime.Now; Console.WriteLine($"Started {startTime} and Ended {endTime}. Duration = {endTime - startTime}"); QueueHandler.CloseAndDispose(); }