Take over the previous chapter. Today, we will talk about the application of MSMQ in practical projects. As we all know, if Order is placed to prevent Order loss, we use Order to pass MSMQ.
The advantages of MSMQ are: inherent asynchronous message transmission and inherent automatic load balancing.
Let's take a look at the application of MSMQ in practice.
Step 1: Prepare for installation. Install the MSMQ server and check the options.
Step 2: Create a class library. Create two files, IOrder. cs and Order. cs. As follows.
Step 3: Create the Host Console program and create the App. config file, as shown below.
Step 4: In the console program: ①: Create a queue. ②: Enable the service.
Last step: Create a Console program as the client to test MSMQ. This time, we generate an instance through "channel.
①: Let the Host service Off Line. We can insert 100 orders to check whether msmq responds.
Yes, the number of messages is the 100 order information inserted by the Client.
②: This time, I will restart the Host to make the Service end On Line. Let's see how MSMQ reacts.
Yes, when msmqfinds that my wcfhas been opened, the message will also go to my 1.txt file.
The project diagram is shown as follows:
Author huangxincheng520