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

seneca-web-helper

v1.0.1

Published

Two useful plugins for using seneca-web in a distributed manner.

Downloads

5

Readme

Seneca

Seneca-Web-Helper

npm version Build Status Coverage Status Dependency Status

Two useful plugins for using seneca-web in a distributed manner.

This uses the magic of redis-pubsub and fire/forget mechanisms to mount routes when services come online.

The goal here is to stop excessive routes from being mounted to the target host server, and to ensure resilisiancy when new hosts or clients come online.

This plugins acts as a proxy to seneca-web calls, and uses redis pubsub to ensure all hosts receive all routes only when they need to.

Seneca compatibility

Supports Seneca versions 1.x - 3.x

Important Notes

  • the seneca-redis-transport transport is currently broken. Use seneca-redis-transport-fork

  • the cache mechanism is based upon the tag of each client microservice - this must be set.

  • hostname defaults to the OS's hostname and is used to ensure targetted population of routes for each host under a given hostname - if this is the same for multiple hosts, you'll end up with a lot of noise.

  • if a microservice comes online with new routes and all hosts are already aware of it, the new routes will not be mounted. You'll need to call into role:web,clear:all to get all hosts to clear their cache and repopulate routes.

Install

To install, simply use npm. You'll need to install seneca, seneca-web, and seneca-redis-transport-fork if you haven't already.

npm i seneca seneca-web seneca-redis-transport-fork

Host

const os = require('os')
const Express = require('express')
const Seneca = require('seneca')
const SenecaWeb = require('seneca-web')
const SenecaWebAdapterExpress = require('seneca-web-adapter-express')
const {WebHost} = require('seneca-web-helper')
const SenecaRedisTransport = require('seneca-redis-transport-fork')

const app = Express()
const server = http.createServer(app)

Seneca({ tag: 'api-gateway' })

  .use(SenecaRedisTransport)

  .use(SenecaWeb, {
    adapter: SenecaWebAdapterExpress,
    options: {parseBody: false},
    context: new Express.Router(),
    routes: []
  }))

  .use(WebHost)

  // you need to provide some kind of point->point mechanism for web requests
  .client({type: 'tcp', pins: ['role:test,cmd:*']})

  .ready(function () {

      this.act('role:web,register:all', {to_hostname: os.hostname()}) // this is the magic

      app.use('/api', this.export('web/context')())

      server.listen(3000, () => this.log.info('api gateway listening!'))

  })

Client

const Seneca = require('seneca')
const SenecaWeb = require('seneca-web')
const {WebClient} = require('seneca-web-helper')
const SenecaRedisTransport = require('seneca-redis-transport-fork')

Seneca({tag: 'microservice-1'})

  .use(SenecaRedisTransport)

  .use(WebClient, {
    routes: [{
      pin: 'role:test,cmd:*',
      map: {test: true}
    }]
  })

  // you need to provide some kind of point->point mechanism for web requests
  .listen({type: 'tcp', pins: ['role:test,cmd:*']})
  .add('role:test,cmd:foo', (args, cb) => cb(null, {ok: true}))

  .ready(function () {
    this.act('role:web', {register: this.options().tag}) // this is the magic
    this.log.info('microservice ready!')
  })

Contributing

The Senecajs org encourages open participation. If you feel you can help in any way, be it with documentation, examples, extra testing, or new features please get in touch.

License

Copyright Tyler Waters and other contributors 2019, Licensed under MIT.