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

@opuscapita/kafka-client

v2.0.1

Published

OpusCapita kafka client library.

Downloads

192

Readme

DEPRECATED

You should probably NOT be using this library for the following purposes:

  • not much value is added over kafkajs
  • many interfaces of native kafkajs are hidden
  • assumption of autocommit
    • every message processed with a separate call (no batch processing)
    • autocommit could lead to data loss
  • not used in OpusCapita

However you might find it usable as there is a lot of logic implemented and it is using TypeScript. In such a case feel free to unarchive it or fork.

This module implements a high-level Kafka consumer/producer. It is based on kafkajs and adds some convenience functions on top of the provided functionallity:

  • Supports dead letter queing by implementing a simplified, one-stage DLQ without retry.
  • Enveloping: Every message is enriched by platform specific information (context) that is transparent to the application using kafka-client
  • Disables usage of wildcard topics
  • On-demand subscribe and unsubscribe
  • (tba) Metrics: Implement metrics for active health monitoring of client connections

Please find more information on the individual topics in the wiki.

Minimum setup

First got to your local code directory and run:

npm install @opuscapita/kafka-client

Kafka-client uses consul for service discovery meaning you need to have access to a running Consul server to get your endpoint configuration for the broker. In addition, the Kafka broker itself is required which also has to be registered inside Consul.

The basic implementation requirements defines the naming conventions used for topics as follows: serviceName.domainName.eventType.eventDetail.

Common subscription

If all this is set up, a new client connection can be created like this:

const KafkaClient = require('@opuscapita/kafka-client');
const kafka = new KafkaClient();
await kafka.init();

Consuming and producing works analogous to the well-known rabbitMq-based event-client library. Attention: Wildcard subscriptions are no longer supported.

(async () =>
{
    // Subscribe to a channel by name.
    await events.subscribe('my-service.my-channel', (m ) => { console.log(m); return true; });
    await events.emit('my-service.my-channel', 'Hello, world!');

    // unsubscribe from a particular key
    await events.unsubscribe('my-service.my-channel');

    // gracefully shutdown
    await events.dispose();
})();

If the application callback provided as the second parameter provided to the subscribe() method, the message handling will be considered errornous and the message will be put the DLQ.

Fetching single message

tbi

Default configuration

The default configuration object provides hints about what the module's standard behavior is like.

{
    serializer: JSON.stringify,
    parser: JSON.parse,
    serializerContentType: 'application/json',
    parserContentType: 'application/json',
    consumerGroupId: null,
    enableHealthChecks: true,
    logger: new Logger(),
    consul: {
        host: 'consul',
        mqServiceName: 'kafka'
    },
    consulOverride: {
        host: null
    },
    context: {
    }
}