Hi, Thanks for the help. Is there a way to take the message off the queue without calling ReceiveByCorrelationId because behind the scenes that method iterates through every message in the queue and then takes the message off the queue and I doubt it is thread safe. Thanks [EMAIL PROTECTED]
> Date: Sat, 5 Aug 2006 17:03:45 -0500> From: [EMAIL PROTECTED]> Subject: Re: > [ADVANCED-DOTNET] ReceiveByCorrelationId + MSMQ> To: > [email protected]> > Sample below...> > A few > thoughts/comments - first, I think you always want to EndPeek. I> remember > reading somewhere that the API docs state that the framework does> not > promise to behave nicely if you forget to. Second, EndPeek will throw an> > exception if BeginPeek times out. I added the 'using' statements on the> > messages because they are disposable and I am a little superstitutious about> > that more than that I have ever actually seen that cause a problem. It would> > seem weird to me that a Message object would actually hold on to some> > important unmanaged resource, but who knows? Reflector doesn't make it> > obvious. Maybe someone can comment on that. FWIW, I highly recommend you set> > up a little functional test in NUnit or whatever it is you use to write your> > tests to simulate the situation you are looking for and prove it out to> > yourself. You don't even have to have Navision running. There are few things> > like the comfort of a good, green bar to aid in understanding.> > I hope that > helps!> > Thanks,> Jef Newsom> > > private void ReceiveQ_PeekCompleted(object > sender, PeekCompletedEventArgs e)> {> try> {> MessageQueue > messageQueue = sender as MessageQueue;> using(Message message = > messageQueue.EndPeek(e.AsyncResult))> {> > if(!message.CorrelationId.Equals(_correlationId))> {> > messageQueue.BeginPeek(_timeOut);> return;> }> }> > using(message = messageQueue.ReceiveByCorrelationId(_correlationId))> {> > // do something with it.> }> }> catch(MessageQueueException > e)> {> if(e.MessageQueueErrorCode == > MessageQueueErrorCode.IOTimeout*)*> * {*> // log it, peek again, > whatever you think is the right thing to do.> }> }> }> > > On 8/5/06, > Paul Cowan <[EMAIL PROTECTED]> wrote:> >> > Hi,> >> > THe eventargs contains > the message. I have the following event handler> > for PeekCompleted:> >> > > private void ReceiveQ_PeekCompleted(object sender, PeekCompletedEventArgs> > > e)> > {> > if (e.Message.CorrelationId != _correlationId)> > {> > > messageQueue.BeginPeek(_timeOut);> > return;> > }> > > MessageQueue messageQueue = sender as MessageQueue;> > Message message = > messageQueue.EndPeek(e.AsyncResult);> > }> >> > My question is what if there > is an error on the other side and the message> > never gets placed onto the > queue?? How can I timeout gracefully if> > BeginPeek is being called each > time?> >> > Thanks> > Paul> > [EMAIL PROTECTED]> >> >> >> > > Date: Sat, 5 > Aug 2006 14:16:28 -0500> From: [EMAIL PROTECTED]>> > Subject: Re: > [ADVANCED-DOTNET] ReceiveByCorrelationId + MSMQ> To:> > > [email protected]> > I think you can just do a BeginPeek> > > and check the correlationId against the> message you receive from the> > > EndPeek. If it is [one of your outstanding]> message[s], then> > > receiveByCorrelationId. If not, then ignore and BeginPeek> again. Sorry, I> > > haven't worked with MSMQ in over a year, so the details are> a bit rusty,> > > but I think that should work for you.> > On 8/5/06, Paul Cowan <> > [EMAIL > PROTECTED]> wrote:> >> > Hi,> >> > We are creating a web> > application that > unfortunately has to communicate> > with a product called> > Navision. The > communication is to send and receive> > xml documents via> > MSMQ.> > The > process is we send a message to one queue and receive messages> > on> > > another queue. The only reliable way I have been able to marry these>> > > > messages together is to by setting the CorrelationId of the response> > > message> > to be the id of the request message.So far I am doing this> > > synchronously> > using the ReceiveByCorrelationId method. I have grave> > > worries of how this> > will scale and I don't think it is thread safe.> >> >> > > My code is as follows:> >> > while ( > receiveQ.PeekByCorrelationId(messageId,> > _timeOut) != null)> > {> > > message = receiveQ.ReceiveByCorrelationId(messageId,> > _timeOut);> > }> >> > > I would like to do this asynchronously but am really> > not sure how to go> > > about this.> >> > Can anyone with MSMQ experience tell> > me how I can > accomplish this problem> > asynchronously??> > Thanks> > Paul>> > >> >> > > ===================================> > This list is hosted by> > > DevelopMentor(r) http://www.develop.com> >> > View archives and manage> > > your subscription(s) at> > http://discuss.develop.com> >> >> > > ===================================> This list is hosted by DevelopMentor(r)> > > http://www.develop.com> > View archives and manage your subscription(s) at> > > http://discuss.develop.com> > ===================================> > This > list is hosted by DevelopMentor(r) http://www.develop.com> >> > View > archives and manage your subscription(s) at http://discuss.develop.com> >> >> > > ===================================> This list is hosted by DevelopMentorĀ® > http://www.develop.com> > View archives and manage your subscription(s) at > http://discuss.develop.com =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com
