nestjs-kafka
nestjs-kafka copied to clipboard
Solution to Invalid Topic Name on Producer
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch @rob3000/[email protected]
for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/@rob3000/nestjs-kafka/dist/kafka.service.js b/node_modules/@rob3000/nestjs-kafka/dist/kafka.service.js
index 9bd0b5b..0a13615 100644
--- a/node_modules/@rob3000/nestjs-kafka/dist/kafka.service.js
+++ b/node_modules/@rob3000/nestjs-kafka/dist/kafka.service.js
@@ -97,8 +97,8 @@ let KafkaService = KafkaService_1 = class KafkaService {
this.logger.error('There is no producer, unable to send message.');
return;
}
- const serializedPacket = await this.serializer.serialize(message);
- return await this.producer.send(serializedPacket);
+ await Promise.all(message.messages.map(x => x.value = JSON.stringify(x.value)))
+ return await this.producer.send(message);
}
getGroupIdSuffix(groupId) {
return groupId + '-client';
This issue body was partially generated by patch-package.
Hi @samithbharadwaj thanks for the diff. What config are you using? And are you using JSON for your messages in Kafka?
Hi @rob3000
Are you referring to the Kafka Config? If yes, please find it below
{
name: 'HERO_SERVICE',
options: {
client: {
clientId: 'hero',
brokers: ['localhost:9092'],
},
consumer: {
groupId: 'hero-consumer',
},
producer: {
allowAutoTopicCreation: true,
},
},
},
Yes, I'm using JSON for my serialization and deserialization. I'm using Kafka for interservice communication between microservices.
PS: I'm sure there's a prettier/better way to do the serialization. This method would not hold up for circular JSON structures. But I'm just using this as a temporary fix. Will need to write a custom serializer very soon.
So most likely it looks like there could be an issue in the https://github.com/rob3000/nestjs-kafka/blob/master/src/serializer/kafka-request.serializer.ts