I got a system of console applications written in C# running on different machines. I use MSMQ.
My questions is, how do I make my console applications communicate to each other?
I'm asking because I want to create a new console application that can be queried by other applications to know the number of messages in MSMQ.
Edit 1: Thanks for the replies and comments! About the requirements, I'm estimating maybe about 10-50/sec of queries
You need to use a pipe to achieve this: see Named pipe and anonymous pipe
A pipe works like this: The host application (the one launching the console application) has to create a pipe to catch the concole application's std output and an other one to write to the console application's std input.
There is plenty of code example in the link I gave you
Also here is a code example (using existing pipes StandardInput and StandardOutput): it starts a cmd.exe console but it is a layer over: not the actual console...see for yourself:
You can achieve the same result by replacing the StreamReader and the StreamWriter by a port connection (socket) buffer for remote communication between two process http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx
It is recommended to secure the communication to minimize intrusion possibility
Here is an example of communication through a sockets...now this is running in one program but everything is on separate threads and it would work if the communication was to be on two separate machines: the server is the one controlling the process cmd.exe and the client is a viewer/writer
WCF. WCF, WCF, WCF, WCF.
Don't bother reinventing the wheel, just use WCF for communications, and let it worry about the details (whether using a pipe or some other mechanism).
testable and extendable - can be easily changed to work between computers.
you have a few methods. "named pipes" can be achieved easily using WCF. its nice because its very testable.
best performance you can use memory mapped files http://weblogs.asp.net/gunnarpeipman/archive/2009/06/21/net-framework-4-0-using-memory-mapped-files.aspx
they have AMAZING performance. BUT less harder to test.
easiest - if you have very low traffic you can use the registry. theres a Regisrty class in C# its threadsafe and fast.