@deployagram/kafkajs
v1.0.0
Published
Reports the Kafka records a kafkajs consumer reads to the Deployagram Collector, as the Java Kafka consumer interceptor does. Wrap the consumer's eachMessage handler.
Readme
@deployagram/kafkajs
Reports the Kafka records a kafkajs consumer reads to the Deployagram Collector, as the Java Kafka consumer interceptor does. The Collector then reads each record from the broker and shows it on the diagram.
Usage
Wrap the eachMessage handler. Each message is reported before the handler runs.
import { DiagramLoggerClient } from '@deployagram/logger-client';
import { recordConsumedMessages } from '@deployagram/kafkajs';
const logger = new DiagramLoggerClient({ baseUrl: 'http://localhost:1152' });
await consumer.run({
eachMessage: recordConsumedMessages({ logger, consumingApp: 'DontForget' }, async ({ message }) => {
// handle the message
}),
});The Collector must also know the broker and, for Avro or JSON-schema records, the Schema Registry.
Set both with configureKafkaBroker and configureSchemaRegistry on the logger client. The Collector
must be in runtime configuration mode for those calls to succeed.
Behaviour
- A failure to report a read is warned about, and the message is still handled.
- An error thrown by the handler is thrown on, so kafkajs retries the message as it would without this package.
- The offset is sent as a number, as the Collector expects.
Testing
npm testThe tests use a logger that keeps reads in memory. They need no Collector or broker.
