MSDN's definitions:
private queue
A queue registered on the local computer (not in the directory service) that
typically cannot be located by other applications. Private queues have the
advantage of no directory service overhead (faster to create, no latency,
and no replication), and they can be created and deleted when the directory
service is not working.
public queue
A queue registered in the directory service that can be located by any
Message Queuing application. Public queues are persistent and their
registration information can be backed up on the enterprise, making them
good for long-term use.
From this I deduced that the queues that are private are only accessed by
the application that created them?
I don't think you should specify the "private" sub path name when accessing
a queue reading or writing...
I've created a wrapper for reading and writing synchronously if you'd like
to have a look.
I've changed the example, and removed a few references to the rest of the
app in which it resided.
*******************************************************************
using System;
using System.Windows.Forms;
using System.Messaging;
using System.IO;
using System.Threading;
namespace BIF_Queues
{
/// <summary>
/// InterfaceTypeMSMQ handles the message queues for MSMQ (version 2/3).
/// </summary>
public class MSMQWrapper
{
//
// Thread Safe Wrapper...
//
//
// member variables
//
private MessageQueue m_Queue;
private bool m_bValid = false;
public Valid
{
get
{
return m_bValid;
}
}
//
// constructor
//
public MSMQWrapper(string szServer, string szAddress)
{
string szQueuePath = szServer + "\\" + szAddress;
try
{
if ( !MessageQueue.Exists( szQueuePath ) )
{
if ( MessageBox.Show("The path you specified for a
queue, '" + szQueuePath +"' does not exists. Do you wish to create it? (
Pressing 'No' disregard this queue ).", "MSMQ Queue not found!",
MessageBoxButtons.YesNo ) == DialogResult.Yes )
{
m_Queue = MessageQueue.Create(szQueuePath);
m_bValid = true;
}
}
else
{
m_Queue = new MessageQueue(szQueuePath);
m_bValid = true;
}
m_szAddress = szQueuePath;
}
catch ( Exception ex )
{
DebugLog.Instance().WriteLog( "InterfaceTypeMSMQ [" +
szQueuePath + "] :- Exception Error. " + ex.Message );
}
}
//
// overridden methods
//
public override eResult Send( string data )
{
m_Queue.Send(data);
return eResult.RES_SUCCESS;
}
public override void Receive( out string data )
{
data = "";
while (Global.Instance().Listening)
{
try
{
System.Messaging.Message msg = m_Queue.Receive(new
TimeSpan(0,0,0,0,500)); // throws an exception if the method times out
// message was received, strip out the padded XML,
should it exist
string szBuffer = Global.Instance().StreamToString(
msg.BodyStream );
szBuffer = szBuffer.Replace("<?xml
version=\"1.0\"?>\r\n<string>", "");
szBuffer = szBuffer.Replace("</string>", "");
szBuffer = szBuffer.Replace("<","<");
szBuffer = szBuffer.Replace(">",">");
// stick it back into a buffer
data = szBuffer;
return;
}
catch ( Exception )
{
// wait a litte, and carry on, all the exception
// means is no message was found no the queue.
Thread.Sleep(1000);
}
}
return;
}
}
}
***********************************************************************
so all you'd need to do is something like this:
MSMQWrapper myQueue = new MSMQWrapper ( "myComputer", "remoteQueue" );
myQueue.Send ("Test Data");
String receivedData;
myQueue.Receive( receivedData );
Although it's synchronous, you can use it in multithreaded instances, so
that one thread would have the task of simply looking at a queue for data,
and processing that data it downloaded, while the rest of the program got on
and did something else.
Hope that helps.
Dan.
***********************************************************************
Thanks Daniel,
Since I'm a bit new to .Net I'm still learning all the nitty gritties.
In one of my previous applications I wrote using MSMQ2 COM component(VB6),
the application picked up the remote private journal. Was the application
suppose to
be able to do that, because if not then I would maybe have to make some
changes to the app.
Do you maybe know why the MSMQ functionality differ from the MessageQueue
functionality?
Thanks in advance