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 🙏

© 2026 – Pkg Stats / Ryan Hefner

microwork-rpc-handler

v1.0.2

Published

A little handler that allow to send RPC with microwork package

Downloads

8

Readme

microwork-rpc-handler

A little handler that allow to send RPC with microwork package

Install : npm install microwork-rpc-handler -S

Current : v 1.0.1 - see CHANGELOG

API

  • handleRPCReply(data, msg, response, reply, provider) - Allow to reply to a given request.
  • async handleRPCRequest(topic, data, service) - Send the request
  • prepareRPCRequest(data, resolve, reject, [timeout]) - Should be used before a RPCRequest. Allow to prepare the reception of the RPCCalls, and handle resolving of the promise. If provided, a timeout can be executed which will remove the event listener
  • async subscribeToRPCEvents(service) - Should be executed before everything : Allow to enable the reception and dispatching of future RPC Calls

Usage exemple

We will assume in this exemple that we use microwork and winston.

I can only suggest you to see the working example is the example folder

Consumer.js

const Microwork = require('microwork');
const winston = require('winston');
const provider = new Microwork({host:'/', exchange:'myExchange', loggingTransports:[new winston.transports.Console({level: 'error'})]});
const RPCHandler = require('microwork-rpc-handler');

function consumeSomething(query){
    return new Promise(async function (resolve, reject) {
        let data = {
                type:'askForSomething',
                query:query
        };
        //Generate a unique rpcId, and prepare himself to receive an event (using emitter.once)
        //will also sanitize the data.
        //When it will receive a response from the provider service, it will resolve the promise using receided data
        data = RPCHandler.prepareRPCRequest(data, resolve, reject);
        //Send to the desired topic, the data using the service.id as a correlationId.
        await RPCHandler.handleRPCRequest('myService.myTopic', data, provider);
    });
};
const startConsumer = async() => {
    //Subscribe to event on the topic being the service id.
    //When it will received something, it will check if the data received has a _rpcId, and a data field.
    //If so, it will emit an event with theses information.
    //Note : If no data field in the received message, it will then emit with all msg (_rpcId excluded )
    await RPCHandler.subscribeToRPCEvents(provider);
    console.log('Consumer started..');
};
startConsumer();

provider.js

const Microwork = require('microwork');
const winston = require('winston');
const provider = new Microwork({host:'/', exchange:'myExchange', loggingTransports:[new winston.transports.Console({level: 'error'})]});
const RPCHandler = require('microwork-rpc-handler');

const getResultFromQuery=function(query){
    return 42;
}
const handleMyTopic = async function (msg, reply, ack, nack, data) {
    if(msg){
        if(msg.hasOwnProperty('type')){
            let type = msg.type;
            if(type=='askForSomething' && msg.hasOwnProperty('query')){
                let query = msg.query;
                let result = getResultFromQuery(query);
                let response = {
                    data:{
                        result:result
                    }
                };
                //Will reply to the consumer the data : 42.
                RPCHandler.handleRPCReply(data, msg, response, reply, provider);
            };
        }
    }
}
const startProvider = async() => {
    console.log('Started providing stuff');
    await RPCHandler.subscribeToRPCEvents(provider);
    await provider.subscribe('myService.myTopic', handleMyTopic);
};
startProvider()

Contributions

Every idea, issue, PR, contributions or anything else is welcomed :)

LICENSE

MIT