js-bson错误-OpenShift上的Mosca(MQTT经纪人) [英] js-bson error - Mosca (MQTT Broker) on OpenShift

查看:87
本文介绍了js-bson错误-OpenShift上的Mosca(MQTT经纪人)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在OpenShift上使用NodeJS进行一些工作,当我试图在Node实例中运行Mosca服务器时遇到了一个问题。我收到的错误如下:

I've been doing some work with NodeJS on OpenShift and am facing a problem when I'm trying to run a Mosca server in a Node instance. The error I'm getting is as follows:

[Error: /var/lib/openshift/5547bd284382ec394a000088/app-root/runtime/repo/node_modules/mosca/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/build/Release/bson.node: invalid ELF header]
js-bson: Failed to load c++ bson extension, using pure JS version

我最近从OpenShift创建了一个新应用程序从头开始使用NodeJS墨盒,并从墨盒中克隆了示例应用程序git存储库作为起点。为此,我通过npm添加了mosca( npm install mosca --save )。甚至没有将Mongo用作Mosca的持久存储,因此仅在内存中运行时,在运行应用程序时出现了上面显示的错误。据我所知,当我在笔记本电脑上运行它时,一切都相同,就很好。

I have recently created a new Application (on OpenShift) from scratch with a NodeJS cartridge and have cloned the sample app git repository from the cartridge as the starting point. Into this I have added mosca via npm (npm install mosca --save). Without even using Mongo as a persistent store for Mosca, so just running in memory, I get the error shown above when I run the application. It's fine when I run it on my laptop, same versions of everything, as far as I can tell.

我已经尝试了一些发现的东西堆栈溢出,例如在将代码推回git并清理npm缓存但无济于事之前构建所有相关模块。

I've already tried a few things I've found on Stack Overflow, such as building all the dependent modules before pushing code back to git and cleaning npm cache but to no avail.

如果有人遇到类似问题,我将不胜感激。拥有其他模块的经验,或者具有与Mosca相同的经验,也许可以为我指明正确的方向。

I'd appreciate if anyone has had a similar experience with other modules or the same experience with Mosca and might be able to point me in the right direction.

亲切的问候。

下面的代码是标准的Node示例应用程序模板,在启动功能中带有示例Mosca服务器。

The code below is the standard Node sample application template, with a sample Mosca server in the start function.

#!/bin/env node
//  OpenShift sample Node application
var express = require('express');
var fs      = require('fs');
var mosca   = require('mosca');

/**
 *  Define the sample application.
 */
var SampleApp = function() {

    //  Scope.
    var self = this;

    /*  ================================================================  */
    /*  Helper functions.                                                 */
    /*  ================================================================  */

    /**
     *  Set up server IP address and port # using env variables/defaults.
     */
    self.setupVariables = function() {
        //  Set the environment variables we need.
        self.ipaddress = process.env.OPENSHIFT_NODEJS_IP;
        self.port      = process.env.OPENSHIFT_NODEJS_PORT || 8080;

        if (typeof self.ipaddress === "undefined") {
            //  Log errors on OpenShift but continue w/ 127.0.0.1 - this
            //  allows us to run/test the app locally.
            console.warn('No OPENSHIFT_NODEJS_IP var, using 127.0.0.1');
            self.ipaddress = "127.0.0.1";
        };
    };


    /**
     *  Populate the cache.
     */
    self.populateCache = function() {
        if (typeof self.zcache === "undefined") {
            self.zcache = { 'index.html': '' };
        }

        //  Local cache for static content.
        self.zcache['index.html'] = fs.readFileSync('./index.html');
    };


    /**
     *  Retrieve entry (content) from cache.
     *  @param {string} key  Key identifying content to retrieve from cache.
     */
    self.cache_get = function(key) { return self.zcache[key]; };


    /**
     *  terminator === the termination handler
     *  Terminate server on receipt of the specified signal.
     *  @param {string} sig  Signal to terminate on.
     */
    self.terminator = function(sig){
        if (typeof sig === "string") {
           console.log('%s: Received %s - terminating sample app ...',
                       Date(Date.now()), sig);
           process.exit(1);
        }
        console.log('%s: Node server stopped.', Date(Date.now()) );
    };


    /**
     *  Setup termination handlers (for exit and a list of signals).
     */
    self.setupTerminationHandlers = function(){
        //  Process on exit and signals.
        process.on('exit', function() { self.terminator(); });

        // Removed 'SIGPIPE' from the list - bugz 852598.
        ['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT',
         'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGTERM'
        ].forEach(function(element, index, array) {
            process.on(element, function() { self.terminator(element); });
        });
    };


    /*  ================================================================  */
    /*  App server functions (main app logic here).                       */
    /*  ================================================================  */

    /**
     *  Create the routing table entries + handlers for the application.
     */
    self.createRoutes = function() {
        self.routes = { };

        self.routes['/asciimo'] = function(req, res) {
            var link = "http://i.imgur.com/kmbjB.png";
            res.send("<html><body><img src='" + link + "'></body></html>");
        };

        self.routes['/'] = function(req, res) {
            res.setHeader('Content-Type', 'text/html');
            res.send(self.cache_get('index.html') );
        };
    };


    /**
     *  Initialize the server (express) and create the routes and register
     *  the handlers.
     */
    self.initializeServer = function() {
        self.createRoutes();
        self.app = express();

        //  Add handlers for the app (from the routes).
        for (var r in self.routes) {
            self.app.get(r, self.routes[r]);
        }
    };


    /**
     *  Initializes the sample application.
     */
    self.initialize = function() {
        self.setupVariables();
        self.populateCache();
        self.setupTerminationHandlers();

        // Create the express server and routes.
        self.initializeServer();
    };


    /**
     *  Start the server (starts up the sample application).
     */
    self.start = function() {
        //  Start the app on the specific interface (and port).
        self.app.listen(self.port, self.ipaddress, function() {
            console.log('%s: Node server started on %s:%d ...',
                        Date(Date.now() ), self.ipaddress, self.port);
        });

        // START MOSCA SERVER

            var server = new mosca.Server({});

            server.on('clientConnected', function(client) {
                console.log('client connected', client.id);
            });

            // fired when a message is received
            server.on('published', function(packet, client) {
              console.log('Published', packet.payload);
            });

            server.on('ready', function() {
                console.log('Mosca server is up and running');
            });

    };

};   /*  Sample Application.  */



/**
 *  main():  Main code.
 */
var zapp = new SampleApp();
zapp.initialize();
zapp.start();


推荐答案

无效的ELF标头通常表示您尝试使用的二进制文件要执行的代码是在与您尝试在其上运行的系统不兼容的系统上编译的(在x86上编译,在x86_64上运行等)。您是否要将应用程序中的node_modules目录提交到git?您应该让OpenShift应用程序为您安装正确的节点模块,而不要提交该目录/将其添加到git版本控制系统中。

Invalid ELF header usually means that the binary you are trying to execute was compiled on a system that is not compatible with the system you are trying to run it on (compiled on x86, running on x86_64, etc). Are you committing your node_modules directory within your application to git? You should let your OpenShift application install the correct node modules for you and not commit that directory / add it into your git version control system.

这篇关于js-bson错误-OpenShift上的Mosca(MQTT经纪人)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