首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >OpenShift上的Mosca (MQTT代理)

OpenShift上的Mosca (MQTT代理)
EN

Stack Overflow用户
提问于 2015-06-03 14:59:41
回答 1查看 729关注 0票数 0

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

代码语言:javascript
运行
复制
[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 install mosca --save)。即使不使用Mongo作为Mosca的持久存储库,只要在内存中运行,我在运行应用程序时就会得到上面显示的错误。据我所知,当我在笔记本电脑上运行它时,一切都是一样的。

我已经尝试了一些在堆栈溢出中找到的东西,比如在将代码推回git之前构建所有依赖模块,以及清理npm缓存,但都没有效果。

如果有人对其他模块有类似的体验,或者与Mosca有同样的经验,我会很感激,并且可能会为我指明正确的方向。

亲切的问候。

下面的代码是标准的Node示例应用程序模板,启动函数中有一个示例Mosca服务器。

代码语言:javascript
运行
复制
#!/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();
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-03 19:43:47

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30623788

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档