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

clouds

v0.3.4

Published

lightweight remote services framework base on Redis 基于Redis的分布式服务框架

Downloads

108

Readme

分布式服务框架

基于Redis的分布式服务框架,传输层使用super-queue消息队列模块。

安装

$ npm install clouds --save

服务提供者(Server)

var clouds = require('clouds');

// 创建服务提供者
var server = new clouds.Server({
  // redis连接配置
  redis: {
    host: '127.0.0.1',
    port: 6379,
    db: 3
  },
  // 心跳周期,如果服务提供者异常下线,超过指定时间将自动从服务器端删除,单位:秒
  heartbeat: 2
});

// 注册服务处理程序
server.register('test.hello', function (name, msg, callback) {
  // 函数的最后一个参数表示回调函数,客户端在调用的时候必须保证参数数量是一致的
  // 回调函数第一个参数表示是否出错,第二个参数起表示返回的结果
  callback(null, 'Hello ' + name + ', ' + msg);
});

客户端(Client)

const clouds = require('clouds');

const client = new clouds.Client({
  // redis连接配置
  redis: {
    host: '127.0.0.1',
    port: 6379,
    db: 3
  },
  // 调用超时时间,如果服务器超过指定时间没有响应结果,则认为调用失败,单位:秒
  timeout: 2
  // 本地超时检查(timeout的倍数),默认为1.1,小于1表示不进行本地检查(如果没有启动server端,可能会导致回调无法执行)
  timeoutChecker: 1.1,
  // 心跳周期,如果服务提供者异常下线,超过指定时间将自动从服务器端删除,单位:秒
  heartbeat: 2
});

// 返回一个函数,用于直接调用远程服务
const testHello = client.bind('test.hello');

client.ready(() => {
  // 当所有bind()的函数都已经准备就绪时只需回调
});

// 调用远程服务,跟使用本地普通函数差不多
testHello('Glen', 'timestamp is ' + Date.now(), (err, ret) => {
  console.log(err, ret);
});

// 也可以这样直接调用,第一个参数是服务名,第二个参数是调用参数数组,第三个参数是回调函数
client.call('test.hello', ['Glen', 'timestamp is ' + Date.now()], (err, ret) => {
  console.log(err, ret);
});

监视器(Monitor)

var clouds = require('clouds');

// 创建服务器
var monitor = new clouds.Monitor({
  // redis连接配置
  redis: {
    host: '127.0.0.1',
    port: 6379,
    db: 3
  }
});

// 获取状态
monitor.status(function (err, info) {
  console.log(err, info);
  // info.methods服务名对应的服务器ID列表
  // info.servers服务器对应的服务名列表
});

License

Copyright (c) 2012-2016 Zongmin Lei (雷宗民) <[email protected]>
http://ucdok.com

The MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.