How to do target load balancing and append different query param for each targets?

Hi Guys,

We have a scenario where we have to do a load balancing with two target endpoints based on the availability of the target server. We are using health check HealthMonitor to check whether the target servers are accessible or not.

The challenge here is, we have to append a different query param for "target1" and "target2" servers.

Example:

If target server 1 is reachable (as a result of Health Monitor and Max Failure), then the service should call "target server 1 + query param 1" (i.e https://httpbin.org/get?code=abc)

Otherwise, call "target server 2 + query param 2" (i.e https://mocktarget.apigee.net/get?code=xyz)

Target Server 1 = https://httpbin.org/get

Target Server 1 Query param = abc

Target Server 2 = https://mocktarget.apigee.net/get

Target Server 2 Query param = xyz

We have a KVM where we've stored the query param details and assigning it to the query param.

<Get assignTo="request.queryparam.code">

<Key>

<Parameter>query_param</Parameter>

</Key>

</Get>

Initially, we don't have this load balancing scenario. Hence we have only one value and assigned it to the query param directly. But, now we have to append the different query params according to the target server.

The reason for this, Target server has the multi region capability. Hence we have to achieve the automatic failover in case one region is not available. Since it's two different regions the query param is also different for both the regions.

<TargetEndpoint name="default">
	<HTTPTargetConnection>
		<LoadBalancer>
			<Server name="target1" />
			<Server name="target2" />
			<MaxFailures>5</MaxFailures>
		</LoadBalancer>
		<Path>/get</Path>
		<HealthMonitor>
			<IsEnabled>true</IsEnabled>
			<IntervalInSec>5</IntervalInSec>
			<TCPMonitor>
				<ConnectTimeoutInSec>10</ConnectTimeoutInSec>
			</TCPMonitor>
		</HealthMonitor>
	</HTTPTargetConnection>
</TargetEndpoint>
0 3 434
3 REPLIES 3

Not applicable

I have two suggestions.

1. You can use flowhook for this particular proxy.

2. You can do proxy chaining and in the actual backend configured proxies you can set your query params.

@Priyadarshi Ajitav Jena : Thanks for the assistance. Would you be able to elaborate it further?

Not applicable

If you will create a shared flow having condition of the proxy name is your proxy and configure that to pre target flow hook, the flowhook will exicutive just before the request goes to target.

In shared flow you can use assign message policy for configuring queryparam for the target.

The other option is proxy chaining, you can configure two proxies for your two backends. Then configure those api endpoints in the main proxy as backend. Now in the two proxies in which the actual backends are configured, you can add policies for setting queryparams specific to them.