From 88106da25ab9f72230fd2010c2c63cdeb33147ad Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Wed, 6 Nov 2024 09:33:00 -0500 Subject: [PATCH] Suppress warnings about default partitioner Suppress the following producer warnings: `KafkaJS v2.0.0 switched default partitioner. To retain the same partitioning behavior as in previous versions, create the producer with the option "createPartitioner: Partitioners.LegacyPartitioner". See the migration guide at https://kafka.js.org/docs/migration-guide-v2.0.0#producer-new-default-partitioner for details. Silence this warning by setting the environment variable "KAFKAJS_NO_PARTITIONER_WARNING=1"` --- index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.ts b/index.ts index ad93960..c858bb8 100644 --- a/index.ts +++ b/index.ts @@ -4,10 +4,12 @@ import { CompressionCodecs, CompressionTypes, Kafka as BaseKafka, + Partitioners, } from 'kafkajs' import type { KafkaConfig as BaseKafkaConfig, ConsumerConfig as BaseConsumerConfig, + ProducerConfig, } from 'kafkajs' import { Issuer } from 'openid-client' import { randomUUID } from 'crypto' @@ -69,6 +71,14 @@ class Kafka extends BaseKafka { groupId ??= randomUUID() return super.consumer({ groupId, ...config }) } + + producer({ createPartitioner, ...config }: ProducerConfig = {}) { + // Suppress default partitioner warning. + // FIXME: remove once KafkaJS has removed the warning. + // See https://kafka.js.org/docs/migration-guide-v2.0.0#producer-new-default-partitioner + createPartitioner ??= Partitioners.DefaultPartitioner + return super.producer({ createPartitioner, ...config }) + } } export * from 'kafkajs'