You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: daprdocs/content/en/reference/components-reference/supported-pubsub/setup-apache-kafka.md
+46-2
Original file line number
Diff line number
Diff line change
@@ -468,7 +468,7 @@ Apache Kafka supports the following bulk metadata options:
468
468
469
469
When invoking the Kafka pub/sub, its possible to provide an optional partition key by using the `metadata` query param in the request url.
470
470
471
-
The param name is `partitionKey`.
471
+
The param name can either be `partitionKey` or `__key`
472
472
473
473
Example:
474
474
@@ -484,7 +484,7 @@ curl -X POST http://localhost:3500/v1.0/publish/myKafka/myTopic?metadata.partiti
484
484
485
485
### Message headers
486
486
487
-
All other metadata key/value pairs (that are not `partitionKey`) are set as headers in the Kafka message. Here is an example setting a `correlationId` for the message.
487
+
All other metadata key/value pairs (that are not `partitionKey` or `__key`) are set as headers in the Kafka message. Here is an example setting a `correlationId` for the message.
488
488
489
489
```shell
490
490
curl -X POST http://localhost:3500/v1.0/publish/myKafka/myTopic?metadata.correlationId=myCorrelationID&metadata.partitionKey=key1 \
@@ -495,7 +495,51 @@ curl -X POST http://localhost:3500/v1.0/publish/myKafka/myTopic?metadata.correla
495
495
}
496
496
}'
497
497
```
498
+
### Kafka Pubsub special message headers received on consumer side
498
499
500
+
When consuming messages, special message metadata are being automatically passed as headers. These are:
501
+
- `__key`: the message key if available
502
+
- `__topic`: the topic for the message
503
+
- `__partition`: the partition number for the message
504
+
- `__offset`: the offset of the message in the partition
505
+
- `__timestamp`: the timestamp for the message
506
+
507
+
You can access them within the consumer endpoint as follows:
508
+
{{< tabs "Python (FastAPI)" >}}
509
+
510
+
{{% codetab %}}
511
+
512
+
```python
513
+
from fastapi import APIRouter, Body, Response, status
0 commit comments