I try to send message into right partition here is my NESTJS Producer Controller
constructor(
private readonly appService: AppService,
@Inject('any_name_i_want') private readonly client: ClientKafka,
) {}
async onModuleInit() {
['test2'].forEach((key) => this.client.subscribeToResponseOf(`${key}`));
await this.client.connect();
}
@Get('kafka-test-with-response')
async testKafkaWithResponse() {
const res = await this.client.send('test2', {
foo: 'bar',
data: new Date().toString(),
partition: 1,
});
return res;
}
I try to read in NestJs Document but it's provide link into Kafka website and I've found this in Kafka document
const producer = kafka.producer()
await producer.connect()
await producer.send({
topic: 'topic-name',
messages: [
{ key: 'key1', value: 'hello world', partition: 0 },
{ key: 'key2', value: 'hey hey!', partition: 1 }
],
})
After I've check in UI Kafka enter image description here
It seems like Producer still send random partition
I try to deep down check in typescript send() function but it use any so I'm really not sure how to specify partition in send function