Beispiel #1
0
        /// <summary>
        /// Receive msmq message
        /// </summary>
        private static void MsmqReceiveMessage(IMsmqProviderFactory msmqProviderFactory)
        {
            var isRunning = true;

            using (var messageQueue = msmqProviderFactory.Create <SampleMessage>(Serializer.Json, "message_queue_sample_console"))
            {
                while (isRunning)
                {
                    QueueMessage <SampleMessage> queueMessage = null;

                    try
                    {
                        queueMessage = messageQueue.ReceiveAsync(new TimeSpan(0, 0, 0, 10, 0)).Result;

                        if (queueMessage != null)
                        {
                            System.Console.WriteLine(string.Format("Removed message from the queue. Body: {0}", queueMessage.Item));
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine("Unexpected error: " + ex.Message);
                    }
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Purge msmq message
 /// </summary>
 private static void MsmqPurgeMessage(IMsmqProviderFactory msmqProviderFactory)
 {
     using (var messageQueue = msmqProviderFactory.Create <SampleMessage>(Serializer.Json, "message_queue_sample_console"))
     {
         messageQueue.PurgeAsync().Wait();
     }
 }
Beispiel #3
0
        /// <summary>
        /// Push msmq message
        /// </summary>
        /// <param name="msmqProviderFactory"></param>
        private static void MsmqPushMessage(IMsmqProviderFactory msmqProviderFactory)
        {
            using (var messageQueue = msmqProviderFactory.Create <SampleMessage>(Serializer.Json, "message_queue_sample_console"))
            {
                for (int i = 0; i < 5; i++)
                {
                    var sampleMessage = new SampleMessage
                    {
                        SampleMessageId = i,
                        Name            = "Sample Message",
                        Created         = DateTime.UtcNow
                    };

                    messageQueue.PushAsync(new QueueMessage <SampleMessage>(sampleMessage)).Wait();
                }
            }
        }