import { Inject , Post } from '@nestjs/common' ; import { Payload } from "@nestjs/microservices" ; import { SubscribeTo , KafkaService } from '../../../src' ; import { KafkaMessageSend } from '../../../src/interfaces' ; export const TOPIC_NAME = 'test.topic' ; export class TestConsumer { messages = [ ] ; constructor ( @ Inject ( 'KAFKA_SERVICE' ) private client ) { } onModuleInit ( ) { this . client . subscribeToResponseOf ( TOPIC_NAME , this ) ; } @ SubscribeTo ( TOPIC_NAME ) async message ( @ Payload ( ) data ) { this . messages . push ( data ) ; } @ Post ( ) async sendMessage ( event ) { const a = { ... event , topic : TOPIC_NAME } ; return await this . client . send ( a ) ; } }