Layer 7 API Management

Expand all | Collapse all

Asynchronous HTTP Calls

Jump to Best Answer
  • 1.  Asynchronous HTTP Calls

    Posted 11-06-2017 01:42 AM

    My requirement is to make Asynchronous HTTP calls to multiple backends.
    Now if one particular http connection returns the response first,i should close rest of the connections and send only this single response.However if this particular http connection is not the first one to return response,i should wait for all connection response,aggregate them and send response.
    I can use Run All Assertions Currently to make asynchronous http calls but how to close http connection based on some other connection's response time.

     

    Regards,

    Sonalee Shyam



  • 2.  Re: Asynchronous HTTP Calls

    Posted 11-06-2017 07:25 PM

    Hello Sonalee,

    Could you please provide more details about the use case/business logic? Why you want to do things like that?

     

    Regards,

    Mark



  • 3.  Re: Asynchronous HTTP Calls

    Posted 12-04-2017 12:23 AM

    Hi Mark,

    My use case is something like this - I can get a JSON request with details of say N customers,i need to make N asynchronous HTTP call to get some response for each customer ,aggregate and send that as a single response.What i could like to know is if it is possible to make dynamic asynchronous calls where the number of calls depends upon how many customers are there in my JSON request.

     

    Regards,

    Sonalee Shyam



  • 4.  Re: Asynchronous HTTP Calls

    Posted 12-04-2017 07:26 PM

    Dear Sonalee ,

    As Jay Thorne said, asynchronous HTTP call is not supported.

    We can jsonpath N customers and put all the backends into a multivalued context variable, and then "run assertion to each item" to loop all the backends, and retrieve all the responses(one by one), and then you can aggregate those responses as you wish.

     

    Regards,

    Mark



  • 5.  Re: Asynchronous HTTP Calls

    Posted 12-04-2017 07:34 PM

    There's a way to handle this semi asynchronously.

     

    Use the concurrent all, and just check first in each thread to see if there's a request data structure present - if not, just return success and an empty data structure in that branch of the policy. You create a policy that runs 10 concurrent or something, and if you only run 6, you're great.

     

    On the other hand if you need 100, you don't really want asynchronous, because that leads to a LOT of concurrent threads/back end requests, which leaves you open to a denial of service just from the sheer number of things running. 



  • 6.  Re: Asynchronous HTTP Calls

    Posted 12-04-2017 07:52 PM

    Dear Jay Thorne,

    I think the problem is, the number of backends is dynamic.

    I'm not sure how to put dynamic number of assertions under "run all" assertion.

     

    Thanks,

    Mark

     



  • 7.  Re: Asynchronous HTTP Calls
    Best Answer

    Posted 11-07-2017 12:01 PM

    Your use case is the opposite what the run all assertion concurrently was expected to do.

     

    "Run All" waits for all child operations to complete. You want "if the special child operation completes early, cancel the other ones". Meaning you want abort the other routing assertions and only return one result. 

     

    We don't have what you are asking for, directly, because we didn't know about this use case; I'd say it is particularly uncommon. Asynchronously initiating another assertion to return early would require quite different tooling than what we have. 

     

    In the gateway product we don't generally make "this particular part of policy is special" distinctions; part of the power of the tool is that the composite assertions treat all their child assertions equally. 

     

    I can't see how we'd do what you want directly in our policy language as defined.