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

hapi-message-manager

v2.0.6

Published

A hapi-rascal driver for message management with keys based on the structure 'dom.obj.act.det'

Downloads

12

Readme

Hapi amqp message manager

A hapi-rascal https://github.com/sitamet/hapi-rascal driver. A wrapper for event management with keys based on the structure 'dom.obj.act.det'

  • dom: domain where the event occurs or the command is targetted
  • obj: object the message carries.
  • act: action: [event|error|cmd command].
  • det: action detail.

This service driver exposes:

  • publish: a method used to publish events.
  • Routing: a class that helps us to manage a message.
  • subscribeThisProcessor: a method used to link an event message digest to a subscription.

IMPORTANT: this module is in design stage.

Dependencies

hapi-message-manager is a driver loaded by hapi-rascal https://github.com/sitamet/hapi-rascal (the amqp rascal plugin for hapijs).

Install

npm install hapi-rascal --save
npm install hapi-message-manager --save

Config

When starting your hapijs server, register this module after hapi-rascal:

{ register: require('hapi-rascal'), options: config.rascal },
...

where config.rascal config contains the driver options:

{
    'defaults': {...},
    'vhosts': {
        'test': {
            'connection': {...},
            'exchanges': {...},
            'publications': {
                'dom.obj.act.det': {...}
            },
            'queues': {...},
            'bindings': [...],
            'subscriptions': {...}
        }
    },
    'drivers': [{
        module: 'hapi-message-manager',
        name: 'events',
        options: {
            publication: 'dom.obj.act.det'
        }
    }]
}

Usage

This message-manager service gets exposed in drivers name under rascal plugin server.plugins.rascal.events

How to link a processMessage digest to a subscription:

To subscribe processMessage to our named subscription entity-product.tasks:

function processMessage(message, content, ackOrNack) {
    // message digest
}

server.plugins.rascal.events.subscribeThisProcessor(processMessage, 'entity-product.tasks');

How to publish a message:

server.plugins.rascal.events.publish({ 'foo': 'bar' }, 'test-domain.foo.cmd.update-foo');

// now you can await for its delivery:

try {
    await server.plugins.rascal.events.publish({ 'foo': 'bar' }, 'test-domain.foo.cmd.update-foo');
}
catch(err) {
    server.log('error', err);
}

How to deal with a message with the help of Routing:

let routing = server.plugins.rascal.events.Routing(message, content);

// routing provides getters to deal with all key segments based on structure 'dom.obj.act.det'
// i.e for a given key ´domain-one.object-type-a.cmd.do-something´ keyBare give us 'object-type-a.cmd.do-something'
switch (routing.keyBare()) {

    case 'object-type-a.cmd.do-something':
        // once exec the rounting delivers the 'object-type-a.event.do-something-done'
        // and if there is an err the 'object-type-a.error.do-something'
        doSomething(content.objectTypeA.id).exec(routing.reply.bind(routing));
        break;

    case 'object-type-b.cmd.update-b':

        // once updateB calls back, routing sets new content if no err
        // and reply emits a done with key object-type-b.event.update-b-done or
        // object-type-b.errir.update-b if the updateB fails
        updateB(content.objectTypeB, (err, objectTypeB) => {
            routing.setContent(err ? null : { objectTypeB }).reply(err);
        });
        break;
}

Running the tests

npm test