. NET Microsoft Message Queuing (MSMQ) simple case

Source: Internet
Author: User
Tags message queue msmq

1. First we need to install the Message Queuing service, which is a standalone message logging service and is saved in the hard disk file.

We add a private message queue named: Dmimgupload.

2. Define the connection string for Message Queuing IP is recommended:

(1) Formatname:direct=os:pac_gzf-pc\private$\dmimgupload

(2) Formatname:direct=tcp:192.168.1.105\private$\dmimgupload

String queuepath= "Formatname:direct=tcp:192.168.1.105\private$\dmimgupload";

2. Create an instance: "Using System.Messaging;"

protected MessageQueueTransactionType Transactiontype = messagequeuetransactiontype.automatic;//define Transaction

MessageQueue queue = new MessageQueue (QueuePath); Create a queue based on incoming Quueupath
TimeSpan Timeout = timespan.fromseconds (3);//Set read message interval time;
Queue. Defaultpropertiestosend.attachsenderid = false;
Queue. Defaultpropertiestosend.useauthentication = false;
Queue. Defaultpropertiestosend.useencryption = false;
Queue. Defaultpropertiestosend.acknowledgetype = Acknowledgetypes.none;
Queue. Defaultpropertiestosend.usejournalqueue = false;

3.

Receive Message methods
Public virtual Object Receive ()
{
Try
{
using (Message message = queue. Receive (timeout, transactiontype))
return message;
}
catch (Messagequeueexception Mqex)
{
if (MQEX. MessageQueueErrorCode = = messagequeueerrorcode.iotimeout)
throw new TimeoutException ();
Throw Mqex;
}
}

Send Message "lable: Message ID, MSQ: Message"
public virtual void Send (String label, Object msg)
{
Queue. Send (MSG, label, Transactiontype);
}

5. Remark:

When we call across hosts, Message Queuing permission prompts to set Network service permissions in MSMQ

Message Queuing stores can make a string, or it can make an object form.

For example: We define an object: Solimgcreatemodel. To accept a message for casting:

(Solimgcreatemodel) (Message) Receive ()). Body;

. NET Microsoft Message Queuing (MSMQ) simple case

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.