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

message-hub-rest

v2.0.0

Published

Node.js module for connecting to the Kafka REST interface of IBM Message Hub.

Downloads

1,368

Readme

IBM Message Hub REST API Client Module

IBM Message Hub is a scalable, distributed, high throughput message bus to unite your on-premise and off-premise cloud technologies. You can wire micro-services together using open protocols, connect stream data to analytics to realise powerful insight and feed event data to multiple applications to react in real time.

This Node.js module provides a high-level API by which you can interact with the REST API exposed by the Message Hub service.

Note:

From version 2.0.0 onwards, the consume and produce APIs have been removed as the Message Hub Enterprise offering does not support them. Customers should instead use node-rdkafka for Kafka API-level messaging.

Getting Started

Prerequisites

You will need a Node.js 0.12.x runtime environment to use this module. This can be installed from http://nodejs.org/download/, or by using your operating system's package manager.

Installation Instructions

Installing using npm:

npm install message-hub-rest

Run Tests

  • To run against a mock Kafka service, use npm test
  • Important Note: Running tests against a live service (with the '--real' flag) is will incur a fee and as such is not recommended.

Example Usage:

The following example sets up a connection to the Message Hub REST API, creates a topic, consumer and producer, then produces and consumes a few messages before exiting.

var MessageHub = require('message-hub-rest');
var services = process.env.VCAP_SERVICES;
var instance = new MessageHub(services);
var topicName = 'mytopic';

instance.topics.create(topicName)
  .then(function(response) {
      console.log('Topic created.');
  })
  .fail(function(error) {
    throw new Error(error);
  });

API

MessageHub(services, [opts])

Constructs a new Client object, provided with Bluemix VCAP_SERVICES and additional options used to help connect to a particular service.

  • services - (Object) VCAP_SERVICES of your Bluemix Message Hub service.
  • opts - (Object) Optional configuration options used when connecting to the service. Properties include:
    • https, (Boolean) (optional), make HTTPS requests to the service. Defaults to true, should only be set to false when testing against a mock Kafka service.

Instantiate with the new keyword. When instantiated correctly, a new MessageHub/Client object will be returned. Throws an error with an accompanying message if the provided services information is incorrect.

MessageHub.prototype.topics.get()

Retrieves a list of all topics connected to the provided API key.

Returns a Promise object which will be fulfilled when the request to the service resolves.

MessageHub.prototype.topics.create(topic, partitions, retentionHours)

Creates a topic of the specified name. Important Note: Creating topics incurs a fee - check the Bluemix documentation for more information.

  • topic - (String) (required), the topic name for the service to create.
  • partitions - (Number) (optional), the number of partitions to use for this topic. Defaults to 1.
  • retentionHours - (Number) (optional), the number of hours to retain messages on this topic. Minimum is 24 hours, if retentionHours is less than this, it will be set to the minimum.

Returns a Promise object which will be fulfilled when the request to the service resolves.

MessageHub.prototype.topics.delete(topic)

Deletes a topic of the specified name.

  • topic - (String) (required), the topic name to delete from the service.

Returns a Promise object which will be fulfilled when the request to the service resolves.