Microsoft message queue for distributed applications

Microsoft message queue is the way to go for distributing applications. It allows you to build an application environment with disconnected components.

Code example sending and receiving from a message queue, first the class which we want to send and receive, only interesting thing here is the serializable attribute.

[Serializable]
    public class Klant
    {
        public string Voornaam { get; set; }

        public string Tussenvoegsel { get; set; }

        public string Achternaam { get; set; }
    } 

We are going to use this class to generate objects which we send to the message queue:

try
            {
                using (MessageQueue messageQueue = new MessageQueue(QueueName))
                {
                    using (MessageQueueTransaction transaction = new MessageQueueTransaction())
                    {
                        transaction.Begin();

                        Klant klant = new Klant() { Achternaam = "LastName", Tussenvoegsel = "Suffix", Voornaam = "FirstName" };
                        messageQueue.Send(klant, transaction);
                        transaction.Commit();
                        messageQueue.Close();
                    }
                }
            }
            catch (Exception excp)
            {
                // MessageBox.Show(excp.Message);
            } 

And next thing is receiving the messages:

using (MessageQueue messageQueue = new MessageQueue(QueueName))
            {
                messageQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(Klant) });
                System.Messaging.Message message = messageQueue.Receive();
                Klant receivedKlant = (Klant)message.Body;
                
            } 

{{opmerking.Naam}}:

{{opmerking.OpmerkingText}}

            

Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!