Docs menu
Build a scenario
Scenario file Generators vars and const Time and pace Defaults Relationships Schedules Instances Lifecycle Collections Connections Delivery behaviorBuild a scenario
Connections
Until now, the lessons printed generated values locally. A connection tells Synthtraffic where to send those events.
Connections have two parts:
connectionscontains named, reusable destination settings such as Kafka brokers or an HTTP base URL.- Each generator selects one of those names with
connectionand provides the fields for one event, such as a Kafkatopicandvalue.
This keeps credentials and client settings separate from the data generated for every event.
Shape an event for Kafka
Kafka needs more than the order value. It also needs a topic and, optionally, a key and headers. We want the preview to show this envelope:
{
"topic": "shop.orders",
"key": "ORD-000",
"headers": null,
"value": {
"orderId": "ORD-000",
"status": "placed",
"total": 49.99
}
}
Orders ready for a Kafka topic
connections:
eventBus:
type: kafka
brokers: [localhost:9092]
generators:
- name: orders
connection: eventBus
config:
maxEvents: 2
vars:
orderId: =seq(format=ORD-%03d)
topic: shop.orders
key: $orderId
value:
orderId: $orderId
status: placed
total: =cycle(49.99, 84.50)
Press Try it. Previewing does not contact localhost:9092; it safely shows the envelope above.
Connection settings and event fields
The introduced lines belong to those two parts:
connections.eventBusnames reusable destination settings.type: kafkaselects the Kafka connection behavior.brokerslists the bootstrap address.connection: eventBusselects that connection fororders.topic,key, andvaluedescribe the event sent to Kafka.
The shared $orderId comes from vars, so the Kafka key and payload always identify the same order. Expressions are calculated before delivery; the connection receives finished fields and does not change them.
The event fields depend on the destination:
- Kafka:
topic, optionalkeyandheaders, andvalue - PostgreSQL:
table,row, and optionalschema - HTTP: optional
method, requiredpath, optionalqueryandheaders, and optionalbody - File and cloud storage:
prefixandvalue
Do not move these fields into connections. One connection can be reused by generators that publish to different topics, tables, paths, or artifact prefixes.
Preview before sending
Use sample while shaping an event. It skips real-time waits and never opens Kafka, PostgreSQL, HTTP, file, or cloud-storage connections. Use run --stdout when you also want real pacing and delivery behavior without contacting the destination. A connected run opens every declared connection and sends events.
sample prints a short preview to your terminal. It does not
wait for real-time pacing, and it never opens Kafka, PostgreSQL, or other
destinations.
synthtraffic sample kafka-orders.yaml --events 2 --seed 42 docker run --rm \
--env-file ./license.env \
--volume "${PWD}/kafka-orders.yaml:/work/kafka-orders.yaml:ro" \
synthtraffic/synthtraffic:latest \
sample /work/kafka-orders.yaml --events 2 --seed 42 run --stdout prints the destination-shaped envelope locally
without opening the configured connection. Remove --stdout
when you are ready to send to that destination.
synthtraffic run kafka-orders.yaml --stdout --events 2 --seed 42 docker run --rm \
--env-file ./license.env \
--volume "${PWD}/kafka-orders.yaml:/work/kafka-orders.yaml:ro" \
synthtraffic/synthtraffic:latest \
run /work/kafka-orders.yaml --stdout --events 2 --seed 42 Full flag lists: sample and run. Install and license: Install.
After the envelope looks right:
- Start Kafka and create
shop.orders. - Replace the example broker address if Kafka is elsewhere.
- Run the shown
run --stdoutcommand once more to verify the full paced output. - Remove
--stdoutto publish through the configured connection.
Choose a destination
Each guide starts with a runnable scenario, then lists every supported setting and the setup required for real delivery:
- Kafka —
topic, optionalkeyandheaders, andvalue - PostgreSQL —
tableandrow, with an explicit schema policy - HTTP —
method,path, optional request fields, andbody - File — rolling local artifacts
- S3, GCS, and Azure Blob — rolling cloud-storage objects