Skip to content

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: true

Functions 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: true

Subject with sequence number

yaml
subject:
  fromString: "orders.created.{{ msg_count() }}"
  parseAsTemplate: true

Randomized test data

yaml
data:
  fromString: '{"name":"{{ rand.person.firstName() }}","email":"{{ rand.person.email() }}"}'
  parseAsTemplate: true

Base64 encode payload field

yaml
data:
  fromString: '{"token":"{{ encode.base64(uuid.v4()) }}"}'
  parseAsTemplate: true

Runtime Variables

VariableAvailable InDescription
msg_count()subject, headers, data1-based index of the current message/request iteration
msg_subject()headers, dataThe resolved subject of the current message

Where Templates Are Evaluated

FieldFlagDefault
spec.subject.fromString (Publish/Request)parseAsTemplatefalse
spec.data.fromString and spec.data.fromFileparseAsTemplatetrue when omitted
spec.headers[].keyparseKeyAsTemplatetrue
spec.headers[].valueparseValueAsTemplatetrue

If you need literal \{\{ ... \}\} text, disable parsing with the matching flag.

High-Value Namespaces

  • uuid: request IDs and correlation keys
  • time: timestamps and date partitioning
  • rand: sample payload generation
  • strings: formatting and normalization
  • encode / hash: signing, encoding, and checksums

Troubleshooting

  • Template not evaluated: check parse flags (parseAsTemplate, parseValueAsTemplate, etc.)
  • Unknown function: verify namespace (for example uuid.v4() not uuid_v4())
  • File templates: fromFile paths are relative to the collection directory
  • Prefer smaller templates and keep complex payloads in files for readability

Powered by Qaze