Skip to content

Commit

Permalink
Merge pull request #10549 from Papooch/fix/microservices-client-falsy…
Browse files Browse the repository at this point in the history
…-options

fix(microservices): allow falsy values in options
  • Loading branch information
kamilmysliwiec committed Apr 5, 2023
2 parents 5aab28f + e45e04a commit 5a2be89
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
24 changes: 16 additions & 8 deletions packages/microservices/client/client-kafka.ts
Expand Up @@ -60,14 +60,22 @@ export class ClientKafka extends ClientProxy {
constructor(protected readonly options: KafkaOptions['options']) {
super();

const clientOptions =
this.getOptionsProp(this.options, 'client') || ({} as KafkaConfig);
const consumerOptions =
this.getOptionsProp(this.options, 'consumer') || ({} as ConsumerConfig);
const postfixId =
this.getOptionsProp(this.options, 'postfixId') ?? '-client';
this.producerOnlyMode =
this.getOptionsProp(this.options, 'producerOnlyMode') || false;
const clientOptions = this.getOptionsProp(
this.options,
'client',
{} as KafkaConfig,
);
const consumerOptions = this.getOptionsProp(
this.options,
'consumer',
{} as ConsumerConfig,
);
const postfixId = this.getOptionsProp(this.options, 'postfixId', '-client');
this.producerOnlyMode = this.getOptionsProp(
this.options,
'producerOnlyMode',
false,
);

this.brokers = clientOptions.brokers || [KAFKA_DEFAULT_BROKER];

Expand Down
2 changes: 1 addition & 1 deletion packages/microservices/client/client-proxy.ts
Expand Up @@ -130,7 +130,7 @@ export abstract class ClientProxy {
T extends ClientOptions['options'],
K extends keyof T,
>(obj: T, prop: K, defaultValue: T[K] = undefined) {
return (obj && obj[prop]) || defaultValue;
return obj && prop in obj ? obj[prop] : defaultValue;
}

protected normalizePattern(pattern: MsPattern): string {
Expand Down

0 comments on commit 5a2be89

Please sign in to comment.