【问题标题】:Apigee Api proxy - how to make asynchronous callApigee Api 代理 - 如何进行异步调用
【发布时间】:2014-01-28 06:22:59
【问题描述】:

我有 api,我想在 apigee 收到消息后立即返回给用户。不要等待我的服务的响应。你知道如何使用 apigee api 代理来做到这一点吗?

【问题讨论】:

  • 尝试构建一个 Node.js 代理,您可以在其中返回一个即时(异步)响应,然后再发送另一个请求。
  • 感谢您的回答。我现在所做的是将 js 作为资源创建为 get() 到我的目的地并将其附加到我的端点。之后,我附加 raisefault 以尽快返回给用户,所以跟踪我看到大约 8 毫秒的响应。但是,我会按照@r3mus 的建议检查 node.js,因为它似乎是一个正确的解决方案,而不是像我那样“变通”。

标签: api asynchronous proxy response apigee


【解决方案1】:

上面提到的 node.js 方法可能是最直接的解决方案。有关在 Apigee 中使用 node.js 的信息,请访问 http://apigee.com/docs/api-services/content/developing-nodejs-applications-apigee-edge

【讨论】:

    【解决方案2】:

    我相信您使用 httpClient get 方法尝试了最初的正确方法 Kaszaq。正如 Apigee Docs 中所记录的那样。

    http://apigee.com/docs/api-services/content/javascript-object-model

    https://github.com/apigee/api-platform-samples/blob/master/sample-proxies/async-callout/apiproxy/resources/jsc/callout.js

    是的,如果您想要更强大的解决方案,请尝试 Node.js。

    //
    //  Make 5 HTTP callouts to Yahoo weather to get the weather for 5 cities 
    //  The calls are all asynchronous and execute in parallel
    //  httpClient returns an exchange object that will contain the HTTP response. . . when it arrives
    //
    
    var paloAlto = httpClient.get('http://weather.yahooapis.com/forecastrss?w=2467861'); 
    context.session['paloAlto'] = paloAlto;
    
    var anchorage = httpClient.get('http://weather.yahooapis.com/forecastrss?w=2354490'); 
    context.session['anchorage'] = anchorage;
    
    var honolulu = httpClient.get('http://weather.yahooapis.com/forecastrss?w=2423945');
    context.session['honolulu'] = honolulu;
    
    var newyork = httpClient.get('http://weather.yahooapis.com/forecastrss?w=2459115');
    context.session['newyork'] = newyork;
    
    var dublin = httpClient.get('http://weather.yahooapis.com/forecastrss?w=560743');
    context.session['dublin'] = dublin;
    

    【讨论】:

      【解决方案3】:

      因为您可以使用 Node.js 自定义 API。您可以使用它在您的 api 代理中实现异步行为。

      有关使用 Node.js 自定义 api 的更多信息,请访问以下链接 - http://apigee.com/docs/api-services/content/developing-nodejs-applications-apigee-edge

      【讨论】:

        猜你喜欢
        • 2014-09-17
        • 1970-01-01
        • 2019-01-31
        • 2018-08-05
        • 2021-08-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多