@MessagePattern maps to a Kafka topic name. Use @Ctx() to inject a KafkaContext which exposes getTopic(), getPartition(), and getMessage() containing the offset and headers. Publish messages with a key to determine partition assignment and include headers for cross-cutting concerns like correlation IDs.
Message key determines which partition receives the message — same key always goes to the same partition.
All messages with the same key are ordered within their partition — critical for event sourcing.
Without a key, Kafka round-robins across partitions — no ordering guarantee.
Offset identifies the message position within a partition — use it for manual offset commits.
Headers are available via ctx.getMessage().headers — use for correlation IDs and trace context propagation.
Suppose you need to consume a Kafka topic in a NestJS microservice and you must read a custom header called 'event-type' to route the payload. How would you access that header using KafkaContext?
If a message arrives on partition 3 and you want to log the partition number inside your NestJS consumer, what code would you write to retrieve the partition from KafkaContext?
What happens if you try to read a header that wasn't set on the incoming Kafka message? How would your NestJS handler behave?
You added a new header 'correlation-id' to all outbound events, but downstream services are sometimes not receiving it. Walk me through how you'd debug the issue using KafkaContext in your NestJS consumer.
When implementing a pattern that processes messages differently based on the partition they came from, what trade‑offs do you consider, and how would you structure your NestJS handler to access partition info efficiently?
Explain why using KafkaContext to read headers inside a @MessagePattern handler might cause issues when you have multiple consumer groups, and how you'd mitigate them.
At scale, you need to enforce ordering guarantees per key across partitions while also extracting headers for audit logging. How would you design your NestJS Kafka consumer architecture to reliably get partition and header info without impacting throughput?
If you need to route messages to different processing pipelines based on a combination of header values and partition number, what patterns would you use in NestJS, and how would you handle potential back‑pressure or hot partitions?
Discuss the performance implications of repeatedly calling KafkaContext.getMessage().headers in a high‑throughput NestJS service and how you would optimize it.
Your organization is migrating from a legacy Java Kafka consumer to a NestJS‑based platform. How would you ensure consistent handling of message headers and partition metadata across teams, and what abstraction or governance would you introduce?
When designing a cross‑service event schema that relies heavily on custom headers for routing, what architectural considerations would you raise about coupling NestJS consumers to header conventions, and how would you future‑proof the design?
If you need to support multiple versions of a message format where headers indicate version, how would you structure the NestJS layer to handle version negotiation while keeping partition handling robust across deployments?