When you deal with API Proxies that have to be deployed in multiple environments target servers can help you with getting the backend URL right. A target server definition is basically a name for a backend URL, and you can set a different URL for each environment. By using target servers you can reference the target server name instead of hard-coding the backend URL directly.
Apigee Edge support defining target servers from the UI, and also through the Management API.
In this video we show how to create target servers and how to use it in your API Proxy. Also we demonstrate how to do load balancing over target servers.
Creating a target server definition through the Management API looks like this:
curl -H "Content-Type:text/xml" -X POST -d \ '<TargetServer name="OMDB"> <Host>www.omdbapi.com</Host> <Port>80</Port> <IsEnabled>true</IsEnabled> </TargetServer>' \ -u username@apigee.com https://api.enterprise.apigee.com/v1/o/orgname/environments/envname/targetservers
To reference the target server in the TargetEndpointHTTPConnection you use this XML snippet:
<LoadBalancer> <Server name="OMDB"/> </LoadBalancer> <Path>/</Path>
If you would like to use LoadBalancing over multiple target server definitions you simply include an algorithm element and all the target servers:
<LoadBalancer> <Algorithm>RoundRobin</Algorithm> <Server name="OMDB1" /> <Server name="OMDB2" /> <Server name="OMDB3" /> </LoadBalancer> <Path>/</Path>
The following algorithms are supported for loadbalancing:
More information about target servers can be found here:
any chance you can expand on this a bit and include some https details?
For SSL in combination with TargetServers you have two options.
1. One-way SSL
This one is easy. Make sure that you set the SSLInfo to enabled. When using a self-signed cert also add the truststore.
<TargetServer name="target1"> <Host>www.omdbapi.com</Host> <Port>443</Port> <IsEnabled>true</IsEnabled> <SSLInfo> <Enabled>true</Enabled> <TrustStore>myTrustStore</TrustStore> </SSLInfo> </TargetServer>
2. Mutual SSL
For mutual SSL you'll need to set the ClientAuthEnabled to true and also reference the private key in a keystore and (when using self-signed certs) a truststore in the target server definition.
<TargetServer name="TargetServer 1"> <IsEnabled>true</IsEnabled> <Host>www.omdbapi.com</Host> <Port>443</Port> <SSLInfo> <Ciphers/> <ClientAuthEnabled>true</ClientAuthEnabled> <Enabled>true</Enabled> <IgnoreValidationErrors>false</IgnoreValidationErrors> <KeyAlias>myKeyStoreAlias</KeyAlias> <KeyStore>myKeyStore</KeyStore> <Protocols/> <TrustStore>myTrustStore</TrustStore> </SSLInfo> </TargetServer >
For more information on this see here: http://docs.apigee.com/api-services/content/client-ssl-backend-servers
For information on setting up a TrustStore and KeyStore see http://docs.apigee.com/api-services/content/keystores-and-truststores
BTW, the doc had the algorithm as "LeastConnection" when it should have been "LeastConnections. The doc has been updated here.
Stephen
Can I use variable in name (<Server name="OMDB">) instead of some constant value.
Why i need to add
Path like this
<Path>/</Path>
Can i do like this ?
<Path>/test</Path>