@Payload() extracts the message data and can accept a ValidationPipe for automatic validation. @Ctx() injects the transport-specific context object — RmqContext for RabbitMQ, KafkaContext for Kafka, TcpContext for TCP. Context objects expose transport metadata like channel references, partition numbers, and message offsets.
TcpContext — getPattern() returns the message pattern object.
RmqContext — getChannelRef() returns the AMQP channel; getMessage() returns the raw message for ack/nack.
KafkaContext — getTopic(), getPartition(), getMessage() with offset and headers.
NatsContext — getHeaders() returns NATS message headers.
@Payload(new ValidationPipe()) validates message data the same way @Body(new ValidationPipe()) validates HTTP bodies.
You need to create a NestJS microservice handler that receives a JSON payload. How would you use the @Payload() decorator to extract the data, and what would happen if you omitted it?
In a simple TCP microservice, you want to log the client’s IP address from the transport context. Show how you would use @Ctx() in the handler to get that information.
We have a message pattern that sometimes includes metadata in the transport context and sometimes doesn't. How would you safely access optional fields using @Ctx() without causing runtime errors?
During integration testing, a handler that uses @Payload() started receiving undefined values after a refactor. Walk me through how you would debug the issue and verify the decorator is applied correctly.
Our system uses RabbitMQ and gRPC transports side by side, and we need a unified way to extract correlation IDs for tracing. How would you design a utility that leverages @Ctx() to handle both transports efficiently?
When scaling the microservice, we observed that heavy payloads cause increased memory usage. Discuss trade‑offs of using @Payload() versus manually parsing the raw message inside the handler.
We are migrating a legacy monolith to a NestJS microservice architecture and need to preserve existing request context (auth tokens, request IDs) across multiple transports. How would you architect the use of @Ctx() and possibly custom decorators to ensure consistent context propagation across teams?
Consider a cross‑team initiative to implement end‑to‑end tracing across all NestJS microservices. What are the implications of relying on @Ctx() for transport‑specific data, and how would you standardize context handling to avoid duplication and maintainability issues?