beanify
TypeScript icon, indicating that this package has built-in type declarations

3.0.34 • Public • Published
Beanify

Beanify

A Node.js microservices toolkit for the NATS messaging system

Beanify's inspiration came from working with Hemera. After 3 versions of iteration, it has become a low-cost, high load capacity microservice framework. With beanify, you can start any number of services on different hosts to ensure maximum availability.

Requirements

Node.js v10 LTS (10.16.0) or later.

Features

  • Lightweight: The Beanify is small as possible and provide an extensive plugin system.
  • Location transparency: A service may be instantiated in different locations at different times. An application interacting with an service and does not know the service physical location.
  • Service Discovery: You don't need a service discovery all subscriptions are managed by NATS.
  • Load Balancing: Requests are load balanced (random) by NATS mechanism of "queue groups".
  • High performant: NATS is able to handle million of requests per second.
  • Scalability: Filtering on the subject name enables services to divide work (perhaps with locality).
  • Fault tolerance: Auto-heals when new services are added. Configure cluster mode to be more reliable.
  • Extendible: Beanify is fully extensible via its hooks, plugins and decorators.
  • Developer friendly: the framework is built to be very expressive and help the developer in their daily use, without sacrificing performance and security.
  • Request & Reply: By default point-to-point involves the fastest or first to respond.
  • Publish & Subscribe: Beanify supports all features of NATS. This includes wildcards in subjects and normal publish and queue mechanism.

Environment

  • BEANIFY_NATS_URL: will be mapped to the nats.url
  • BEANIFY_NATS_SERVERS: will be mapped to the nats.servers
  • BEANIFY_NATS_USER: will be mapped to the nats.user
  • BEANIFY_NATS_PASS: will be mapped to the nats.pass
  • BEANIFY_NATS_TOKEN: will be mapped to the nats.token
  • BEANIFY_PINO_LEVEL: will be mapped to the pino.level
  • BEANIFY_PINO_PRETTY: will be mapped to the pino.printPretty
  • BEANIFY_ROUTER_PREFIX: will be mapped to the router.prefix

Install

If installing in an existing project, then Beanify can be installed into the project as a dependency:

Install with npm:

npm i beanify --save

Install with yarn:

yarn add beanify

Example

const beanify = require('beanify')({
  // nats:{}
  // pino:{}
  // errio:{}
  // router:{}
})

beanify
  .route({
    url: 'math.add',
    handler (req, rep) {
      const { a, b } = req.body
      rep.send(a + b)
    }
  })
  .route({
    url: 'math.sub',
    handler (req, rep) {
      const { a, b } = req.body
      rep.send(a - b)
    }
  })
  .ready(() => {
    beanify.inject({
      url: 'math.add',
      body: {
        a: 1,
        b: 2
      },
      handler (e, sum) {
        console.log(e, sum)
      }
    })
  })

with async-await:

const beanify = require('beanify')({
  // nats:{}
  // pino:{}
  // errio:{}
  // router:{}
})

beanify
  .route({
    url: 'math.add',
    async handler (req) {
      const { a, b } = req.body
      return a + b
    }
  })
  .route({
    url: 'math.sub',
    async handler (req) {
      const { a, b } = req.body
      return a - b
    }
  })
  .ready(async () => {
    const sum = await beanify.inject({
      url: 'math.add',
      body: {
        a: 1,
        b: 2
      }
    })
    console.log({ sum })
  })

Documentation

Ecosystem

Readme

Keywords

none

Package Sidebar

Install

npm i beanify

Weekly Downloads

4

Version

3.0.34

License

MIT

Unpacked Size

108 kB

Total Files

53

Last publish

Collaborators

  • beanjs