Is It possible to send one request to two different target endpoints at the same time

I have got two different target endpoints in my apigee. Both the target endpoints accept a different json payload. So I have got one assign message policy in my request which matches one of the target backend server. Now i want to use another assign message policy which will match the other target backend server. 

So what i am trying to achieve is  when a request comes in the same content will go in two different types of payload to the target backend server.

Is that something possible to do in apigee and how do we do it?

0 1 907
1 REPLY 1

when a request comes in the same content will go in two different types of payload to the target backend server.

Yes, I think so, but there are caveats.

I think you mean, when a request is handled by Apigee, Apigee will send two different requests to two different targets, at the same time. Is that right?

Apigee is designed to be a synchronous HTTP proxy. a request arrives, your Apigee proxy might inspect it, validate a token, maybe enforce a rate limit, maybe lookup a dynamic endpoint, maybe modify the request (inject a header, transform the payload, etc), and then... finally.... the Apigee proxy sends the possibly modified request to the upstream (target) server. In simple terms, for each request that comes in, Apigee sends a corresponding request out to the target. The response handling is the converse.

OK, what you are asking is, is it possible to configure an Apigee proxy so that for each request that comes in, Apigee sends out TWO requests to TWO different targets.

And the answer to that is "Yes, sort of". The "one request in, one request out" model is very much intrinsic to the model of the Apigee proxy. If I use the term "Target" in a strict sense, then the answer is, "No, you can't have two targets for the same request in Apigee." But if you are ok with not having all the target server and TargetEndpoint capabilities, and you just want to send two requests out, then the answer is, Yes, you can do that.

Apigee has a builtin policy called ServiceCallout. It sends out an arbitrary HTTP request. You can attach a ServiceCallout policy to either the request flow or the response flow. That means you can configure your Apigee proxy to do all of what I described above (inspect, validate, enforce rate limit), as well as "send out an HTTP request". That request outbound would not be to the defined target, but to some arbitrary address. And Apigee would not send it at the same time as it invoked the target, but either before or after it invoked the target. If you choose to use this policy you would be responsible for forming the request (verb payload headers etc), and handling the response. IF the response is 400 what do you do? If it's 503, then what? You would have to handle all of that in your API proxy.

There is also an httpClient in the JavaScript step, which can be used in the same way:

So that's the caveat. You can configure Apigee to send out two requests. One would be to the actual target, and the second would be to an arbitrary endpoint.

Now that you have all this information, Maybe you can explain why you want to send out two requests?