Socket
Book a DemoInstallSign in
Socket

@imec/digital-twin-kafka-utils

Package Overview
Dependencies
Maintainers
4
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@imec/digital-twin-kafka-utils

## Description Styleguide used for the Digital Twin project. It's meant to be available publicly from NPM.

npmnpm
Version
0.1.2
Version published
Weekly downloads
13
1200%
Maintainers
4
Weekly downloads
 
Created
Source

Kafka Connection Manager

Description

Styleguide used for the Digital Twin project. It's meant to be available publicly from NPM.

How to use it

You need to make sure to initialize the KafkaConnectionManager instance before using the producer or consumer.

Example to create and initialize an instance

import createKafkaManager from 'digital-twin-kafka-utils'

const kafka = await createKafkaManager({
  ip: 'localhost',
  port: '9092',
  clientId: 'digital-twin',
  consumerGroupId: 'my-group'
});

Example on how to publish a message

Send a single or multiple messages on a topic. The payload is mapped to the value of the kafka message. It's used as an array so we can send a batch if needed.

await kafka.publish({
    topic: 'my-topic',
    type: 'Road Closing',
    headers: {},
    payload: [`{}`],
    compression: CompressionTypes.GZIP,
  })

Example on how to subscribe to a topic

/!\ If using eachMessage, the eachBatch won't be called as it's the way kafkaJS has done the implementation.

// By each message
await kafka.subscribe({
    topic: 'my-topic',
    eachMessage: (messagePayload) => {
      console.log("messagePayload", messagePayload);
    },
})
// By batch
await kafka.subscribe({
    topic: 'my-topic',
    eachBatch: (batchPayload) => {
      console.log("batchPayload", batchPayload);
    },
})

FAQs

Package last updated on 10 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts