is there anyway in azure to know instances for some other role have started or not?

81 views Asked by At

in my service deployment i have two roles.. a web role and a worker role..
in my on_start() method of webrole im enumerating the instances of the worker roles and creating a tcp connection on some internal end point.
but very often it fails because the instances of the worker role havent started yet.
so the question is that can i know wether the instances have started or can i wait for instances of the worker role to start in some way? herez the code

public override bool OnStart()
        {
            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            ConnectionStatics.ConnectRouterToWorkers();
            Messaging.KeepReadingMessages.Start();

            return base.OnStart();
        }
2

There are 2 answers

0
Tom On BEST ANSWER

Another option would be to have the worker roles put a message in a queue when they are started up. Then you could just check the queue and wait for it to post a message there.

0
BrentDaCodeMonkey On

I'd recommend building retry logic into your loop so when its unable to establish the connection, it just sleep and retries it again later. Not only will this address your startup issue, but it will help you address changes to the service topology as instances are added/removed by the fabric controller (which can happen for numerous reasons).

Taken a step further, you might be able to leverage the RoleEnvironmentChanging and RoleEnvironmentChanged events to provide notification of when an instances is added/dropped. But I haven't leveraged this personally and can't say with any certain how these methods may or may not reflect the "ready state" of particular instances.