Skip to content

Commit e6ea76b

Browse files
Update content/microservices/kafka.md
1 parent 12eec1f commit e6ea76b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

content/microservices/kafka.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,13 @@ Committing offsets is essential when working with Kafka. Per default, messages w
396396

397397
```typescript
398398
@@filename()
399-
400-
constructor(@Inject(KAFKA) client: ClientKafka) {}
401-
402-
@EventPattern('user_created')
403-
async handleUserCreated(@Payload() data: IncomingMessage) {
399+
@EventPattern('user.created')
400+
async handleUserCreated(@Payload() data: IncomingMessage, @Ctx() context: KafkaContext) {
404401
// business logic
405-
406-
await this.client.commitOffsets([ { topic: data.topic, partition: data.partition, offset: data.offset } ])
402+
403+
const originalMessage = context.getMessage();
404+
const { topic, partition, offset } = originalMessage;
405+
await this.client.commitOffsets([{ topic, partition, offset }])
407406
}
408407
@@switch
409408
@Bind(Payload(), Ctx())

0 commit comments

Comments
 (0)