Remote journal problem - MessageQueue

G

Gerhard Swart

Hi all. I'm writing a queue browser that reads queues from a specified
machine and then display the data that's on the queue. I am using the
MessageQueue Class in .Net(C#).

I get the problem that I can't read the journal private queue on a remote
machine. I don't know if this is possible though. I have tried all the
possible options but can't seem to get it to work. The code that I tried is:

MessageQueue _mq = new MessageQueue( "FormatName:DIRECT=OS:" +
"RemoteMachine\private$\icsis_el_queue\JOURNAL$);

Any help will be appreciated.

Thanks in advance
 
D

Daniel Bass

you can only access a remote machine's public queues.
private queues are for messages sent internally on a machine.

Dan.

Hi all. I'm writing a queue browser that reads queues from a specified
machine and then display the data that's on the queue. I am using the
MessageQueue Class in .Net(C#).

I get the problem that I can't read the journal private queue on a remote
machine. I don't know if this is possible though. I have tried all the
possible options but can't seem to get it to work. The code that I tried is:

MessageQueue _mq = new MessageQueue( "FormatName:DIRECT=OS:" +
"RemoteMachine\private$\icsis_el_queue\JOURNAL$);

Any help will be appreciated.

Thanks in advance
 
G

Gerhard Swart

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
 
D

Daniel Bass

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("&lt;","<");
szBuffer = szBuffer.Replace("&gt;",">");

// 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top