C # Message Queue operations

Source: Internet
Author: User

Public class QueueManage
{
///
/// Send the object to the queue
///
/// Queue name, because the queue name should not be changed in an application, it is best to write it in the configuration file.
/// The object to be sent out
Public static void SendQueue (string QueuePath, MyBase. SmsQueue sq)
{
System. Messaging. MessageQueue mqSend = new System. Messaging. MessageQueue (QueuePath, false );
EnsureQueueExists (QueuePath );
MqSend. Send (sq );
}


///
/// Check the queue. If the queue does not exist, create
///
/// Queue name
Private static void EnsureQueueExists (string path)
{
If (! MessageQueue. Exists (path ))
{
If (! MessageQueue. Exists (path ))
{
MessageQueue. Create (path );
MessageQueue mqTemp = new MessageQueue (path );
MqTemp. SetPermissions ("Everyone", System. Messaging. MessageQueueAccessRights. FullControl );
/// I don't know what permissions should I give, so I gave all the permissions to Everone. Of course, you 'd better control them by yourself.
}
}
}


///
/// Retrieve the object list from the queue
///
/// Queue name
Public static System. Collections. ArrayList GetMessage (string QueuePath)
{
MyBase. SmsQueue sq = new MyBase. SmsQueue ();
System. Messaging. MessageQueue mq = new System. Messaging. MessageQueue (QueuePath, false );
Mq. Formatter = new XmlMessageFormatter (new Type [] {typeof (MyBase. SmsQueue )});
System. Messaging. Message [] arrM = mq. GetAllMessages ();
Mq. Close ();
System. Collections. ArrayList al = new System. Collections. ArrayList ();
Foreach (System. Messaging. Message m in arrM)
{
Sq = (TimeFound. SmsGate. Base. SmsQueue) m. Body;
Al. Add (sq );
}

Return al;

}

}
 

Related Article

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.