In my Azure role I need to be able to query the current number of instances at any time.
I don't have any internal endpoints, so I can't use Role.Instances. I can use Management API, but it's relatively time consuming and querying it sometimes results in protocol timeout errors and I'd prefer to not deal with timeouts.
Looks like there's RoleEnvironment.Changing event that can contain RoleEnvironmentTopologyChange class objects that reflects which role changes the instance count. This would be optimal for me - I wouldn't need to do any external calls, just store the new instance count when it changes, so no overhead and no timeouts. Yet I can't find whether it's possible to find the new instance count when RoleEnvironment.Changing fires.
Is it possible to detect the changes in role instance count and the actual number of instances using only RoleEnvironment.Changing or similar events in Azure?
Yes, inside that event handler, you can use RoleEnvironment.Roles to obtain a list of roles. Then for each role, you can use the Instances property to find how many instances does that role have. It is not needed to use management API. To detect change, query instance count during the instance's startup, and save the data in memory, so you can compare it later.
Best Regards,
Ming Xu.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With