I have multiple processes monitoring an MSMQ queue. I want to do multi-step operations like first peek the message and then based on some criteria receive the message. A single message may pass the receiving criteria of multiple processes so that more than one process may try to receive the same message. Will these operations be thread safe? If not what should I do to prevent one process from failing to receive the message that other process has already received?
Queues are thread safe in that multiple tasks can try to concurrently write to or read from a given queue, and the queue will handle the syncronization so that each message gets put in as a unique message and each message gets sent to a single task.
Microsoft Message Queue server, short MSMQ, provides exactly that - guaranteed and reliable message delivery. It provides an easy way to send messages between different applications or to process messages asynchronously.
Message Queuing (MSMQ) technology enables applications running at different times to communicate across heterogeneous networks and systems that may be temporarily offline. Applications send messages to queues and read messages from queues.
Microsoft Messaging Queue (MSMQ) technology is used for asynchronous communication using messages. MSMQ also can be considered to be an Inter- process communication capability. Whenever two processes want to communicate with each other in a "Fire and Forget" manner, MSMQ is very useful for that. Usage.
According to MSDN:
Only the following methods are thread safe: BeginPeek, BeginReceive, EndPeek(IAsyncResult), EndReceive(IAsyncResult), GetAllMessages, Peek, and Receive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With