Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem in Message Queuing

Status
Not open for further replies.

surovi99

IS-IT--Management
Feb 11, 2005
28
US
Hi,

I am trying to run a program on message queuing in which the user inserts some info in text boxes from the client side which gets entered into a message queue and the server receives the info by message queue, writes to a file and then reads the file. These are the requirements of my program. Now the client side works ok. But the server displays the info from the client only once with the codes I have written. It doesnt display the info if I insert new info from the client side. What could be the problem?

Below I give WaitForData() function codes which I call inside the function where the client connects to server:

public void WaitForData()
{ System.Messaging.MessageQueue mq;
try
{
if (MessageQueue.Exists(@".\Private$\MyQueueParts"))
//creates an instance MessageQueue, which points to the already existing MyQueueParts

mq = new System.Messaging.MessageQueue(@".\Private$\MyQueueParts");

else
//creates a new private queue called MyQueueParts

mq = MessageQueue.Create(@".\Private$\MyQueueParts");

mq.Formatter = new System.Messaging.XmlMessageFormatter (new Type[] {typeof (WritePartsItems)}) ;

System.Messaging.Message msg = mq.Receive();
WritePartsItems outpartsItems = (WritePartsItems)msg.Body;

using( StreamWriter sw = new StreamWriter(outpartsItems.FileName,true))

{
sw.WriteLine(outpartsItems.Message);
sw.Flush();
}

using (StreamReader sr = new StreamReader(outpartsItems.FileName, true))
{

string line;
// Read and display lines from the file until the end of
// the file is reached.

while ((line = sr.ReadLine()) != null)
{
Client_Parts_Records.Items.Add(line);
}
}

}

catch (MessageQueueException ex)
{
MessageBox.Show(ex.Message);
}

}

Any quick help will be much appreciated.

Thanks
 
It appears that you're creating multiple instances of your MessageQueue object and then calling the Receive method only once.

You should open the queue once, and then call receive as many times as needed. Close the MessageQueue when your program ends.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Hi,

I have a new problem. I want the message queue to be persistent i.e when I stop the server and restart it, the messages it has read before should still be there. How can I resolve this problem?


Thanks

 
Configure your message queue to have guaranteed delivery.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
How can I configure the message queue to have guaranteed delivery?

Thanks a lot.
 
That's in the MSMQ documentation.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Looks like I would require JSM for the message queue to have guaranteed delivery. But my requirements are Visual Studio.NET,C# on Windows XP.

Is there any other way?

Any help much appreciated.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top