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 🙏

© 2025 – Pkg Stats / Ryan Hefner

hapi-kafka

v0.0.4

Published

hapijs-plugin for consuming and producing to a kafka queue

Readme

Hapi-Kafka

Launch Kafka Queue

docker run -p 2181:2181 -p 9092:9092 --env ADVERTISED_HOST=localhost --env ADVERTISED_PORT=9092 --env KAFKA_CREATE_TOPICS=test:1:1 vicentehidalgo/kafka:0.0.1 (Important!) Logs are stored at: /tmp/kafka-logs

Reference:

  • https://github.com/Superbalist/docker-kafka
  • https://github.com/Spotify/docker-kafka

Parameters ADVERTISED_HOST: the external ip for the container, e.g. docker-machine ip \docker-machine active ADVERTISED_PORT: the external port for Kafka, e.g. 9092 KAFKA_CREATE_TOPICS : topic:n_partitions:repl_factor ZK_CHROOT: the zookeeper chroot that's used by Kafka (without / prefix), e.g. "kafka" LOG_RETENTION_HOURS: the minimum age of a log file in hours to be eligible for deletion (default is 168, for 1 week) LOG_RETENTION_BYTES: configure the size at which segments are pruned from the log, (default is 1073741824, for 1GB) NUM_PARTITIONS: configure the default number of log partitions per topic

This is a plugin to share a common kafka connection across the whole Hapi server.

This version is intended for use with hapi v11.x.x

Registering the plugin

Options:

  • zkHost : Producer Consumer The Zookeeper host.
  • host: Consumer the host to send the messages to.
  • topics: Consumer list of topics to be consumed
  • groupId: Consumer the cosumer group ID.
  • id: Consumer the consumer ID.
  • encoding: Consumer Encoding to use.

Using the plugin

Two objects are exposed by this plugin :

  • client : a kafka client connection object that is connected to the kafka instance
  • library: the kafka module used by this module
  • name: the kafka module used by this module

Example

var Hapi = require('hapi');
var config = require('./config/environment');

// Create a server with a host and port
var server;


var setOptions = function () {
  var opts = {};
  opts.routes = {prefix: config.routes.prefix};
  return opts;
};


var init = function () {
  return new Promise((resolve, reject) => {
    // Create a server with a host and port
    server = new Hapi.Server();
    server.connection({port: config.port, routes: {cors: true}});

    // Register the server and start the application
    server.register(
      [
        {register: require('./routes')},
        {register: require('hapi-mongodb'), options: config.mongoSettings},
        {register: require('hapi-kafka'),
          options: {
            host: 'http://' + config.ip + ':' + config.port + config.routes.prefix + '/msg',
            zkHost: 'localhost:2181/' ,
            topics: [{topic: 'topic1'}],
            groupId: 'kafka-node-group',
            id: 'my-consumer-id-1',
            encoding: 'utf8'
          }
        },
        {register: require('inert')},
        {register: require('vision')}
      ],
      setOptions(),
      function (err) {
        if (err) {
          return reject(err);
        }
        server.start(function (err) {
          if (err) {
            return reject(err);
          }
          GlobalModule.setConfigValue('producer', server.plugins['hapi-kafka'].producer);
          return resolve(server);
        });
      }
    );
  });
};

exports.init = init;
exports.stopServer = stopServer;