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

eip

v1.8.1

Published

Enterprise Integration Patterns for javascript

Downloads

129

Readme

eip

Enterprise Integration Patterns for javascript.

This repo is based on jkanschik/node-eip implements various eip patterns for javascript and mainly enhances the aggregator functionality.

Installation

npm install --save eip

Usage

Create a Route

const eip = require('eip');
const route = new eip.Route('Route-0', {route: {retryLimit: 3, retryDelay: 1000}, isErrorRoute:false}, [])

Add a processor to the Route

route.process(event => event * 2).info()

Inject events to Route

route.inject(1);
// output: [2017-03-10 17:04:12.636] [INFO] [aggregator-eip] - [Route-0(info-1)] 2
route.inject(2);
// output:  [2017-03-10 17:04:13.082] [INFO] [aggregator-eip] - [Route-0(info-1)] 4

Builtin Processors

aggregate({ timeout = [1000], maxTimes = 3 }) // or
aggregate({ timer= new Timer(), store = new Store(), strategy = new AggregationStrategy() })
// Timer, Store and AggregationStrategy are abstract classes exported by eip that can be extended.
// see eip-mongo and eip-rabbit for implementations of Timer on top of rabbitmq and Store on top of mongo

dispatch(route1, route2)
filter(event => event > 5); // or
filter(event => doAsyncStuff(event).then(result => result > 5)) // filter can accept conditions tha return a promise
process(event => [event, event]) // custom processor that transforms the event
process(event => doAsyncStuff(event)) // transform event returning a promise
throttle(10, 1000) // 10 events per second (1000 ms)
throttleResource({
  eventsPerPeriod:1,
  periodInMs:1000
})

  //or
throttleResource({
  timer: new Timer(),
  resource: x => x,
  pubSub: new PubSub(),
  queue: new Queue()
})
// Timer, PubSub and Queue are abstract classes exported by eip that can be extended.
// see eip-redis and eip-rabbit for implementations of Timer on top of rabbitmq and pubSub and queue on top of redis

//logging
trace()
debug()
info()
warn()
error()
fatal()

// all logger scan transform the logging msg using a callback
// eg:
event => 'message to be logged:' + event;

Aggregator example

const aggregator = new eip.Route().aggregate({ timeout: [1000], maxTimes: 3 }).info();

aggregator.inject({
  headers: {
    id: 'the id to aggregate data',
    param: 'one'
  },
  body:'one'});

aggregator.inject({
  headers: {
    id: 'the id to aggregate data',
    param: 'two'
  },
  body:'two'});

aggregator.inject({
  headers: {
    id: 'the id to aggregate data',
    anotherParam: 'other'
  },
  body:'three'});


// it will be aggregated and log to output:
// [2017-03-10 16:32:07.605] [INFO] [aggregator-eip] - [Route-1(info-1)] {"body":["one","two","three"],"headers":{"status":"COMPLETED","id":"the id to aggregate data","param":"two","anotherParam":"other","aggregationNum":1,"timeoutNum":0,"previousStatus":"INITIAL"}}
// [2017-03-10 16:32:08.606] [DEBUG] [aggregator-eip] - [Route-1(aggregate-0)] [timeout-1] [1] Already completed


// we could have formatted the output using:
aggregator.info(aggregated => JSON.stringify(aggregated, null, 2));
/*
[2017-03-10 16:38:05.484] [INFO] [aggregator-eip] - [Route-1(info-2)] {
  "body": [
    "one",
    "two",
    "three"
  ],
  "headers": {
    "status": "COMPLETED",
    "id": "the id to aggregate data",
    "param": "two",
    "anotherParam": "other",
    "aggregationNum": 1,
    "timeoutNum": 0,
    "previousStatus": "INITIAL"
  }
}
[2017-03-10 16:38:06.152] [DEBUG] [aggregator-eip] - [Route-1(aggregate-0)] [timeout-1] [the id to aggregate data] Already completed
*/

License

MIT