npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kitejs

v1.1.11

Published

the rpc framework Kite for Node.js

Downloads

176

Readme

kitejs

说明

kitejs 提供统一访问服务的 client,支持 Http、RPC(thrift) 协议,提供多种编解码方式(正在支持)。 kitejs 集成寻址、支持负载均衡策略

使用

首先进行安装

npm install kitejs --save

使用方法

// for HTTP
const kite = require('kitejs');

var client = new kite.Client(
    {
        host: '127.0.0.1',
        port: 8080,
        protocol: 'HTTP',
        log: {
            logFile: __dirname + '/client.log',
            logId: Date.now()
        }
    }
);

// use request component
client.request({ path: '/' }, function (err, data) {
    if (err) throw err;
    console.log(data);   
});
// for THRIFT
const kite = require('kitejs');

var client = new kite.Client(
    {
        host: '127.0.0.1',
        port: 8080,
        protocol: 'THRIFT',
        log: {
            logFile: __dirname + '/client.log',
            logId: Date.now()
        }
    }
);

client
    .loadService(__dirname + '/thrift/gen-nodejs/Calculator.js')
    .request(function (err, cal, conn) {
        if (err) throw err;
        cal.ping(function (err, response) {
            console.log('ping()');
        });

        cal.add(1, 1, function (err, response) {
            console.log(response);
        });
    });
// for CONSUL
const kite = require('kitejs');

var client = new kite.Client({
    service: 'ies.fe.mis',
    searchHostType: 'CONSUL',
    log: {
        logFile: __dirname + '/client.log',
        logId: Date.now()
    }
});

client.request({path: '/'}, function (err, data) {
    console.log(data);
});

接口

Client(options) 客户端类

可以方便的创建一个 Client 用于请求。。。

Options

  • protocol 访问协议,HTTP \ THRIFT,默认HTTP

  • searchHostType 寻址方式 LOCAL 或者 CONSUL,默认LOCAL

  • service consul 时提供 PSM 信息

  • host 服务端域名信息

  • port 服务端端口信息

  • timeout 访问超时时间 1s 100ms or 1 默认为

  • address 更人性化的地址设置,比如 127.0.0.1:10220

  • consul 提供 consul 服务地址信息

  • retry 重试次数,当网络不稳定时,需要重试 2

  • transport 选择的thrift协议。FRAMED | BUFFERED

    {
        consul: {
            host: '127.0.0.1',
            port: 2280
        }
    }

Client.request 发起请求,获取服务端数据

.request(options?, cb);

参数

  • options 可选,主要用于 HTTP 填写 PATH、HEADERS 等信息

    • request 的参数
  • cb

    function (err, data, conn?) {}
    • err 如果发生错误,err 为 Error 对象实例,如果未发生错误为 null
    • data
      • protocol=THRIFT 时,返回 Service 对象
      • protocol=HTTP 时,直接返回请求 response 的内容
    • conn 可选参数,如果 THRIFT 时,返回请求 connection ,可以方便 Service 获取到数据后关闭连接。

Client.loadService 加载 Thrift Service

参数

client.loadService('xxService.js')
// return client Object instance.
  • Thrift Service 的 path,框架会 load xxService.js 并注册入 Thrift 请求框架

返回

  • Client 对象实例