1.) Question: I would like to know, how can I require and use a node module inside of an FOXX application.
我想使用nemopersona的名为:node-json-rpc的NPM模块作为客户端 . 可能也作为服务器 . 但至少作为客户端从RPC的其他地方获取数据很方便 .
似乎FOXX不喜欢那条特定的行:只要我添加这行foxx应用程序就会抛出错误 .
var rpc = require('node-json-rpc');
我已经将NPM模块(包)添加到各种目录中,例如:
/myfoxxappdirectory/node_modules
/usr/share/arangodb/js/common/modules
/usr/share/arangodb/js/node/node_modules
在我进行更改后,我重新启动Arangodb服务器 . 但它不喜欢模块 . 另外我认为它不具体那条线:
// Create a server object with options
var serv = new rpc.Server(options);
在这里你可以看到我的FOXX应用程序的完整代码,它不起作用 .
(function () {
var rpc = require('node-json-rpc'); // FOXX throws error at that line
//"use strict";
var Controller = require("org/arangodb/foxx").Controller,
Repository = require("org/arangodb/foxx").Repository,
console = require("console"),
arangodb = require("org/arangodb"),
db = arangodb.db,
actions = require("org/arangodb/actions"),
//helloworld = require("./lib/a").text,
controller = new Controller(applicationContext),
central = new Repository(controller.collection("centraladdressdb"));
// .............................................................................
// Example: Route without parameters & simple text output with static text
// .............................................................................
controller.get('/hello', function (req, res) {
res.set("Content-Type", "text/plain; charset=utf-8");
res.body = "blabla it works!\n";
});
}());
2.) Question: Are the FOXX commands asyncronous like in pure Nodejs? 例如,当我们查看命令以在FOXX应用程序中查找ArangoDB文档时:
FOXX应用代码:
var accountdoc;
accountdoc = db.mysupercollection.document('rumpelstilzchen'); // find doc by _key
显然这不是一个匿名的回调,对吗?它必须是阻止的 . 它会阻止服务器吗?这是我真正想知道的,它必须阻止服务器 . 但我是否也可以在FOXX-apps中编写ArangoDB数据库命令以进行I / O操作,例如回调式以避免阻塞?它是Nodejs和javascript编写非阻塞代码的最大优势 . 是否有可能用FOXX做到这一点?
在Nodejs中有一个javascript驱动程序,以非阻塞方式对Arango进行I / O操作 .
然后是ArangoDB中的交易 . 还有阻塞 . 但对于ACID交易,我认为阻止本身是可取的 . 所以我们不需要回调 .
但是在访问ArangoDB的FOXX应用程序中,为什么不呢?我错过了什么?
请尽可能帮助我,非常感谢你 .
1 回答
(1)我认为为了使"node-json-rpc"模块工作,需要支持node.js兼容的"http"模块 . 你应该联系谷歌组https://groups.google.com/forum/?hl=de#!forum/arangodb
(2)ArangoDB是多线程的 . 它使用非阻塞I / O和worker来处理请求 . 因此它不会阻止服务器 . 如果你写
在你的Foxx应用程序中,这将在一个工作线程中执行 . 将此调用异步化是非常困难的,因为与I / O通信不同,没有单一事件可以作出反应 . 因此,使用工作线程要快得多 .