How the system reduces the data peak (MSMQ)

Source: Internet
Author: User
Tags msmq

As a securities system, servers receive extremely frequent data volumes for system scalability. The system design is as follows: receive data --> MSMQ queue --> process business --> MSMQ queue --> return information, and store the received data to MSMQ through the interface.

MSMQ can be applied in many places. Now, let's put out our ideas and give them to your friends for reference. It may be outdated, but I always hope someone will need it!

First, reference the namespace: using system. messaging;

Private Static bool insertdata (string mqname, object OBJ)
{
Bool flag = false;
If (mqname = NULL | mqname. Length = 0)
{
Throw new argumentnullexception ("mqname", "mqname is null ");
}
If (! Messagequeue. exists (@ ". \ private $ \" + mqname ))
{
Throw new argumentnullexception ("mqname", "mqname isn't exists ");
}

Try
{
Messagequeue mequ = new messagequeue (@ ". \ private $ \" + mqname );

Message MEs = new message ();
Mes. Body = OBJ;
Mes. formatter = new xmlmessageformatter (New Type [] {typeof (clsst)}); // clsst is the class name
Mequ. Send (MES );

Mes. Dispose ();
Mequ. Close ();

Flag = true;

}
Catch (exception ex)
{
Throw ex;
}

Return flag;

}
In this way, the operation of inserting data into MSMQ is completed. If you need to modify the receiving data module in the future, it is okay to modify the data independently. facilitate system expansion in the future. the following business module needs to read the message from MSMQ. When MSMQ has a message, it immediately reads the message and reads the content for processing. Program You can monitor MSMQ continuously. The following is the message in MSMQ. Code :
Private Static clsst readmes (string mqname)
{
Clsst clsstread = NULL;
If (mqname = NULL | mqname. Length = 0)
{
Throw new argumentnullexception ("mqname", "mqname is null ");
}
Try
{
Messagequeue mequ = new messagequeue (@ ". \ private $ \" + mqname );
Myqueue. formatter = new xmlmessageformatter (New Type [] {typeof (clsst )});
Message MEs = mequ. Receive ();
Clsstread = (clsst) mes. Body;

}
Catch (exception ex)
{
Throw ex;
}

Return clsstread;
}

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.