Code Monkey home page Code Monkey logo

thriftily's Introduction

Thriftily

A plugin for use thrift clients quickly and friendly with nodejs or eggjs.

Support: Node 10+,Eggjs

Npm Version License Npm Download

Useage

npm install thriftily --save

Common Config

const config = {
  app: true, // default true, use it with eggjs app
  agent: false, // default false, use it with eggjs agent
  pinglog: true, // default false,false is use logger.debug, ture is use logger.info print the ping log.
  default: {
    // it will as default as all clients config
    reconnect: true, // default true
    reconnectMaxTimes: 200, // default 0, 0 means no limit
    reconnectMaxSleep: 30000, // default 60000ms, reconnect sleep equals reconnect times multiplication 1000ms.
    host: '1.2.3.4',
    pingSleep: 5000 // default 10000ms
  },
  clients: {
    // clients config example, msFoo & msBar as alias name
    msFoo:{
      host: 'foohost',
      port: 'fooport',
      client: yourFooGenjs
      ping: 'youpingName',  // your ping method name in yourFooGenjs
      pingSleep: 5000
    },
    msBar:{
      host: 'barhost',
      port: 'barport',
      client: yourBarGenjs
    }
  }
}

With Egg

config/plugin.js

module.exports.thriftily = {
  enable: true,
  package: 'thriftily'
}

config/config.js

module.exports.thriftily = thriftilyConfig // same as upper common config

Use in service

const { Service } = require('egg')

class FooService extends Service {
  bar() {
    const { app } = this
    const { client } = app.thriftily.get('your client name')
    try{
      const res = await client.yourClientMethod()
    }catch(e){
      console.log(e)
    }
  }
}

With Node

const { ThriftilyManager } = require('thriftily')
const thriftilyConfig = require('your config path')

const manager = new ThriftilyManager(yourConfig, yourLogger)
manager.start()

const { client } = manager.get('your client alias')

try {
  const res = await client.yourClientMethod()
} catch (e) {
  console.log(e)
}

thriftily's People

Stargazers

 avatar lbb avatar

Watchers

lbb avatar

Forkers

zbl91555

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.