Azure how to create an internal endpoint that has load ballancing?
How can an internal endpoint for a web role or a worker role have load ballance? If I declare the endpoint in ServiceDefinition.csdef as <InternalEndpoint name="GeneratePDF" protocol="tcp" />
, and then I expose it like:
// define an internal endpoint for inter-role traffic
RoleInstanceEndpoint internalEndP开发者_如何学运维oint =
RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["IGeneratePDF"];
this.serviceHost.AddServiceEndpoint(
typeof(IGeneratePDF),
binding,
String.Format("net.tcp://{0}/GeneratePDF", internalEndPoint.IPEndpoint));
than I get an endpoint that allows me to call each instance I want. But I don't get load ballancing this way, which is what I want.
probably not the ideal solution, but this seems to be one way of doing it...
int instances = RoleEnvironment.Roles["InstanceName"].Instances.Count;
Random rand = new Random();
var endpoint = RoleEnvironment.Roles["InstanceName"].Instances[rand.Next(instances)].InstanceEndpoints["YourEndpointName"].IPEndpoint;
from what i am reading, only working roles (Roles which are marked as ready) are in the Instances list, so you should only get instances which are working...
精彩评论