Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xyj-consul

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xyj-consul

smart sport consul service

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

xyj-consul

结合smartsport项目架构使用,接口使用node-consul搭建,在node-consul的基础上封装易于结合smartsport项目使用的接口

Installation

install via NPM

$ npm install --save xyj-consul

Example Usage

创建实例:

const Consul = require('xyj-consul');

const consul = new Consul({host: '127.0.0.1', port: 8500}); // default: host-127.0.0.1, port-8500

服务注册:

const opts = {
  name: 'example',
  tags: ['example'],
  address: '127.0.0.1',
  servicePort: '10001'
};
consul.register(opts);

服务发现(格式化适用于web层):

consul.listFormat((err, result) => {
  if(err) throw err;
  console.log(result);
  /*
  { example: { host: '127.0.0.1', port: 8500 },
  example1: { host: '127.0.0.1', port: 8500 },
  example2: { host: '127.0.0.1', port: 8500 } }
  */
})

API

consul.register(options, callback)

Registers a new service.

Options

  • name (String): service name
  • id (String, optional): service ID
  • tags (String[], optional): service tags
  • address (String, optional): service IP address
  • port (Integer, optional): service port
  • check (Object, optional): service check
    • http (String): URL endpoint, requires interval
    • tcp (String): host:port to test, passes if connection is established, fails otherwise
    • script (String): path to check script, requires interval
    • dockercontainerid (String, optional): Docker container ID to run script
    • shell (String, optional): shell in which to run script (currently only supported with Docker)
    • interval (String): interval to run check, requires script (ex: 15s)
    • timeout (String, optional): timeout for the check (ex: 10s)
    • ttl (String): time to live before check must be updated, instead of http/tcp/script and interval (ex: 60s)
    • notes (String, optional): human readable description of check
    • status (String, optional): initial service status
    • deregistercriticalserviceafter (String, optional, Consul 0.7+): timeout after which to automatically deregister service if check remains in critical state
  • checks (Object[], optional): service checks (see check above)

Usage

consul.register('example', function(err) {
  if (err) throw err;
});

consul.list(callback)

Returns the services the agent is managing.

Usage

consul.list(function(err, result) {
  if (err) throw err;
});

Result

{
  "example": {
    "ID": "example",
    "Service": "example",
    "Tags": [
      "dev",
      "web"
    ],
    "Port": 80
  }
}

consul.listFormat(callback)

返回格式化后适合web服务层使用的列表格式

Usage

consul.listFormat(function(err, result) {
  if (err) throw err;
});

Result

{ 
  example: { 
    host: '127.0.0.1', 
    port: 8500 
  },
  example1: { 
    host: '127.0.0.1', 
    port: 8500 
  },
  example2: { 
    host: '127.0.0.1', 
    port: 8500 
  }
}

consul.consul

直接返回node-consul实例

TODO

  • all

License

@MIT

Keywords

FAQs

Package last updated on 18 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc