mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 15:08:37 +00:00
52 lines
905 B
TypeScript
52 lines
905 B
TypeScript
import { Consumer, KafkaMessage } from '../external/kafka.interface';
|
|
import { BaseRpcContext } from './base-rpc.context';
|
|
|
|
type KafkaContextArgs = [
|
|
message: KafkaMessage,
|
|
partition: number,
|
|
topic: string,
|
|
consumer: Consumer,
|
|
heartbeat: () => Promise<void>,
|
|
];
|
|
|
|
export class KafkaContext extends BaseRpcContext<KafkaContextArgs> {
|
|
constructor(args: KafkaContextArgs) {
|
|
super(args);
|
|
}
|
|
|
|
/**
|
|
* Returns the reference to the original message.
|
|
*/
|
|
getMessage() {
|
|
return this.args[0];
|
|
}
|
|
|
|
/**
|
|
* Returns the partition.
|
|
*/
|
|
getPartition() {
|
|
return this.args[1];
|
|
}
|
|
|
|
/**
|
|
* Returns the name of the topic.
|
|
*/
|
|
getTopic() {
|
|
return this.args[2];
|
|
}
|
|
|
|
/**
|
|
* Returns the Kafka consumer reference.
|
|
*/
|
|
getConsumer() {
|
|
return this.args[3];
|
|
}
|
|
|
|
/**
|
|
* Returns the Kafka heartbeat callback.
|
|
*/
|
|
getHeartbeat() {
|
|
return this.args[4];
|
|
}
|
|
}
|