Apigee Api代理 - 如何进行异步调用

时间:2014-01-09 15:43:17

标签: api asynchronous proxy response apigee

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

3 个答案:

答案 0 :(得分:2)

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

找到

答案 1 :(得分:1)

我相信您使用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;

答案 2 :(得分:0)

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

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