moleculer-repl

作者: Odeng | 来源:发表于2018-12-13 22:21 被阅读0次

标题: REPL 控制台程序

moleculer repl 是Moleculer的一个交互性的控制台程序

2018-12-13_185656.png

安装

npm install moleculer-repl --save

使用

切换 broker 到 REPL 模式

let broker = new ServiceBroker({ logger: console });

// Switch to REPL mode
broker.repl();

REPL 命令

  Commands:
    help [command...]                         Provides help for a given command.
    exit                                      Exits application.
    q                                         Exit application
    call <actionName> [jsonParams]            Call an action
    dcall <nodeID> <actionName> [jsonParams]  Direct call an action
    emit <eventName>                          Emit an event
    broadcast <eventName>                     Broadcast an event
    broadcastLocal <eventName>                Broadcast an event to local services
    load <servicePath>                        Load a service from file
    loadFolder <serviceFolder> [fileMask]     Load all service from folder
    actions [options]                         List of actions
    events [options]                          List of events
    services [options]                        List of services
    nodes [options]                           List of nodes
    info                                      Information from broker

列出 nodes

mol $ nodes

命令选项

    -d, --details  Detailed list
    -a, --all      List all (offline) nodes

输出

image

列出 services

mol $ services

命令选项

    -l, --local         Only local services
    -i, --skipinternal  Skip internal services

输出

image

列出 actions

mol $ actions

命令选项

    -l, --local         Only local actions
    -i, --skipinternal  Skip internal actions
    -d, --details       Print endpoints

输出

image

列出 events

mol $ events

命令选项

    -l, --local         Only local events
    -i, --skipinternal  Skip internal events
    -d, --details       Print endpoints

输出

显示常规信息

mol $ info

输出

image

调用一个请求处理器

mol $ call "test.hello"

调用一个带参请求处理器

mol $ call "math.add" --a 5 --b Bob --c --no-d --e.f "hello"

参数是 { a: 5, b: 'Bob', c: true, d: false, e: { f: 'hello' } }

参数为JSON格式的调用

mol $ call "math.add" '{"a": 5, "b": "Bob", "c": true, "d": false, "e": { "f": "hello" } }'

参数是 { a: 5, b: 'Bob', c: true, d: false, e: { f: 'hello' } }

直接调用

获取节点node-12的运行参数信息

mol $ dcall "node-12" "$node.health"

参数传递有点类似调用命令。

触发事件

mol $ emit "user.created"

触发带参事件

mol $ emit "user.created" --a 5 --b Bob --c --no-d --e.f "hello"

参数是 { a: 5, b: 'Bob', c: true, d: false, e: { f: 'hello' } }

从文件读取服务

mol $ load "./math.service.js"

从文件夹中读取所有服务

mol $ load "./services"

参考资料

  1. moleculer 官方文档:https://moleculer.services/docs/0.13/moleculer-repl.html

本文原文出自moleculer官网,如有翻译不当还请见谅

相关文章

  • moleculer-repl

    标题: REPL 控制台程序 moleculer repl 是Moleculer的一个交互性的控制台程序 安装 ...

网友评论

    本文标题:moleculer-repl

    本文链接:https://www.haomeiwen.com/subject/pmobhqtx.html