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;
}