I have two Web Roles, another of which provides a data API an another one hosts a frontend www site and then some compute roles that produce data.
What I would like to achieve is in the www Web Role to query the VIP of the data API Web Role by running a query function that abstracts the details if I'm running locally or in Azure. It looks like querying the PublicIPEndpoint
would work in Azure, but not locally. The need would be such that I could further give out, say, some URL constants for JavaScript.
Is there a better way than to hardcode some string or, say, read the .csdef
file with a relative path and take it from there?
In code crudely something like
let IsInAzureFabric =
try
RoleEnvironment.IsAvailable
with _ ->
false
let IsInAzureCloud =
try
IsInAzureFabric && not RoleEnvironment.IsEmulated
with _ ->
false
let GetVirtualIP(roleName, endPoint) =
try
if IsInAzureCloud then
//Collect the protocol (http/https) from the endpoint information and pick only one endpoint as it's the one shown on the loadbalancer...
RoleEnvironment.Roles.[roleName].Instances
|> Seq.map(fun roleInstance -> "http://" + roleInstance.InstanceEndpoints.[endPoint].PublicIPEndpoint.ToString())
elif IsInAzureFabric then
//In local development fabric...
Seq.ofList ["http://localhost:8080"]
else
//This is locally outside of Azure Fabric (or in virtual machine?).
Seq.ofList ["http://localhost:1943"]
with _ ->
Seq.empty