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

circuit-breaker-nodejs

v1.0.0

Published

**npm v1.0.0**

Downloads

32

Readme

Circuit Breaker for Node.js

npm v1.0.0

Overview

The Circuit Breaker for Node.js library is a powerful and flexible implementation of the circuit breaker pattern for handling external service dependencies in Node.js applications. It helps you build more resilient and fault-tolerant applications by preventing cascading failures when a service experiences issues.

Features

  • Configurable Circuit Breaker: Easily configure circuit breaker settings such as failure thresholds, success thresholds, timeouts, and more to suit your application's needs.
  • Proxy Support: Seamlessly integrate with HTTP and HTTPS proxies, allowing you to route requests through a proxy server.
  • Logging: Integrated logging for tracking requests and circuit breaker state changes.
  • Customizable Callbacks: Define custom success and failure callback functions for fine-grained control.
  • Promises: Utilizes Promises to make it easy to work with asynchronous operations.

Installation

You can install the Circuit Breaker for Node.js library via npm:

npm install circuit-breaker-sns28

Usage

Importing the Library To use the library in your Node.js application, import it as follows:

const { CircuitBreaker, setProxyAgent } = require('circuit-breaker-sns28');

or

import { cbInit, cbSuccess } from './circuit-breaker-sns28';

Basic Example
Here's a basic example of how to use the circuit breaker:
// Initialize the Circuit Breaker with configuration
cbInit({
      requestUrl,
      jsonObjectData,
      headersObjectData,
      cbfailurethreshold,
      cbsuccessthreshold,
      cbtimeoutms,
    })

You can call 'cbInit' function with the target request's data; it will trigger the request, and while doing so, the circuit breaker instance will be activated. It will return a promise that you can handle as per your need.

// Execute a request using the circuit breaker
cbSuccess() and cbFailure() methods can be called in the callback of the request you are making; these will keep track of success and failure attempts against a particular URL.

// Configure a proxy agent if needed
setProxyAgent({ proxyUrl: 'https://proxy.example.com' });

This proxy agent function is used inside the got request to set the proxy; you can provide other parameters like:
{
	keepAlive: true,
	keepAliveMsecs: 1000,
	maxSockets: 256,
	maxFreeSockets: 256,
	scheduling: 'lifo',
	proxy: proxyUrl,
}

Expected Behaviour:

Circuit should suspend once the failure threshold is crossed.
After a successful attempt against the failed URL, the failure count will be reset to 0 for that particular URL.
Once the cooldown time is over and the same request fails again, the failure count is again set to the threshold, and the circuit is suspended after one more failed attempt.

Contributing
We welcome contributions from the community! If you'd like to contribute to the Circuit Breaker for Node.js library, please follow our contribution guidelines.

License
This library is licensed under the ISC License.

Contact
If you have any questions, issues, or suggestions, please feel free to open an issue on GitHub or reach out to the maintainers directly.

Thank you for using the Circuit Breaker for Node.js library! We hope it helps you build more robust and resilient applications.