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

@frmnt/hydra

v0.0.2

Published

Microservices framework for Node.js

Downloads

3

Readme

Hydra

Hydra is a framework for building networked microservices, supporting both remote procedure call (RPC) and publish-subscribe models of communication.

At a glance

As an example of a the most basic Hydra system, we'll make a single "hello" Service with a sayHello method, and call that method from a separate process using a Client.

A Service has a name and set of named methods:

var hydra = require('@frmnt/hydra');

var hello_service = new hydra.Service('hello', {
    sayHello: function (args, cb) {
        cb(null, 'Hello, ' + args.name + '!');
    }
});

To make requests to a Service you use a Client:

var hydra = require('@frmnt/hydra');

var hello_client = new hydra.Client();

hello_client.remote('hello', 'sayHello', 'world', function (err, response) {
    console.log('Got response: ' + response);
});

Installation

Hydra requires the Node.js ZeroMQ library, which requires ZeroMQ libraries - install those with your system package manager:

$ sudo apt-get install libzmq-dev

Install the Hydra library locally, and the Hydra Server globally:

$ npm install @frmnt/hydra
$ npm install -g @frmnt/hydra-server

Getting started

First make sure the Hydra Server is installed and running:

$ hydra-server
[Hydra Server] Bound to 127.0.0.1:8420

Creating a Service

Create a Service using new hydra.Service(args, methods). The methods argument is an object of named functions; every function is asynchronous and takes a callback as its second argument.

A Service can publish events using service.publish(type, data).

This example creates a Service named "hello" with a single method sayHello(args, cb), and emits an event called hi every 2 seconds:

var hydra = require('@frmnt/hydra');

var hello_service = new hydra.Service('hello', {
    sayHello: function (args, cb) {
        cb(null, 'Hello, ' + args.name + '!');
    }
});

setInterval(function() {
    hello_service.publish('hi', "Just saying hi.");
}, 2000);

Running a Service

When a Service is started it will bind to a random port and register itself with the Hydra Server:

Registered service `hello~9iuma73n` on tcp://127.0.0.1:15544

Creating a Client

Create a Client using new hydra.Client().

Call a remote method of a Service using client.remote(service, method, args, cb). The callback takes two argments, err and response.

Subscribe to events from a Service using client.subscribe(service, type, cb). This callback takes one argument, the incoming event.

This example connects to the "hello" service, calls the sayHello method, and subscribes to its events:

var hydra = require('@frmnt/hydra');

var hello_client = new hydra.Client();

hello_client.remote('hello', 'sayHello', 'world', function (err, response) {
    console.log('Got response: ' + response);
});

hello_client.subscribe('hello', 'hi', function (event) {
    console.log('Got event: ' + event);
});

Running a Client

Assuming the Hydra Server and "hello" service are running, running the client call the "hello" service's remote method sayHello and subscribe to its hi events:

Got response: Hello, world!
Got event: Just saying hi.
Got event: Just saying hi.
Got event: Just saying hi.
^C