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

reef-service

v1.0.0-beta.7

Published

A nodejs service for the Reef arquitectural pattern

Downloads

13

Readme

node-reef-service

A nodejs service for the Reef arquitectural pattern

#How to Reef uses Amazon SQS queues, so you need an AWS account and the credentials to use it.

Set up

import { SqsBrokerFacade, ReefService } from 'reef-service';
import bunyan from 'bunyan';

let log = bunyan.createLogger({
  name        : 'foo',
  level       : process.env.LOG_LEVEL || 'info',
  stream      : process.stdout,
  serializers : bunyan.stdSerializers
});

let brokerFacade = new SqsBrokerFacade({
    region: process.env.AWS_REGION,
    accessKeyId: process.env.AWS_ACCESSKEYID,
    secretAccessKey: process.env.AWS_SECRETACCESSKEY,
    clientDomain: "serviceDomain",
    clientLane: "singleton"
});

let service = new ReefService(brokerFacade);

log.info('Setting up runners'); //The ones that listen for commands and fireAndForgets

service.addRunner("SAVE_USER", saveUser); //service.addRunner(commandToListen, function)

log.info('Setting up resolvers'); //The ones that listen for queries

service.addResolver("GET_USER_INFORMATION", userInformation);

log.info('Setting up Reef Service');
await service.setup();

log.info('Starting up Reef Service');
await service.start();

log.info('Adding info listener');
service.on('info', (info) => {
    log.info('Reef layer info: ', info);
});

log.info('Adding warn listener');
service.on('warn', (info) => {
    log.warn('Reef layer info: ', info);
});

log.info('Adding error listener');
service.on('error', (error) => {
    log.error('Reef layer info: ', error);
});

log.info('Listening');

Programming functions

There are two types of functions that reef accepts: runners and resolvers.

import mysql from 'mysql';
import databaseConnection from './databaseConnection'; //For more detail in how to implement a mysql connection visit mysql repository

async function saveUser(parameters){ //parameters is the payload that the client sends
  
 let query = `INSERT INTO subscriptor
            (user, name, lastName)
            VALUES (?, ?, ?)`;
    
  let inserts = [parameters.user, parameres.name, parameters.lastName];
  query = mysql.format(query, inserts);

  return new Promise( (resolve, reject) => {
        databaseConnection.query(query, (err, rows, fields) => {
            if (err){
                bunyanLog.info(err);
                resolve({
                  success: false,
                  error: err
                });
            }
            
            resolve({
              success: true
            });

        });
    });
}

The object that the client will receive is the one that is returned after the promise is resolved.

If a resolver/runner throws an error(reject), it will send a failuere message the the client, and the message will be deleted from the queue.

If a runner throws an error and the command type is a fireAndForget, the message will be requeued, and no response will be sent.

#How does it work

Each service has a request queue compose of the domain and lane. For example a queue full name will be:

serviceDomain-singleton-req

Each client has a response queue compose of the domain and lane. For example the queue name of the last example will be:

clientDomain-singleton-res

The service in the other side will send a message through that queue, and the cliente will process that.