-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path07-example-convert.yaml
More file actions
76 lines (72 loc) · 2.5 KB
/
07-example-convert.yaml
File metadata and controls
76 lines (72 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# $schema: https://axual.github.io/ksml/latest/ksml-language-spec.json
# This example shows how to read from a simple AVRO stream, then perform a series of conversions:
#
# source topic --> AVRO --> JSON --> String --> JSON --> XML --> String --> XML --> target topic
# output to a target topic.
#
# Note that AVRO, XML and JSON all have the same INTERNAL representation, so printing one or the other won't give any
# other output on stdout. The difference only shows when converting to a String or writing to a target topic.
streams:
sensor_source:
topic: ksml_sensordata_avro
keyType: string
valueType: avro:SensorData
offsetResetPolicy: latest
sensor_target:
topic: ksml_sensordata_xml
keyType: string
valueType: xml:SensorData
pipelines:
# The main pipeline reads messages, converts to json, outputs them, and saves to a target topic
main_to_xml:
from: sensor_source
via:
# Change notation from AVRO to JSON
- type: convertValue
into: json
name: avro_to_json
- type: peek
forEach:
code: log.info("AVRO TO JSON - key={}, value={}", key, value)
# Convert from JSON to String
- type: convertValue
into: string
name: json_to_string
- type: peek
forEach:
code: log.info("JSON TO STRING - key={}, value={}", key, value)
# Convert back from String to JSON
- type: convertValue
into: json
name: string_to_json
- type: peek
forEach:
code: log.info("STRING TO JSON - key={}, value={}", key, value)
# Change notation from JSON to XML
- type: convertValue
into: xml:SensorData
name: json_to_xml
- type: peek
forEach:
code: log.info("JSON TO XML - key={}, value={}", key, value)
# Convert from XML to String
- type: convertValue
into: string
name: xml_to_string
- type: peek
forEach:
code: log.info("XML TO STRING - key={}, value={}", key, value)
# Convert back from String to XML
- type: convertValue
into: xml:SensorData
name: string_to_xml
- type: peek
forEach:
code: log.info("STRING TO XML - key={}, value={}", key, value)
to:
topic: ksml_sensordata_xml
# The alternative pipeline achieves the same, but by inlining the target topic definition and its
# data types (conversion is done implicitly on writing to the target topic)
alternate_to_xml:
from: sensor_source
to: sensor_target