Skip to content

Commit 8c6c707

Browse files
committed
Adds runtime exceptions for kafka client consumer topics.
1 parent 28ca9ba commit 8c6c707

3 files changed

Lines changed: 19 additions & 25 deletions

File tree

packages/microservices/client/client-kafka.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
ConsumerGroupJoinEvent
2525
} from '../external/kafka.interface';
2626
import { KafkaHeaders } from '../enums';
27+
import { InvalidKafkaClientTopicException } from '../errors/invalid-kafka-client-topic.exception';
28+
import { InvalidKafkaClientTopicPartitionException } from '../errors/invalid-kafka-client-topic-partition.exception';
2729

2830
let kafkaPackage: any = {};
2931

@@ -201,39 +203,17 @@ export class ClientKafka extends ClientProxy {
201203
}
202204

203205
private getReplyPartition(topic: string): string {
204-
// this.consumer.describeGroup().then((description) => {
205-
// // this.logger.error(util.format('getReplyTopicPartition(): groupDescription: %o', description));
206-
207-
// description.members.forEach((member) => {
208-
// const memberMetadata = kafkaPackage.AssignerProtocol.MemberMetadata.decode(member.memberMetadata);
209-
// const memberAssignment = kafkaPackage.AssignerProtocol.MemberAssignment.decode(member.memberAssignment);
210-
211-
// // this.logger.error(util.format('getReplyTopicPartition(): groupDescription.member[i]: %o', member));
212-
// this.logger.error(util.format('getReplyTopicPartition(): memberId: %s metadata: %o', member.memberId, {
213-
// topics: memberMetadata.topics,
214-
// userData: memberMetadata.userData.toString()
215-
// }));
216-
217-
// this.logger.error(util.format('getReplyTopicPartition(): memberId: %s assignment: %o', member.memberId, {
218-
// assignment: memberAssignment.assignment,
219-
// userData: memberAssignment.userData.toString()
220-
// }));
221-
// });
222-
// });
223-
224-
// return 0;
225-
226206
// get topic assignment
227207
const topicAssignments = this.consumerAssignments[topic];
228208

229209
// throw error
230210
if (isUndefined(topicAssignments)) {
231-
throw new Error(`Unable to send the message request because the client consumer is not subscribed to the topic (${topic}).`);
211+
throw new InvalidKafkaClientTopicException(topic);
232212
}
233213

234214
// if the current member isn't listening to any partitions on the topic then throw an error.
235215
if (isUndefined(topicAssignments[0])) {
236-
throw new Error(`Unable to send the message request because the client consumer subscribed to the topic (${topic}) is not assigned any partitions.`);
216+
throw new InvalidKafkaClientTopicPartitionException(topic);
237217
}
238218

239219
return topicAssignments[0].toString();
@@ -272,7 +252,7 @@ export class ClientKafka extends ClientProxy {
272252
this.routingMap.delete(packet.id);
273253
};
274254
} catch (err) {
275-
this.logger.error(err);
255+
callback({ err });
276256
}
277257
}
278258
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { RuntimeException } from '@nestjs/core/errors/exceptions/runtime.exception';
2+
3+
export class InvalidKafkaClientTopicPartitionException extends RuntimeException {
4+
constructor(topic?: string) {
5+
super(`The client consumer subscribed to the topic (${topic}) is not assigned any partitions.`);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { RuntimeException } from '@nestjs/core/errors/exceptions/runtime.exception';
2+
3+
export class InvalidKafkaClientTopicException extends RuntimeException {
4+
constructor(topic?: string) {
5+
super(`The client consumer is not subscribed to the topic (${topic}).`);
6+
}
7+
}

0 commit comments

Comments
 (0)