简体   繁体   English

ArangoDB:关于FOXX的一些问题

[英]ArangoDB: Some questions about FOXX

1.) Question: I would like to know, how can I require and use a node module inside of an FOXX application. 1.)问题:我想知道,我如何在FOXX应用程序中要求和使用节点模块。

i would like to use the NPM module named: node-json-rpc by nemopersona as a client. 我想使用nemopersona的名为:node-json-rpc的NPM模块作为客户端。 Probably also as a Server. 可能也作为服务器。 But at least as a client to fetch data from somewhere else by RPC which is convenient. 但至少作为客户端从RPC的其他地方获取数据很方便。

It seems that FOXX does not like that specific line: As soon as I add this line the foxx app it throws an error. 似乎FOXX不喜欢那条特定的行:只要我添加这行foxx应用程序就会抛出错误。

var rpc = require('node-json-rpc');

I already added the NPM module (package) into various directories like: 我已经将NPM模块(包)添加到各种目录中,例如:

/myfoxxappdirectory/node_modules
/usr/share/arangodb/js/common/modules
/usr/share/arangodb/js/node/node_modules

After I make changes I restart the Arangodb server. 在我进行更改后,我重新启动Arangodb服务器。 But it does not like modules. 但它不喜欢模块。 Also I think it does not like specificly that line: 另外我认为它不具体那条线:

// Create a server object with options
var serv = new rpc.Server(options);

And here you can see the full code of my FOXX App, which is not working. 在这里你可以看到我的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? 2.)问题:FOXX命令是否与纯Nodejs一样异常? For example when we look at a command to find a ArangoDB Document in FOXX applications: 例如,当我们查看命令以在FOXX应用程序中查找ArangoDB文档时:

FOXX application code: FOXX应用代码:

var accountdoc;
accountdoc = db.mysupercollection.document('rumpelstilzchen'); // find doc by _key

Obviously that is not an anonymous callback, am I right? 显然这不是一个匿名的回调,对吗? It must be blocking. 它必须是阻止的。 And does it block the server? 它会阻止服务器吗? This is what I am really wondering about, it must block the server. 这是我真正想知道的,它必须阻止服务器。 But could I also write ArangoDB database commands in FOXX-apps for I/O operations like a callback-style to avoid blocking? 但我是否也可以在FOXX-apps中编写ArangoDB数据库命令以进行I / O操作,例如回调式以避免阻塞? Its the big advantage of Nodejs and javascript to write non-blocking code. 它是Nodejs和javascript编写非阻塞代码的最大优势。 Is it possible to do that with FOXX too? 是否有可能用FOXX做到这一点?

In Nodejs there is a javascript driver that does I/O to Arango in nonblocking style. 在Nodejs中有一个javascript驱动程序,以非阻塞方式对Arango进行I / O操作。

Then there are transactions in ArangoDB. 然后是ArangoDB中的交易。 There is also blocking. 还有阻塞。 But for ACID transactions I think blocking itself is desirable. 但对于ACID交易,我认为阻止本身是可取的。 So there we would not need callbacks. 所以我们不需要回调。

But in FOXX applications when accessing ArangoDB, why not there? 但是在访问ArangoDB的FOXX应用程序中,为什么不呢? Am I missing something?? 我错过了什么?

Please help me if possible, and many thanks to you. 请尽可能帮助我,非常感谢你。

(1) I think in order to get "node-json-rpc" module to work, support for a node.js compatible "http" modules is required. (1)我认为为了使“node-json-rpc”模块工作,需要支持node.js兼容的“http”模块。 You should contact the google group https://groups.google.com/forum/?hl=de#!forum/arangodb 您应该与Google论坛小组联系https://groups.google.com/forum/?hl=de#!forum/arangodb

(2) ArangoDB is multi-threaded. (2)ArangoDB是多线程的。 It uses non-blocking I/O and workers to handle the requests. 它使用非阻塞I / O和worker来处理请求。 Therefore it does not block the server. 因此它不会阻止服务器。 If you write 如果你写

var accountdoc;
accountdoc = db.mysupercollection.document('rumpelstilzchen'); // find doc by _key

in your Foxx application, this will get executed in a worker thread. 在你的Foxx应用程序中,这将在一个工作线程中执行。 It would be very difficult to make this call asynchronous, because unlike say the I/O communication there is no single event on which to react. 将此调用异步化是非常困难的,因为与I / O通信不同,没有单一事件可以作出反应。 Therefore it is much faster to use work threads instead. 因此,使用工作线程要快得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM