Skip to content

Commit 1d95a2c

Browse files
authored
Fix the order of code examples
1 parent 6fd8d3d commit 1d95a2c

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

content/microservices/kafka.md

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -313,18 +313,16 @@ To access the original Kafka `IncomingMessage` object, use the `getMessage()` me
313313
```typescript
314314
@@filename()
315315
@MessagePattern('hero.kill.dragon')
316-
async killDragon(@Payload() message: KillDragonMessage, @Ctx() context: KafkaContext) {
316+
killDragon(@Payload() message: KillDragonMessage, @Ctx() context: KafkaContext) {
317317
const originalMessage = context.getMessage();
318-
const heartbeat = context.getHeartbeat();
319-
320-
// Do some slow processing:
321-
await doWorkPart1();
322-
323-
// Send heartbeat when it's possible in order to not exceed the sessionTimeout
324-
await heartbeat();
325-
326-
// Do some slow processing again:
327-
await doWorkPart2();
318+
const { headers, partition, timestamp } = originalMessage;
319+
}
320+
@@switch
321+
@Bind(Payload(), Ctx())
322+
@MessagePattern('hero.kill.dragon')
323+
killDragon(message, context) {
324+
const originalMessage = context.getMessage();
325+
const { headers, partition, timestamp } = originalMessage;
328326
}
329327
```
330328

@@ -349,21 +347,22 @@ If your endpoint involves slow processing time for each message you should consi
349347
```typescript
350348
@@filename()
351349
@MessagePattern('hero.kill.dragon')
352-
killDragon(@Payload() message: KillDragonMessage, @Ctx() context: KafkaContext) {
353-
const originalMessage = context.getMessage();
354-
const { headers, partition, timestamp } = originalMessage;
355-
}
356-
@@switch
357-
@Bind(Payload(), Ctx())
358-
@MessagePattern('hero.kill.dragon')
359-
killDragon(message, context) {
350+
async killDragon(@Payload() message: KillDragonMessage, @Ctx() context: KafkaContext) {
360351
const originalMessage = context.getMessage();
361-
const { headers, partition, timestamp } = originalMessage;
352+
const heartbeat = context.getHeartbeat();
353+
354+
// Do some slow processing:
355+
await doWorkPart1();
356+
357+
// Send heartbeat when it's possible in order to not exceed the sessionTimeout
358+
await heartbeat();
359+
360+
// Do some slow processing again:
361+
await doWorkPart2();
362362
}
363363
```
364364

365365

366-
367366
#### Naming conventions
368367

369368
The Kafka microservice components append a description of their respective role onto the `client.clientId` and `consumer.groupId` options to prevent collisions between Nest microservice client and server components. By default the `ClientKafka` components append `-client` and the `ServerKafka` components append `-server` to both of these options. Note how the provided values below are transformed in that way (as shown in the comments).

0 commit comments

Comments
 (0)