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..acecd72 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, ...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; }