Poul K. Sørensen
Poul K. Sørensen

Reputation: 17560

Azure RoleInstance Id when scaling out, RoleEnvironmentTopologyChange not fired

Will the first instance deployed always end with a zero ? 0. like "xxxx_IN_0" When scaling up to X instanses, will the next instanses always get 1 2 3 4 as the last number. ( I think so). What happens when I scale down again? I read that it will take at random one of the instances. So when scaling down to 1 instance, I cant assume that I know what ID is the one that still are running?.

Anyone who have been playing with the IDs when scaling up and down and know those things?

The reason for me asking is that I have some extra logic that I want to run on only one, not less or more, of the instances. If I can assume that the "xxx_IN_0" is always present then i can just do it with a simple check that last of ID is zero. If not, I am considering to check all ids and if the current instance is the lowest, then it will do its magic.

If the last case, are there an event i can monitor for when scaling up or down is done?.

update

From Answer:

    if (RoleEnvironment.IsAvailable)
    {
        RoleEnvironment.Changed += RoleEnvironment_Changed;
    }

    void RoleEnvironment_Changed(object sender, RoleEnvironmentChangedEventArgs e)
    {
        var change = e.Changes.OfType<RoleEnvironmentTopologyChange>().FirstOrDefault();
        if (change != null)
        {
            Trace.TraceInformation("RoleEnvironmentTopologyChange at RoleName '{0}'", change.RoleName);
    }

I do not get any information in my tracelog when i scale up and down.

There have to be set a internal endpoint to trigger the events:

<InternalEndpoint name="InternalEndpoint1" protocol="http" />

http://blogs.msdn.com/b/windowsazure/archive/2011/01/04/responding-to-role-topology-changes.aspx

Upvotes: 2

Views: 303

Answers (1)

M&#229;rten Wikstr&#246;m
M&#229;rten Wikstr&#246;m

Reputation: 11344

You should listen to the RoleEnvironment.Changed event which occurs when the service configuration is changed.

When you receive this event, check the Changes property for an instance of RoleEnvironmentTopologyChange. This change will be reported when the number of instances are changed.

To determine on which server you should run that extra logic you could examine the list of roles and from there find all instances. Sort instances by id and select the first to be the special one.

However, if it is critical that only a single server run this special logic at any time, you will need a more stable solution.

Upvotes: 4

Related Questions