Giter Club home page Giter Club logo

toxiproxy-node-client's Introduction

Toxiproxy Node Client

Build Status NPM version

Toxiproxy makes it easy and trivial to test network conditions, for example low-bandwidth and high-latency situations. toxiproxy-node-client includes everything needed to get started with configuring Toxiproxy upstream connection and listen endpoints.

Installing via NPM

The recommended way to install toxiproxy-node-client is through NPM.

Once that is installed and you have added toxiproxy-node-client to your package.json configuration, you can require the package and start using the library.

JavaScript (ES6) Usage

Here is an example for creating a proxy that limits a Redis connection to 1000KB/s.

// index.js
"use strict";
const toxiproxyClient = require("toxiproxy-node-client");

const getToxic = (type, attributes) => {
  const toxiproxy = new toxiproxyClient.Toxiproxy("http://localhost:8474");
  const proxyBody = {
    listen: "localhost:0",
    name: "ihsw_test_redis_master",
    upstream: "localhost:6379"
  };
  return toxiproxy.createProxy(proxyBody)
    .then((proxy) => {
      const toxicBody = {
        attributes: attributes,
        type: type
      };
      return proxy.addToxic(new toxiproxyClient.Toxic(proxy, toxicBody));
    });
  });

// { attributes: { rate: 1000 },
//   name: 'bandwidth_downstream',
//   stream: 'downstream',
//   toxicity: 1,
//   type: 'bandwidth' }
getToxic("bandwidth", { rate: 1000 })
  .then((toxic) => console.log(toxic.toJson()))
  .catch(console.error);

TypeScript Usage

Here is an example for creating a proxy that limits a Redis connection to 1000KB/s.

// index.ts
import {
    Toxiproxy,
    ICreateProxyBody,
    Toxic, ICreateToxicBody, Bandwidth
} from "toxiproxy-node-client";

const getToxic = async <T>(type: string, attributes: T): Promise<Toxic<T>> => {
  const toxiproxy = new Toxiproxy("http://localhost:8474");
  const proxyBody = <ICreateProxyBody>{
    listen: "localhost:0",
    name: "ihsw_test_redis_master",
    upstream: "localhost:6379"
  };
  const proxy = await toxiproxy.createProxy(proxyBody);

  const toxicBody = <ICreateToxicBody<T>>{
      attributes: attributes,
      type: type
  };
  return await proxy.addToxic(new Toxic(proxy, toxicBody));
};

// { attributes: { rate: 1000 },
//   name: 'bandwidth_downstream',
//   stream: 'downstream',
//   toxicity: 1,
//   type: 'bandwidth' }
getToxic("bandwidth", <Bandwidth>{ rate: 1000 })
  .then((toxic) => console.log(toxic.toJson()))
  .catch(console.error);

Documentation

Additional examples can be found in the examples directory for expected usage.

toxiproxy-node-client's People

Contributors

ihsw avatar chrisblossom avatar harshit-sinha-developer avatar

Watchers

 avatar

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.