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)
{< br> If (! Messagequeue. exists (PATH)
{< br> If (! Messagequeue. exists (PATH)
{< br> messagequeue. create (PATH);
messagequeue mqtemp = new messagequeue (PATH);
mqtemp. setpermissions ("everyone", system. messaging. messagequeueaccessrights. fullcontrol);
// you do not know the permissions you should grant to everone, of course, you 'd better control it by yourself
}< BR >}

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

}

}

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.