# KafkaParserConfig

**Kind:** Interface

**Source:** [`packages/microservices/interfaces/microservice-configuration.interface.ts`](https://github.com/nestjs/nest/blob/master/packages/microservices/interfaces/microservice-configuration.interface.ts#L326)

**Part of:** [Microservices](subsystem-packages-microservices)

`KafkaParserConfig` defines parser behavior for Kafka message payloads within the microservices configuration layer. Its `keepBinary` flag controls whether incoming Kafka values remain in their binary form instead of being converted during parsing.

## Properties

| Property | Type |
|---|---|
| `keepBinary` | `boolean` |

## Diagram

```mermaid
graph LR
  A[Kafka Consumer] --> B[Kafka Message Value]
  B --> C[KafkaParserConfig]
  C -->|keepBinary: true| D[Preserve Binary Payload]
  C -->|keepBinary: false| E[Parse/Convert Payload]
  D --> F[Microservice Handler]
  E --> F
```

## Usage

```ts
import type { KafkaParserConfig } from './interfaces/microservice-configuration.interface';

const parserConfig: KafkaParserConfig = {
  keepBinary: true,
};

// Use this when configuring a Kafka consumer/parser that must receive
// raw Buffer payloads, such as protobuf, Avro, or encrypted messages.
```

## AI Coding Instructions

- Set `keepBinary: true` when handlers need access to the raw Kafka `Buffer` payload.
- Use `keepBinary: false` when message values should be parsed or converted before reaching application handlers.
- Ensure downstream handlers match the configured payload type; binary payloads should not be treated as JSON strings without decoding.
- Keep this configuration aligned with the message serializer and deserializer used by Kafka producers and consumers.
