Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there any event or callback on MSMQ for new message added to queue

I have two component. One is Window application and other is Window Service.
Window Application writing to Message Queue(MSMQ) and Service is reading it and process the message.
Should service always keep looking to queue for new message...In terms of code should I
use infinite while loop or a Timer
OR
is there any event or callback on queue for new message added to queue? So that when window application add a new message to queue, Service can know.
This all I am asking to make my application efficient so if there is any other way to achieve this you can suggest.
Thanks for reading

like image 987
USER_NAME Avatar asked Jul 11 '12 16:07

USER_NAME


People also ask

Is MSMQ asynchronous?

Asynchronous messaging. With MSMQ asynchronous messaging, a client application can send a message to a server and return immediately, even if the target computer or server program is not responding.

Why do we use MSMQ?

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.


1 Answers

You do not need any event or loop. Receive method will read from the queue and if the queue is empty it will block until a new message is added. If you need to do something else in the meantime, put the receiving code in a separate thread.

You can also use asynchronous approach by using BeginReceive. This will actually raise an event when message has been read from the queue.

like image 200
Maciej Avatar answered Oct 09 '22 13:10

Maciej