From 33cec5967c285d0ccb776316674e7de6567eec5d Mon Sep 17 00:00:00 2001 From: Stepan Ryabukhin Date: Thu, 19 Oct 2023 17:01:23 +0500 Subject: [PATCH] feat(cluster): extend initial config --- README.md | 1 + src/config/kafkaClusterConfigDto.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9449d30..695e147 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ export class ConfigModule { password: process.env.KAFKA_PASSWORD, ssl: process.env.KAFKA_SSL, ca: process.env.KAFKA_CA, + connectionTimeout: process.env.KAFKA_CONNECTION_TIMEOUT, // default is 1 s. }, consumer: { groupId: process.env.KAFKA_CONSUMER_GROUP_ID as string, diff --git a/src/config/kafkaClusterConfigDto.ts b/src/config/kafkaClusterConfigDto.ts index 9b6a334..00cfa62 100644 --- a/src/config/kafkaClusterConfigDto.ts +++ b/src/config/kafkaClusterConfigDto.ts @@ -14,13 +14,17 @@ * limitations under the License. */ -import { TransformToBoolean } from "@byndyusoft/class-validator-extended"; +import { + TransformToBoolean, + TransformToNumber, +} from "@byndyusoft/class-validator-extended"; import { Transform } from "class-transformer"; import { ArrayMinSize, IsArray, IsBoolean, IsIn, + IsInt, IsOptional, IsString, } from "class-validator"; @@ -46,6 +50,7 @@ export class KafkaClusterConfigDto { return { brokers, + connectionTimeout: config.connectionTimeout ?? 1000, ...this.getKafkaSslConfig(transformedConfig), ...this.getKafkaSaslConfig(transformedConfig), }; @@ -122,4 +127,9 @@ export class KafkaClusterConfigDto { ) @IsOptional() public readonly ca?: string | Buffer; + + @IsInt() + @IsOptional() + @TransformToNumber() + public readonly connectionTimeout?: number; }