-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetting-started.html
More file actions
524 lines (510 loc) · 29.1 KB
/
Copy pathgetting-started.html
File metadata and controls
524 lines (510 loc) · 29.1 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover">
<meta name="theme-color" content="#0052D4">
<link rel="shortcut icon" href="assets/img/favicon.png" type="image/png">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;700&family=Raleway:wght@700&family=Ubuntu+Mono&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.2/styles/idea.min.css">
<link rel="stylesheet" href="assets/css/index.css">
<title>KSML</title>
<script>
//- Picture element HTML5 shiv
document.createElement( 'picture' );
</script>
<script src="https://cdn.rawgit.com/scottjehl/picturefill/3.0.2/dist/picturefill.min.js" async=""></script>
</head>
<body>
<header class="header">
<div class="container header__container"><a class="header__logo" href="/"><img src="assets/img/logo.svg" alt="KSML"></a>
<div class="header__nav">
<nav class="menu"> <a class="menu__link" href="index.html">Overview</a><a class="menu__link" href="getting-started.html">Getting Started</a><a class="menu__link" href="https://axual.github.io/ksml/">Documentation</a></nav>
</div>
<button class="header__burger" id="burger" aria-label="Menu button"><svg data-name="menu" viewBox="0 0 36 36" width="36" height="36" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M34.5 19.469h-33a1.5 1.5 0 010-3h33a1.5 1.5 0 010 3zM34.5 7.969h-33a1.5 1.5 0 010-3h33a1.5 1.5 0 010 3zM34.5 30.969h-33a1.5 1.5 0 010-3h33a1.5 1.5 0 010 3z" fill="#1F2854"/></svg></button>
</div>
</header>
<div id="menu">
<button id="burgerClose" aria-label="Close"><svg data-name="close" width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M28.395 30.517L5.061 7.181a1.5 1.5 0 012.121-2.121l23.334 23.334a1.5 1.5 0 01-2.12 2.122z" fill="#1F2854"/><path d="M30.517 7.182L7.181 30.516a1.5 1.5 0 01-2.121-2.12L28.395 5.06a1.5 1.5 0 012.122 2.12z" fill="#1F2854"/></svg></button>
<nav class="menu"> <a class="menu__link" href="index.html">Overview</a><a class="menu__link" href="getting-started.html">Getting Started</a><a class="menu__link" href="https://axual.github.io/ksml/">Documentation</a></nav>
</div>
<main>
<section class="start-promo"><img class="start-promo__bg" src="assets/img/start-promo/start-bg-top.png" alt="bg"><img class="start-promo__bgm" src="assets/img/start-promo/start-bg-top-m.png" alt="bg">
<picture class="start-promo__illustration"><img src="assets/img/start-promo/illustration.svg" alt="illustration"></picture>
<div class="container">
<div class="start-promo__info">
<h1 class="start-promo__title">Build your own streaming data pipeline using KSML</h1>
<p class="p3">Step-by-step guide of setting up the runtime and building your own streaming data pipeline</p>
<div class="start-promo__btns"><a class="btn btn_gradient" href="#start-build"> <span>Learn More</span></a>
</div>
</div>
</div>
</section>
<section class="start-build" id="start-build">
<div class="start-build__box">
<div class="container start-build__box-wrap">
<div class="start-build__illustration"> <img src="assets/img/start-build/illustration.svg" alt="What you will build"></div>
<div class="start-build__info">
<div class="start-build__info-icon blue">
<svg data-name="modular" width="34" height="34" viewBox="0 0 34 34" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M13.929 23.36l-3.072 5.32 2.784 4.822a.996.996 0 00.863.498h4.992c.356 0 .685-.19.863-.498l2.784-4.822-3.072-5.32H13.93zM16.004 12.632v1.858l-.292-.292a.996.996 0 00-1.409 1.409l1.993 1.992a.996.996 0 001.408 0l1.992-1.992a.996.996 0 10-1.408-1.409l-.292.292v-1.858h-1.992zM13.641 10.141a.996.996 0 00.863.498h4.992c.356 0 .685-.19.863-.498l2.496-4.323a.996.996 0 000-.996L20.36.498A.996.996 0 0019.496 0h-4.992a.996.996 0 00-.863.498l-2.496 4.324a.996.996 0 000 .996l2.496 4.323zM33.794 21.867l-2.496-4.324a.996.996 0 00-.863-.498h-4.992a.996.996 0 00-.863.498l-2.783 4.822 3.07 5.32h5.568c.356 0 .685-.19.863-.499l2.496-4.323a.996.996 0 000-.996zM9.42 17.543a.996.996 0 00-.863-.498H3.565a.996.996 0 00-.863.498L.206 21.867a.996.996 0 000 .996l2.496 4.323a.996.996 0 00.863.498h5.567l3.072-5.32-2.784-4.82z" fill="#fff"/></svg></div>
<h2>What you will build</h2>
<p class="p1">You will build an app to do stream processing on fictional sensor data (temperature, humidity, light). Sensor data is generated for you using a simulator. Your job is to do stream processing in a low-code way using KSML. </p>
</div>
</div>
</div>
</section>
<section class="start-need">
<div class="container">
<h2 class="start-need__title">What you need</h2>
<div class="start-need__items">
<div class="start-need__elem">
<div class="start-need__elem-box">
<div class="start-need__elem-icon blue"><svg data-name="clock" width="34" height="35" viewBox="0 0 35 35" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#prefix__clip0)"><path d="M17 .5C7.626.5 0 8.126 0 17.5c0 9.374 7.626 17 17 17 9.374 0 17-7.626 17-17 0-9.374-7.626-17-17-17zm8.085 25.793a1.413 1.413 0 01-2.003 0l-7.084-7.083a1.41 1.41 0 01-.415-1.002V9a1.416 1.416 0 112.834 0v8.622l6.668 6.668c.554.554.554 1.45 0 2.003z" fill="#fff"/></g><defs><clipPath id="prefix__clip0"><path fill="#fff" transform="translate(0 .5)" d="M0 0h34v34H0z"/></clipPath></defs></svg></div>
<p class="p1">15 minutes of your time</p>
</div>
</div>
<div class="start-need__elem">
<div class="start-need__elem-box">
<div class="start-need__elem-icon green"><svg data-name="code" width="34" height="34" viewBox="0 0 34 34" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#prefix__clip0)" fill="#fff"><path d="M16.06 16.846a.717.717 0 00-.21-.507L4.103 4.594a.717.717 0 00-1.014 0L.21 7.472a.716.716 0 000 1.014l8.36 8.36-8.36 8.36a.718.718 0 000 1.015l2.879 2.878a.714.714 0 001.014 0L15.85 17.353a.714.714 0 00.21-.507zM33.283 25.03H15.051a.717.717 0 00-.717.716V28.9c0 .396.32.717.717.717h18.232A.717.717 0 0034 28.9v-3.154a.717.717 0 00-.717-.717z"/></g><defs><clipPath id="prefix__clip0"><path fill="#fff" d="M0 0h34v34H0z"/></clipPath></defs></svg></div>
<p class="p1">Your favorite Editor</p>
</div>
</div>
<div class="start-need__elem">
<div class="start-need__elem-box">
<div class="start-need__elem-icon orange"><svg data-name="docker" width="44" height="45" viewBox="0 0 44 45" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M23.763 21.336h-3.895v-3.5h3.895v3.5zm0-12.038h-3.895v3.576h3.895V9.298zm4.608 8.532h-3.895v3.5h3.895v-3.5zm-9.21-4.248h-3.895v3.541h3.895v-3.541zm4.602 0h-3.895v3.541h3.895v-3.541zm16.31 5.892c-.848-.572-2.804-.778-4.307-.495-.194-1.414-.984-2.646-2.422-3.753l-.825-.548-.548.825c-1.084 1.638-1.378 4.336-.218 6.116-.512.277-1.52.654-2.852.63H3.287c-.513 2.994.342 6.883 2.592 9.552 2.187 2.587 5.463 3.9 9.747 3.9 9.274 0 16.14-4.271 19.35-12.032 1.261.026 3.984.007 5.38-2.663.089-.147.39-.778.501-1.007l-.784-.525zM9.957 17.83H6.068v3.5h3.895v-3.5h-.006zm4.602 0h-3.895v3.5h3.895v-3.5zm4.602 0h-3.895v3.5h3.895v-3.5zm-4.602-4.248h-3.895v3.541h3.895v-3.541z" fill="#fff"/></svg></div>
<p class="p1">Docker 19.x</p>
</div>
</div>
</div>
</div>
</section>
<section class="start-step2">
<div class="container">
<div class="start-step2__wrap">
<div class="start-step2__half">
<img src="assets/img/start-complete/github_light.png" alt="GitHub project landing page" style="padding: 48px 51px 64px;">
</div>
<div class="start-step2__half">
<div class="step">Step 1</div>
<h2 class="start-step2__title">Download the KSML Repository</h2>
<ul>
<li>
<p class="p1">Go to the <a href="https://github.com/Axual/ksml">KSML repository</a></p>
</li>
<li>
<p class="p1">Clone the repository with GIT, or download a ZIP file using the Code button</p>
<p class="p1">If you've downloaded a zip file, extract it to a working directory</p>
</li>
<li>
<p class="p1">Open the repository in your favorite editor.</p>
<p class="p1">We will be working in the root and the examples directory of the project. The other
directories contain the source code of KSML. You can take a look if you're interested.</p>
</li>
</ul>
</div>
</div>
</section>
<section class="start-step1">
<div class="container">
<div class="start-step1__wrap">
<div class="start-step1__half">
<div class="step">Step 2</div>
<h2 class="start-step1__title">Start a local Kafka environment + data generator</h2>
<ul>
<li>
<p class="p1">Open the `docker-compose.yml` file in the root directory.</p>
<p class="p1">This file start a Kafka environment with Schema Registry and a data generator for the examples</p>
</li>
<li>
<p class="p1">Perform a `docker-compose up -d` in the root directory to start the environment in the background</p>
<p class="p1">Docker has recently introduced an alternative command `docker compose up -d`</p>
</li>
</ul>
</div>
<div class="start-step1__half">
<div class="exemple">Docker Compose Definition</div>
<div class="code">
<div class="code__box">
<pre> <code class="language-yml">
<pre>
version: "3.7"
services:
# Services can be reached from the local machine and in the docker network
# From the host machine:
# * Localhost port 9092 connects to the broker
# * Localhost port 8081 connects to the schema registry
# From the Docker network:
# * broker port 9093 connects to the broker
# * schema_registry port 8081 connects to the broker
networks:
ksml:
name: ksml_example
driver: bridge
services:
zookeeper:
image: confluentinc/cp-zookeeper:6.0.0
hostname: zookeeper
ports:
- "2181:2181"
networks:
- ksml
restart: always
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
broker:
image: confluentinc/cp-enterprise-kafka:6.0.0
hostname: broker
depends_on:
- zookeeper
ports:
- "9092:9092"
networks:
- ksml
restart: always
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_ADVERTISED_LISTENERS: 'INNER://broker:9093,OUTER://localhost:9092'
KAFKA_LISTENERS: 'INNER://broker:9093,OUTER://broker:9092'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: 'INNER:PLAINTEXT,OUTER:PLAINTEXT'
KAFKA_LOG_CLEANUP_POLICY: delete
KAFKA_LOG_RETENTION_MINUTES: 10
KAFKA_INTER_BROKER_LISTENER_NAME: INNER
KAFKA_METRIC_REPORTERS: io.confluent.metrics.reporter.ConfluentMetricsReporter
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'
KAFKA_MIN_INSYNC_REPLICAS: 1
KAFKA_NUM_PARTITIONS: 1
CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS: broker:9093
CONFLUENT_METRICS_REPORTER_ZOOKEEPER_CONNECT: zookeeper:2181
CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS: 1
CONFLUENT_METRICS_ENABLE: 'true'
CONFLUENT_SUPPORT_CUSTOMER_ID: 'anonymous'
schema_registry:
image: confluentinc/cp-schema-registry:6.0.0
hostname: schema_registry
depends_on:
- zookeeper
- broker
ports:
- "8081:8081"
networks:
- ksml
restart: always
environment:
SCHEMA_REGISTRY_HOST_NAME: schema_registry
SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: 'PLAINTEXT://broker:9093'
SCHEMA_REGISTRY_KAFKASTORE_TOPIC_REPLICATION_FACTOR: 1
SCHEMA_REGISTRY_ZK_NAMESPACE: 'mySRNS'
# This "container" is a workaround to pre-create topics
kafka-setup:
image: confluentinc/cp-enterprise-kafka:6.0.0
hostname: kafka-setup
networks:
- ksml
depends_on:
- broker
- schema_registry
command: "bash -c 'echo Waiting for Kafka to be ready... && \
cub kafka-ready -b broker:9093 1 20 && \
kafka-topics --create --if-not-exists --bootstrap-server broker:9093 --partitions 1 --replication-factor 1 --topic ksml_sensordata_avro && \
kafka-topics --create --if-not-exists --bootstrap-server broker:9093 --partitions 1 --replication-factor 1 --topic ksml_sensordata_copy && \
kafka-topics --create --if-not-exists --bootstrap-server broker:9093 --partitions 1 --replication-factor 1 --topic ksml_sensordata_filtered && \
kafka-topics --create --if-not-exists --bootstrap-server broker:9093 --partitions 1 --replication-factor 1 --topic ksml_sensordata_blue && \
kafka-topics --create --if-not-exists --bootstrap-server broker:9093 --partitions 1 --replication-factor 1 --topic ksml_sensordata_red && \
kafka-topics --create --if-not-exists --bootstrap-server broker:9093 --partitions 1 --replication-factor 1 --topic ksml_sensordata_sensor0 && \
kafka-topics --create --if-not-exists --bootstrap-server broker:9093 --partitions 1 --replication-factor 1 --topic ksml_sensordata_sensor1 && \
kafka-topics --create --if-not-exists --bootstrap-server broker:9093 --partitions 1 --replication-factor 1 --topic ksml_sensordata_sensor2'"
example-producer:
image: axual/ksml-example-producer:latest
hostname: kafka-setup
restart: always
networks:
- ksml
working_dir: /ksml
volumes:
- ./examples:/ksml
depends_on:
- broker
- schema_registry
- kafka-setup
</pre></code></pre>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="start-step2">
<div class="container">
<div class="start-step2__wrap">
<div class="start-step2__half">
<div class="exemple">Verify datageneration</div>
<div class="code small">
<div class="code__box">
<pre> <code class="language-bash">
<pre>docker-compose logs -f example-producer</pre>
</code></pre>
</div>
</div>
</div>
<div class="start-step2__half">
<div class="step">Step 3</div>
<h2 class="start-step2__title">Verify that the data generator is running</h2>
<ul>
<li>
<p class="p1">Perform a `docker-compose logs -d example-producer`. By looking at your console you should see the data generator in action, you should see produce messages appear.</p>
<p class="p1">The service can fail several times while waiting for the Kafka topics to be created.</p>
<p class="p1">Docker has recently introduced an alternative command `docker compose logs -d example-producer`</p>
</li>
</ul>
<div class="code">
<div class="code__box">
<pre> <code class="language-accesslog hljs"><pre>example-producer_1 | 2021-05-11T09:55:00,169Z [system] [main] INFO i.a.k.e.producer.KSMLExampleProducer - Using Kafka backend
example-producer_1 | 2021-05-11T09:55:00,445Z [system] [main] INFO i.a.k.e.producer.KSMLExampleProducer - Producing: 0
example-producer_1 | 2021-05-11T09:55:01,161Z [system] [main] INFO i.a.k.e.producer.KSMLExampleProducer - Produced message to topic ksml_sensordata_avro partition 0 offset 0
example-producer_1 | 2021-05-11T09:55:01,661Z [system] [main] INFO i.a.k.e.producer.KSMLExampleProducer - Producing: 1
example-producer_1 | 2021-05-11T09:55:01,667Z [system] [main] INFO i.a.k.e.producer.KSMLExampleProducer - Produced message to topic ksml_sensordata_avro partition 0 offset 1
example-producer_1 | 2021-05-11T09:55:02,167Z [system] [main] INFO i.a.k.e.producer.KSMLExampleProducer - Producing: 2
example-producer_1 | 2021-05-11T09:55:02,173Z [system] [main] INFO i.a.k.e.producer.KSMLExampleProducer - Produced message to topic ksml_sensordata_avro partition 0 offset 2
example-producer_1 | 2021-05-11T09:55:02,675Z [system] [main] INFO i.a.k.e.producer.KSMLExampleProducer - Producing: 3
example-producer_1 | 2021-05-11T09:55:02,682Z [system] [main] INFO i.a.k.e.producer.KSMLExampleProducer - Produced message to topic ksml_sensordata_avro partition 0 offset 3
</pre></code></pre>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="start-step3">
<div class="container">
<div class="start-step3__wrap">
<div class="start-step3__half">
<div class="step">Step 4</div>
<h2 class="start-step3__title">Build your KSML definitions</h2>
<p class="p1">The next step is to build a KSML definition that is going to process the data. Below you will find 3 simple examples that help you to understand the KSML syntax better and see what it is capable of.</p>
<div class="exemple">Example 1</div>
<h3>Inspecting topic data</h3>
<p class="p1">Create a file `sensor-inspect.yaml` in the folder `/examples` with the following contents</p>
</div>
<div class="start-step3__half">
<div class="exemple">examples/sensor-inspect.yaml</div>
<div class="code">
<div class="code__box">
<pre> <code class="language-apache">
<pre>
streams:
ksml_sensordata_avro:
topic: ksml_sensordata_avro
keyType: string
valueType: avro:SensorData
functions:
print_message:
type: forEach
code: "print('key='+(key if isinstance(key,str) else str(key))+', value='+(value if isinstance(value,str) else str(value)))"
pipelines:
main:
from: ksml_sensordata_avro
forEach: print_message</pre>
</code></pre>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="start-step4">
<div class="container">
<div class="start-step4__wrap">
<div class="start-step4__half">
<div class="exemple">examples/ksml-runner.yml</div>
<div class="code">
<div class="code__box">
<pre> <code class="language-yaml">
<pre>
ksml:
workingDirectory: /ksml
definitions:
- sensor-inspect.yaml
backend:
type: kafka
config:
bootstrapUrl: broker:9093
applicationId: io.ksml.example.processor
schemaRegistryUrl: http://schema_registry:8081
streamsConfig:
acks: all
</pre>
</code></pre>
</div>
</div>
</div>
<div class="start-step4__half">
<div class="step">Step 5</div>
<h2 class="start-step4__title">Launch the KSML Runner</h2>
<p class="p1">It's time to start a KSML Runner with your KSML definition.</p>
<ul>
<li>
<p class="p1">Open the file `ksml-runner.yml` in the `examples` directory.</p>
</li>
<li>
<p class="p1">replace the reference to `1-demo-inspect.yaml` with `sensor-inspect.yaml`</p>
</li>
<li>
<p class="p1">Execute the `run.sh` script in the examples directory</p>
</li>
</ul>
<p class="p1">If everything goes well, you should see the AVRO sensordata being written to STDOUT.</p>
</div>
</div>
</div>
</section>
<section class="start-step5">
<div class="container">
<div class="start-step5__top">
<div class="step">Step 5</div>
<h2 class="start-step5__title">Try out more examples</h2>
<p class="p1">Now that your setup works fine and you have successfully launched the first KSML app, let's add some more. In the list below you will find some example definitions for various operations. Click "expand" to see the code for every example and repeat "step 3" for each of them.</p>
</div>
<div class="start-step5__wrap">
<div class="start-step5__half">
<div class="exemple">Example 2: </div>
<h3>Dynamic topic routing</h3>
<div class="code">
<div class="code__box">
<pre> <code class="language-yaml">
<pre>
streams:
ksml_sensordata_avro:
topic: ksml_sensordata_avro
keyType: string
valueType: avro:SensorData
ksml_sensordata_sensor0:
topic: ksml_sensordata_sensor0
keyType: string
valueType: avro:SensorData
ksml_sensordata_sensor1:
topic: ksml_sensordata_sensor1
keyType: string
valueType: avro:SensorData
ksml_sensordata_sensor2:
topic: ksml_sensordata_sensor2
keyType: string
valueType: avro:SensorData
functions:
print_message:
type: forEach
code: "print('key='+(key if isinstance(key,str) else str(key))+', value='+(value if isinstance(value,str) else str(value)))"
pipelines:
main:
from: ksml_sensordata_avro
via:
- type: peek
forEach: print_message
toExtractor:
code: |
if key == 'sensor1':
return 'ksml_sensordata_sensor1'
elif key == 'sensor2':
return 'ksml_sensordata_sensor2'
else:
return 'ksml_sensordata_sensor0'
</pre>
</code></pre>
</div>
</div>
</div>
<div class="start-step5__half">
<div class="exemple">Example 3: </div>
<h3>Filtering topic data</h3>
<div class="code">
<div class="code__box">
<pre> <code class="language-yaml">
<pre>
streams:
ksml_sensordata_avro:
topic: ksml_sensordata_avro
keyType: string
valueType: avro:SensorData
ksml_sensordata_filtered:
topic: ksml_sensordata_filtered
keyType: string
valueType: avro:SensorData
functions:
print_message:
type: forEach
code: "print('key='+(key if isinstance(key,str) else str(key))+', value='+(value if isinstance(value,str) else str(value)))"
filter_message:
type: predicate
expression: value['color'] == 'blue'
pipelines:
main:
from: ksml_sensordata_avro
via:
- type: filter
predicate: filter_message
- type: peek
forEach: print_message
to: ksml_sensordata_filtered</pre>
</code></pre>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="start-learn">
<div class="container">
<div class="start-learn__top">
<h2 class="start-learn__title">Want to learn more?</h2>
<p class="p1">Did you get the hang of it? <br> Want to know more what KSML is capable of? </p>
</div>
<div class="start-learn__wrap">
<div class="start-learn__elem">
<div class="start-learn__elem-box">
<div class="start-learn__elem-icon blue"><svg data-name="clock" width="34" height="35" viewBox="0 0 35 35" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#prefix__clip0)"><path d="M17 .5C7.626.5 0 8.126 0 17.5c0 9.374 7.626 17 17 17 9.374 0 17-7.626 17-17 0-9.374-7.626-17-17-17zm8.085 25.793a1.413 1.413 0 01-2.003 0l-7.084-7.083a1.41 1.41 0 01-.415-1.002V9a1.416 1.416 0 112.834 0v8.622l6.668 6.668c.554.554.554 1.45 0 2.003z" fill="#fff"/></g><defs><clipPath id="prefix__clip0"><path fill="#fff" transform="translate(0 .5)" d="M0 0h34v34H0z"/></clipPath></defs></svg></div>
<p class="p1">Check our project documentation</p><a class="start-learn__elem-link icon-link" href="https://axual.github.io/ksml/">
Learn More<svg dat-name="arrow" width="31" height="8" viewBox="0 0 31 8" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M30.354 4.354a.5.5 0 000-.708L27.172.464a.5.5 0 10-.707.708L29.293 4l-2.828 2.828a.5.5 0 10.707.708l3.182-3.182zM0 4.5h30v-1H0v1z" /></svg></a>
</div>
</div>
<div class="start-learn__elem">
<div class="start-learn__elem-box">
<div class="start-learn__elem-icon yellow"><svg data-name="code" width="34" height="34" viewBox="0 0 34 34" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#prefix__clip0)" fill="#fff"><path d="M16.06 16.846a.717.717 0 00-.21-.507L4.103 4.594a.717.717 0 00-1.014 0L.21 7.472a.716.716 0 000 1.014l8.36 8.36-8.36 8.36a.718.718 0 000 1.015l2.879 2.878a.714.714 0 001.014 0L15.85 17.353a.714.714 0 00.21-.507zM33.283 25.03H15.051a.717.717 0 00-.717.716V28.9c0 .396.32.717.717.717h18.232A.717.717 0 0034 28.9v-3.154a.717.717 0 00-.717-.717z"/></g><defs><clipPath id="prefix__clip0"><path fill="#fff" d="M0 0h34v34H0z"/></clipPath></defs></svg></div>
<p class="p1">Check the source code and contribute if you like</p><a class="start-learn__elem-link icon-link" href="https://github.com/Axual/ksml">
Learn More<svg dat-name="arrow" width="31" height="8" viewBox="0 0 31 8" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M30.354 4.354a.5.5 0 000-.708L27.172.464a.5.5 0 10-.707.708L29.293 4l-2.828 2.828a.5.5 0 10.707.708l3.182-3.182zM0 4.5h30v-1H0v1z" /></svg></a>
</div>
</div>
</div>
</div>
</section>
</main>
<footer class="footer">
<div class="container">
<div class="footer__wrap">
<div class="footer__top"><a class="footer__logo" href="/"><img src="assets/img/logo.svg" alt="KSML"></a>
<div class="footer__nav">
<nav class="menu"> <a class="menu__link" href="index.html">Overview</a><a class="menu__link" href="getting-started.html">Getting Started</a><a class="menu__link" href="https://axual.github.io/ksml/">Documentation</a></nav>
</div>
<div class="footer__socials" style="visibility: hidden">
<ul class="socials">
<li class="socials__item"><a href="#" title="facebook" target="_blank"><svg data-name="fb" width="8" height="16" viewBox="0 0 8 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M5.826 3.327H7.76V.47H5.487v.01C2.733.58 2.169 2.127 2.119 3.752h-.005v1.426H.239v2.797h1.875v7.496h2.825V7.975h2.315l.447-2.797h-2.76v-.861c0-.55.365-.99.885-.99z"/></svg></a></li>
<li class="socials__item"><a href="#" title="linkein" target="_blank"><svg data-name="in" width="15" height="14" viewBox="0 0 15 14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M.452 13.61h2.81V4.248H.451v9.362zm10.943-9.686c-1.363 0-2.583.498-3.448 1.596V4.217h-2.82v9.393h2.82V8.53c0-1.073.983-2.12 2.215-2.12 1.232 0 1.536 1.047 1.536 2.094v5.105h2.809V8.295c0-3.69-1.748-4.371-3.112-4.371zm-9.551-.612A1.407 1.407 0 101.842.5a1.407 1.407 0 00.002 2.813z"/></svg></a></li>
<li class="socials__item"><a href="#" title="youtube" target="_blank"><svg data-name="yt" width="20" height="14" viewBox="0 0 20 14" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M8.131 9.81L13.011 7 8.13 4.19v5.62zm10.856 1.714c.386-1.467.386-4.509.386-4.509s.015-3.057-.386-4.524A2.35 2.35 0 0017.334.84C15.868.438 10 .438 10 .438s-5.868 0-7.335.386A2.396 2.396 0 001.013 2.49C.627 3.958.627 7 .627 7s0 3.057.386 4.509c.216.803.85 1.436 1.652 1.652 1.483.402 7.335.402 7.335.402s5.867 0 7.334-.387a2.349 2.349 0 001.653-1.652z"/></svg></a></li>
</ul>
</div>
</div>
<div class="footer__bottom"> <span class="footer__license">Licensed under Apache License v2</span>
<var>|</var><span class="footer__copyright">© 2021 KSML. All rights reserved</span>
</div>
</div>
</div>
</footer>
<script src="https://unpkg.com/highlightjs-badge/highlightjs/highlight.pack.js"></script>
<script src="https://unpkg.com/highlightjs-badge/highlightjs-badge.min.js"></script>
<script src="assets/js/index.js"></script>
</body>
</html>