473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Reconnecting to a remote MessageQueue when it has to reboot

I have a VB.Net application that runs as a Windows Service and
monitors a MessageQueue on another machine. At times that machine
will have to be rebooted, so I've been working on how to get my
Service to re-establish the connection after the remote machine is
back.

I found that as soon as the remote machine goes down, the
BeginReceive() method and the ReceiveCompleted() event handler start
throwing an exception, for QueueNotAvailable, which is very
reasonable. I figured I would catch the exception, tell the
CurrentThread to sleep for, say, 5 seconds, then instantiate the
MessageQueue object again, set its Formatter, add the handler, and
call BeginReceive again. I thought it should continue throwing the
same exception and reinstantiating itself until the remote
MessageQueue is on again.

But now I find that after the new MessageQueue is up (which I can see
in my debugging log) the EndReceive() method called inside the
ReceiveCompleted() throws another exception - "An invalid handle
was passed to the function." I thought maybe the new MessageQueue
instance was null or somehow not right, but I've put debug lines in
to check the MessageQueue properties and the properties of the
AsyncResult passed to EndReceive(), and they are all non-null, so I
figure that's not the problem.

Any clues?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 20 '05 #1
5 5724
I found there's apparently a cache for handles, so I called
ClearConnectionCache() before reinstantiating the MessageQueue
object, but then the next call to BeginReceive() threw an exception
saying "Remote computer not available" as if the connection cache
stored EVERYTHING needed, not just handles but remote machine name.

So it'g getting to be a circular problem.

By the way, in case it's not clear:

The remote machine has a private Queue on it, that messages from that
machine's processes send messages to. My app is on this machine, and
instantiates a
MessageQueue(name_of_that_private_queue_on_the_rem ote_machine).
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 20 '05 #2
felecha,
I've just started using MSMQ, so I don't have all the specifics.

Are you working with a public or private queue? I was under the impression
that MSMQ will hide the fact that a remote public queue is not available
from you.

Have you tried asking in one of the MSMQ specific newsgroups?

microsoft.public.msmq.*

Hope this helps
Jay

"felecha" <fe*******@yahoo-dot-com.no-spam.invalid> wrote in message
news:40**********@Usenet.com...
I have a VB.Net application that runs as a Windows Service and
monitors a MessageQueue on another machine. At times that machine
will have to be rebooted, so I've been working on how to get my
Service to re-establish the connection after the remote machine is
back.

I found that as soon as the remote machine goes down, the
BeginReceive() method and the ReceiveCompleted() event handler start
throwing an exception, for QueueNotAvailable, which is very
reasonable. I figured I would catch the exception, tell the
CurrentThread to sleep for, say, 5 seconds, then instantiate the
MessageQueue object again, set its Formatter, add the handler, and
call BeginReceive again. I thought it should continue throwing the
same exception and reinstantiating itself until the remote
MessageQueue is on again.

But now I find that after the new MessageQueue is up (which I can see
in my debugging log) the EndReceive() method called inside the
ReceiveCompleted() throws another exception - "An invalid handle
was passed to the function." I thought maybe the new MessageQueue
instance was null or somehow not right, but I've put debug lines in
to check the MessageQueue properties and the properties of the
AsyncResult passed to EndReceive(), and they are all non-null, so I
figure that's not the problem.

Any clues?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 20 '05 #3
It's a private queue on a remote machine.

The system we're building is an alerting system. When there's a
disaster, first-responders are alerted and a conferencing system goes
into action. The main control system resides on a host that has no
human interface, but runs on Windows XP Pro. That's where the Queue
is located, on that remote machine. The host communicates with the
human-interfacing software through that queue. I'm writing the
Administration Station application that will be on a regular desktop.
the Admin person can change configuration for the system and then
have the system reset itself. It's during the reset that the Queue
goes down. When it finishes its reset, I need to be able to get back
to receiving messages from the host queue.

How do I get to that newsgroup? I tried just using the links I found
to it, but they go nowhere. I generally use Opera as a browser, and
it says Server not found. IE6 tells me I need to install newsreader
software. I don't know about that.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 20 '05 #4
felecha,
It's a private queue on a remote machine. I suspect this may be the issue, however I only open private queues on the
local machine...
How do I get to that newsgroup? I tried just using the links I found
to it, but they go nowhere. I generally use Opera as a browser, and
it says Server not found. IE6 tells me I need to install newsreader
software. I don't know about that. How are you accessing this group?

Remember I gave you the root of a number of groups...

Here is the list on Google:

http://groups.google.com/groups?hl=e...ft.public.msmq

