Kafka delivery modes¶
Choose your decoder to match the event source mapping. Lambda can deliver original binary data in SOURCE mode or convert registry-backed messages to JSON first.
Read JSON-mode messages¶
Use the kafka and logger imports from the JSON order example. This snippet runs in a function returning error.
Input
A JSON-mode Kafka record containing { "id": "ORD-123" }.
Complete Lambda event
Code
appLog := logger.New(logger.WithServiceName("orders"))
consumer := kafka.New(kafka.Config{Value: &kafka.FieldConfig{Type: kafka.JSON}})
records, err := consumer.Deserialize(ctx, event)
if err != nil { return err }
value, err := records.Records[0].Value(ctx)
if err != nil { return err }
return appLog.Info("Order received", logger.Fields{"order": value})
event is the decoded input above.
Output
This is a log excerpt; Logger also adds its level, timestamp, service and sampling rate. The order field contains the decoded value, not the Lambda handler response.
Select a mode¶
| Lambda delivery | Consumer value configuration |
|---|---|
| JSON text, including registry-converted JSON | FieldConfig{Type: kafka.JSON} |
| SOURCE Avro data | Explicit Avro schema/adapter |
| SOURCE Protobuf data | Explicit Protobuf descriptor/adapter |
| Plain text without a schema | Omit the field configuration |
Configure key and value independently. Preserve the schema metadata supplied by Lambda; it is not a request to fetch a schema.
Things to know¶
- Keep the Kafka wrapper's raw event entry point when metadata presence and numeric tokens matter; typed SDK event models can lose that information.
- A registry schema ID does not make the library a schema registry client.
- Self-managed Kafka and MSK events both use the record decoding APIs. Deployment configuration belongs to the event source mapping.