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

soul-king-streams

v1.0.4

Published

A streamlined Node.js microservice skeleton for efficient inter-service communication via Kafka and monitoring endpoint exposure with Express.js. Features include Kafka integration for messaging, an Express.js API for monitoring, modular structure for eas

Downloads

8

Readme

Soul King Streams

Description

Soul King Streams is a Node.js microservice skeleton designed to streamline inter-service communication through Kafka and provide monitoring capabilities via Express.js endpoints. This tool simplifies development, testing, and maintenance processes. The microservice includes two vital API endpoints: /metrics for monitoring metrics and /health for health status checks. It features well-structured classes for handling Kafka messages and an Express.js application setup for monitoring.

Installation

Ensure Node.js and npm are installed on your system. Install Soul King Streams with the following command:

npm i soul-king-streams

Usage

After installation, import the necessary components from Soul King Streams into your Node.js application. The package exports BaseEmitter, BaseListener, KafkaSingleton, and an Express.js application setup (app).

Importing Components

const { BaseEmitter, BaseListener, KafkaSingleton, app } = require('soul-king-streams');

Setting Up KafkaSingleton

Before using BaseEmitter and BaseListener, you must initialize KafkaSingleton with your client ID and Kafka broker addresses.

// Initialize the Kafka client
const clientId = 'my-app-client';
const brokers = ['broker1:9092', 'broker2:9092'];

KafkaSingleton.initialize(clientId, brokers);

// Later in your application, when you need to use Kafka
try {
  const kafka = KafkaSingleton.getInstance();
  // Use the kafka instance for producing or consuming messages
} catch (error) {
  console.error(error.message);
}

API Endpoints

  • /metrics: Access monitoring metrics.
  • /health: Check the health status of the service.

Kafka Emitter and Listener

Use BaseEmitter and BaseListener for handling Kafka messages, after setting up KafkaSingleton.

BaseEmitter Example:

// You need to initialize the KafkaSingleton first
const { BaseEmitter } = require('soul-king-streams');

// Assuming the Kafka brokers are defined somewhere
const kafkaBrokers = ['broker1:9092', 'broker2:9092'];
const topic = 'my-topic';

// Create an instance of BaseEmitter
const emitter = new BaseEmitter(topic, kafkaBrokers);

// Connect to Kafka
await emitter.connect();

// Emit a message
const message = { key: 'value' }; // Replace with your actual message
await emitter.emit(message);

// Disconnect after done
await emitter.disconnect();

BaseListener Example:

// You need to initialize the KafkaSingleton first
const { BaseListener } = require('soul-king-streams');

class MyKafkaListener extends BaseListener {
  async onMessage(data) {
    // Implement your message handling logic here
    console.log(`Received message on ${data.topic}:`, data.message.value.toString());
    // Add more processing logic as needed
  }
}

const myListener = new MyKafkaListener({
  groupId: 'my-group',
  topic: ['my-topic'. 'my-topic-2'],
  clientId: 'my-client-id',
  kafkaBrokers: ['broker1:9092', 'broker2:9092']
});

// Connect to the Kafka topic
myListener.connect()
  .then(() => console.log('Connected to Kafka topic.'))
  .catch(error => console.error('Failed to connect:', error));

// Remember to gracefully disconnect when your application is closing
process.on('SIGINT', async () => {
  await myListener.disconnect();
  console.log('Disconnected from Kafka.');
});

Express.js Application Setup

The app component configures Express.js for the monitoring endpoints.

const { app } = require('soul-king-streams');

const PORT = 3000

app.listen(PORT, () => {
	console.log(`Server running on ${ PORT }`);
})

Configuration

Configure Kafka brokers, topics, and Express.js settings according to your project's requirements.

Contributing

Contributions are welcome. Please open an issue for major changes and submit pull requests for contributions.

License

GNU Affero General Public License (AGPL)