I would think either:
microsoft.public.msmq.networking
microsoft.public.msmq.programming
microsoft.public.msmq.setup

Can answer your question.

Hope this helps
Jay

"felecha" <fe*******@yahoo-dot-com.no-spam.invalid> wrote in message
news:40**********@Usenet.com... It's a private queue on a remote machine.

The system we're building is an alerting system. When there's a
disaster, first-responders are alerted and a conferencing system goes
into action. The main control system resides on a host that has no
human interface, but runs on Windows XP Pro. That's where the Queue
is located, on that remote machine. The host communicates with the
human-interfacing software through that queue. I'm writing the
Administration Station application that will be on a regular desktop.
the Admin person can change configuration for the system and then
have the system reset itself. It's during the reset that the Queue
goes down. When it finishes its reset, I need to be able to get back
to receiving messages from the host queue.

How do I get to that newsgroup? I tried just using the links I found
to it, but they go nowhere. I generally use Opera as a browser, and
it says Server not found. IE6 tells me I need to install newsreader
software. I don't know about that.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 20 '05 #5
Well I have stuff to learn still, I guess. I was able to get to the
groups directly through the google link, but earlier attempts gave
messages saying I needed newsreader software, which I don't know
about.

Anyway, I did see a post at one of the groups that led me to
msmqfaq.doc, where I found something that pretty much confirms me in
my conclusion about my problem. The items says:

4. An attempt to read from a remote queue fails with error
“invalid-handle.” Why?
This probably occurred because the remote computer has restarted, and
you use a cached queue handle that is no longer valid.
In core MSMQ, a local application uses a handle of the local MSMQ
service when reading from a remote queue, and the local MSMQ service
in turn has a remote queue handle from the remote computer. If the
remote computer restarts, the remote queue handle used by the local
MSMQ service is no longer valid. The standard workaround for this is
to close and reopen the queue. However, by default this workaround
does not work in the Microsoft .NET Framework, and the Close method
of the MessageQueue object does not close the queue handle. This is
because the .NET Framework uses a connections cache that caches queue
handles. To close a queue handle, either disable the connections
cache, or call ClearConnectionCache.

Well, it looks like the cache is the issue, but ... I already tried
disabling and clearing, and both steps led to other exceptions being
thrown.

Last night I tried another idea -- in the catch for the exception when
the remote queue goes down, I send an MSMQ Message to a LOCAL queue
that I set up, with a second little app running that has a
MessageQueue object that listens to THAT queue, and simply calls
ServiceController.Stop and ServiceController.Start on my Service, in
effect "rebooting" my Service in response to the reboot of the remote
machine. It keeps rebooting the Service every 5 seconds until the
remote queue comes up and then the connection is established and we
go on just fine.

It works consistently so far, but I still hope I can solve the cache
problem internally in the Service somehow. Creating apps to control
other apps bothers me.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bihari Srinivasan | last post by:
I am using two PCs, say PC-1 and PC-2 in a networked environment (TCP/IP). Both of these run Windows 2000. PC-1 is a development platform and PC-2 is a remote debug platform. I have a very...
1
by: Anibal David Acosta F. | last post by:
I want to access to MessageQueue from a remote machine, the path ".\private$\myQueue" only works locally, and the path "\\myServer\private$\myQueue" doesn't works. Do you know how can I access?...
3
by: Gerhard Swart | last post by:
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...
6
by: deepak | last post by:
I have to create message queue at remote machin. My code works properly when i use console application in c#. But it throws exception whenever i try it on web application in c#. My code is ...
4
by: Ash | last post by:
Is there a built in classes in .NET to make it easy to read/write MSMQ messages to/from remote queues? If not then what is the best way to implement it?
0
by: Marcus | last post by:
Hello All, I am trying to create a private MSMQ message queue on a remote application server from an asp.net application using the following code: Dim queue As MessageQueue queue =...
2
by: felecha | last post by:
I'm stumped. I'm working on an application in VB.Net that uses System.Messaging.MessageQueue to listen for messages sent to a private queue on a remote machine. Both machines are in the same...
0
by: chi.chung.ko | last post by:
Dear Pals local:Windows XP Sp2 server:Windows 2K3 Sever R2 When Use to Receive MessageQueue On Server System.Messaging.MessageQueue IQ = new MessageQueue(); IQ.Path =...
1
by: dif1754 | last post by:
My Windows DB2 Server 9.x is connected, via federation, to a remote AS/ 400 system: I created several nicknames to remote tables and I can query them. Problem is, during the night, my remote...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.