Skip to content

Commit 0e22a69

Browse files
antontroshinyaron2
andauthored
Add Kafka escapeHeaders documentation (#4332)
* Add Kafka escapeHeaders documentation Signed-off-by: Anton Troshin <[email protected]> * update the escapeHeaders setting docs Signed-off-by: Anton Troshin <[email protected]> * review fixes Signed-off-by: Anton Troshin <[email protected]> --------- Signed-off-by: Anton Troshin <[email protected]> Co-authored-by: Yaron Schneider <[email protected]>
1 parent 581fabb commit 0e22a69

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

daprdocs/content/en/reference/components-reference/supported-bindings/kafka.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ spec:
6363
value: true
6464
- name: schemaLatestVersionCacheTTL # Optional. When using Schema Registry Avro serialization/deserialization. The TTL for schema caching when publishing a message with latest schema available.
6565
value: 5m
66+
- name: escapeHeaders # Optional.
67+
value: false
6668
```
6769
6870
## Spec metadata fields
@@ -99,6 +101,7 @@ spec:
99101
| `consumerFetchDefault` | N | Input/Output | The default number of message bytes to fetch from the broker in each request. Default is `"1048576"` bytes. | `"2097152"` |
100102
| `heartbeatInterval` | N | Input | The interval between heartbeats to the consumer coordinator. At most, the value should be set to a 1/3 of the `sessionTimeout` value. Defaults to `"3s"`. | `"5s"` |
101103
| `sessionTimeout` | N | Input | The timeout used to detect client failures when using Kafka’s group management facility. If the broker fails to receive any heartbeats from the consumer before the expiration of this session timeout, then the consumer is removed and initiates a rebalance. Defaults to `"10s"`. | `"20s"` |
104+
| `escapeHeaders` | N | Input | Enables URL escaping of the message header values received by the consumer. Allows receiving content with special characters that are usually not allowed in HTTP headers. Default is `false`. | `true` |
102105

103106
#### Note
104107
The metadata `version` must be set to `1.0.0` when using Azure EventHubs with Kafka.

daprdocs/content/en/reference/components-reference/supported-pubsub/setup-apache-kafka.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ spec:
6363
value: true
6464
- name: schemaLatestVersionCacheTTL # Optional. When using Schema Registry Avro serialization/deserialization. The TTL for schema caching when publishing a message with latest schema available.
6565
value: 5m
66+
- name: escapeHeaders # Optional.
67+
value: false
6668

6769
```
6870

@@ -112,6 +114,7 @@ spec:
112114
| consumerFetchDefault | N | The default number of message bytes to fetch from the broker in each request. Default is `"1048576"` bytes. | `"2097152"` |
113115
| heartbeatInterval | N | The interval between heartbeats to the consumer coordinator. At most, the value should be set to a 1/3 of the `sessionTimeout` value. Defaults to "3s". | `"5s"` |
114116
| sessionTimeout | N | The timeout used to detect client failures when using Kafka’s group management facility. If the broker fails to receive any heartbeats from the consumer before the expiration of this session timeout, then the consumer is removed and initiates a rebalance. Defaults to "10s". | `"20s"` |
117+
| escapeHeaders | N | Enables URL escaping of the message header values received by the consumer. Allows receiving content with special characters that are usually not allowed in HTTP headers. Default is `false`. | `true` |
115118

116119
The `secretKeyRef` above is referencing a [kubernetes secrets store]({{< ref kubernetes-secret-store.md >}}) to access the tls information. Visit [here]({{< ref setup-secret-store.md >}}) to learn more about how to configure a secret store component.
117120

@@ -485,6 +488,39 @@ curl -X POST http://localhost:3500/v1.0/publish/myKafka/myTopic?metadata.correla
485488
}'
486489
```
487490

491+
## Receiving message headers with special characters
492+
493+
The consumer application may be required to receive message headers that include special characters, which may cause HTTP protocol validation errors.
494+
HTTP header values must follow specifications, making some characters not allowed. [Learn more about the protocols](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2).
495+
In this case, you can enable `escapeHeaders` configuration setting, which uses URL escaping to encode header values on the consumer side.
496+
497+
{{% alert title="Note" color="primary" %}}
498+
When using this setting, the received message headers are URL escaped, and you need to URL "un-escape" it to get the original value.
499+
{{% /alert %}}
500+
501+
Set `escapeHeaders` to `true` to URL escape.
502+
503+
```yaml
504+
apiVersion: dapr.io/v1alpha1
505+
kind: Component
506+
metadata:
507+
name: kafka-pubsub-escape-headers
508+
spec:
509+
type: pubsub.kafka
510+
version: v1
511+
metadata:
512+
- name: brokers # Required. Kafka broker connection setting
513+
value: "dapr-kafka.myapp.svc.cluster.local:9092"
514+
- name: consumerGroup # Optional. Used for input bindings.
515+
value: "group1"
516+
- name: clientID # Optional. Used as client tracing ID by Kafka brokers.
517+
value: "my-dapr-app-id"
518+
- name: authType # Required.
519+
value: "none"
520+
- name: escapeHeaders
521+
value: "true"
522+
```
523+
488524
## Avro Schema Registry serialization/deserialization
489525
You can configure pub/sub to publish or consume data encoded using [Avro binary serialization](https://avro.apache.org/docs/), leveraging an [Apache Schema Registry](https://developer.confluent.io/courses/apache-kafka/schema-registry/) (for example, [Confluent Schema Registry](https://developer.confluent.io/courses/apache-kafka/schema-registry/), [Apicurio](https://www.apicur.io/registry/)).
490526

@@ -597,6 +633,7 @@ To run Kafka on Kubernetes, you can use any Kafka operator, such as [Strimzi](ht
597633

598634
{{< /tabs >}}
599635

636+
600637
## Related links
601638
- [Basic schema for a Dapr component]({{< ref component-schema >}})
602639
- Read [this guide]({{< ref "howto-publish-subscribe.md##step-1-setup-the-pubsub-component" >}}) for instructions on configuring pub/sub components

0 commit comments

Comments
 (0)