: test stream data: first event id: 1 data:second event id data: third event
event-stream
Event Stream Format
MIME type: text/event-stream
ID: eventstream
DataWeave represents the Event Stream as an Array
of Object
, where each value is a String
.
The output type is Array<{_:String}>
, where each key represents a field in the event.
Examples
These examples show uses of the Event Stream format.
Example: Simple Server Event Input
This example shows how DataWeave represents a simple server event input.
Input
This stream contains four blocks. The first block has one comment, and fires no events. The second block has two fields with names data
and id
respectively; an event is fired with the data first event
and sets the last event ID to 1
. The third block fires an event with the data second event
; it also has an id
field with no value, which resets the last event ID to an empty string. The fourth block contains a data
field with the value third event
, which fires an event.
Source
The DataWeave script transforms this input into the given output.
%dw 2.0
output application/json
---
payload
dataweave
Output
The JSON format outputs the 3 events.
[
{
"data": "first event",
"id": "1"
},
{
"data": "second event",
"id": ""
},
{
"data": "third event"
}
]
json
Example: Ignoring Spaces After the Colon
This example shows that spaces after the colon are ignored if present.
Input
data:test data: test
event-stream
Source
This process transforms the input into JSON.
%dw 2.0
output application/json
---
payload
dataweave
Output
The JSON output is an Array
of the valid Object
from the server event input.
[ { "data": "test" }, { "data": "test" } ]
weave
Configuration Properties
DataWeave supports these configuration properties for this format.
Reader Properties
This format has no reader properties.
Writer Properties
This format accepts properties that provide instructions for writing output data.
Parameter | Type | Default | Description |
---|---|---|---|
|
|
|
Size of the buffer writer, in bytes. The value must be greater than |
|
|
|
Generates the output as a data stream when set to Valid values are |
Supported MIME Types
This format supports the following MIME types.
MIME Type |
---|
|