@xorde-labs/nestjs-kafka-module
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

Package @xorde-labs/nestjs-kafka-module

Release & Publish Tests TypeScript

Kafka Module for NestJs with extended features

Subscribing to Kafka topics

Topic names

Topic name is an alphanumeric string (0..9, A..Z, a..z), with allows symbols: - (hyphen), _ (underscore), . (dot)

This module also allows subscribers to use special topic name * that will receive messages from all implicitly (by providing topic exact topic name) subscribed topics.

Topic naming convention

https://devshawn.com/blog/apache-kafka-topic-naming-conventions/

Decorator

Example:

import { KafkaMessage } from 'kafkajs';
import { KafkaTopicSubscriber } from './kafka.decorator';

@Injectable()
export class ExampleService {
	constructor() {
	}

	@KafkaTopicSubscriber('topic-name')
	messageHandler(message: KafkaMessage) {
		console.log(message);
	}
}

You can only use run-time constants as topic names. If you want to provide topic names dynamically (eg. using config parameters), then you need to use runtime event emitter method as described below.

Runtime event emitter

Example:

import { KafkaMessage } from 'kafkajs';
import { KafkaService } from './kafka.service';

@Injectable()
export class ExampleService {
	constructor(
		private kafka: KafkaService,
	) {
	}

	async onModuleInit() {
		this.kafka.on('topic-name', this.messageHandler);
	}

	messageHandler(message: KafkaMessage) {
		console.log(message);
	}
}

Dependents (0)

Package Sidebar

Install

npm i @xorde-labs/nestjs-kafka-module

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

70.7 kB

Total Files

32

Last publish

Collaborators

  • amochkin
  • xtovski