Template Reference
Templates let you generate dynamic subjects, headers, and payloads. Use them when static text is not enough.
Template Syntax
Use \{\{ ... \}\} expressions:
yaml
spec:
subject:
fromString: "orders.{{ msg_count() }}"
parseAsTemplate: trueFunctions are namespaced, for example:
uuid.v4()time.rfc3339()strings.toUpper("abc")
Common Recipes
Correlation ID per message
yaml
headers:
- key: X-Correlation-Id
value: "{{ uuid.v7() }}"Timestamp in payload
yaml
data:
fromString: '{"sentAt":"{{ time.rfc3339() }}"}'
parseAsTemplate: trueSubject with sequence number
yaml
subject:
fromString: "orders.created.{{ msg_count() }}"
parseAsTemplate: trueRandomized test data
yaml
data:
fromString: '{"name":"{{ rand.person.firstName() }}","email":"{{ rand.person.email() }}"}'
parseAsTemplate: trueBase64 encode payload field
yaml
data:
fromString: '{"token":"{{ encode.base64(uuid.v4()) }}"}'
parseAsTemplate: trueRuntime Variables
| Variable | Available In | Description |
|---|---|---|
msg_count() | subject, headers, data | 1-based index of the current message/request iteration |
msg_subject() | headers, data | The resolved subject of the current message |
Where Templates Are Evaluated
| Field | Flag | Default |
|---|---|---|
spec.subject.fromString (Publish/Request) | parseAsTemplate | false |
spec.data.fromString and spec.data.fromFile | parseAsTemplate | true when omitted |
spec.headers[].key | parseKeyAsTemplate | true |
spec.headers[].value | parseValueAsTemplate | true |
If you need literal \{\{ ... \}\} text, disable parsing with the matching flag.
High-Value Namespaces
uuid: request IDs and correlation keystime: timestamps and date partitioningrand: sample payload generationstrings: formatting and normalizationencode/hash: signing, encoding, and checksums
Troubleshooting
- Template not evaluated: check parse flags (
parseAsTemplate,parseValueAsTemplate, etc.) - Unknown function: verify namespace (for example
uuid.v4()notuuid_v4()) - File templates:
fromFilepaths are relative to the collection directory - Prefer smaller templates and keep complex payloads in files for readability