/
configured.clj
601 lines (499 loc) · 13.5 KB
/
configured.clj
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
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
(ns jackdaw.streams.configured
"Clojure wrapper to kafka streams."
{:license "BSD 3-Clause License <https://github.com/FundingCircle/jackdaw/blob/master/LICENSE>"}
(:refer-clojure :exclude [count map reduce group-by merge filter peek])
(:require [jackdaw.streams.protocols :refer :all]
[jackdaw.streams.configurable :refer [config IConfigurable]]))
(set! *warn-on-reflection* true)
(declare configured-kstream configured-ktable configured-global-ktable
configured-kgroupedtable configured-kgroupedstream
configured-time-windowed-kstream
configured-session-windowed-kstream)
(deftype ConfiguredStreamsBuilder [config streams-builder]
IStreamsBuilder
(kstream
[_ topic-config]
(configured-kstream
config
(kstream streams-builder topic-config)))
(kstream
[_ topic-config topic-pattern]
(configured-kstream
config
(kstream streams-builder topic-config topic-pattern)))
(kstreams
[_ topic-configs]
(configured-kstream
config
(kstreams streams-builder topic-configs)))
(ktable
[_ topic-config]
(configured-ktable
config
(ktable streams-builder topic-config)))
(ktable
[_ topic-config store-name]
(configured-ktable
config
(ktable streams-builder topic-config store-name)))
(global-ktable
[_ topic-config]
(configured-global-ktable
config
(global-ktable streams-builder topic-config)))
(source-topics
[_]
(source-topics streams-builder))
(streams-builder*
[_]
(streams-builder* streams-builder))
IConfigurable
(config [_]
config)
(configure [_ key value]
(ConfiguredStreamsBuilder.
(assoc config key value)
streams-builder)))
(defn streams-builder
"Makes a topology builder."
([config streams-builder]
(ConfiguredStreamsBuilder. config streams-builder)))
(deftype ConfiguredKStream [config kstream]
IKStreamBase
(left-join
[_ ktable value-joiner-fn]
(configured-kstream
config
(left-join kstream ktable value-joiner-fn)))
(left-join
[_ ktable value-joiner-fn topic-config other-topic-config]
(configured-kstream
config
(left-join kstream ktable value-joiner-fn topic-config other-topic-config)))
(filter
[_ predicate-fn]
(configured-kstream
config
(filter kstream predicate-fn)))
(filter-not
[_ predicate-fn]
(configured-kstream
config
(filter-not kstream predicate-fn)))
(group-by
[_ key-value-mapper-fn]
(configured-kgroupedstream
config
(group-by kstream key-value-mapper-fn)))
(group-by
[_ key-value-mapper-fn topic-config]
(configured-kgroupedstream
config
(group-by kstream key-value-mapper-fn topic-config)))
(peek
[_ peek-fn]
(configured-kstream
config
(peek kstream peek-fn)))
(map-values
[_ value-mapper-fn]
(configured-kstream
config
(map-values kstream value-mapper-fn)))
(print!
[_]
(print! kstream))
(through
[_ topic-config]
(configured-kstream
config
(through kstream topic-config)))
(to!
[_ topic-config]
(to! kstream topic-config))
IKStream
(branch
[_ predicate-fns]
(mapv (partial configured-kstream config)
(branch kstream predicate-fns)))
(flat-map
[_ key-value-mapper-fn]
(configured-kstream
config
(flat-map kstream key-value-mapper-fn)))
(flat-map-values
[_ value-mapper-fn]
(configured-kstream
config
(flat-map-values kstream value-mapper-fn)))
(for-each!
[_ foreach-fn]
(for-each! kstream foreach-fn))
(group-by-key
[_]
(configured-kgroupedstream
config
(group-by-key kstream)))
(group-by-key
[_ topic-config]
(configured-kgroupedstream
config
(group-by-key kstream topic-config)))
(join-windowed
[_ other-kstream value-joiner-fn windows]
(configured-kstream
config
(join-windowed kstream
other-kstream
value-joiner-fn
windows)))
(join-windowed
[_ other-kstream value-joiner-fn windows topic-config other-topic-config]
(configured-kstream
config
(join-windowed kstream
other-kstream
value-joiner-fn
windows
topic-config
other-topic-config)))
(left-join-windowed
[_ other-kstream value-joiner-fn windows]
(configured-kstream
config
(left-join-windowed kstream other-kstream value-joiner-fn windows)))
(left-join-windowed
[_ other-kstream value-joiner-fn windows topic-config other-topic-config]
(configured-kstream
config
(left-join-windowed kstream
other-kstream
value-joiner-fn
windows
topic-config
other-topic-config)))
(map
[_ key-value-mapper-fn]
(configured-kstream
config
(map kstream key-value-mapper-fn)))
(merge
[_ other-kstream]
(configured-kstream
config
(merge kstream
other-kstream)))
(outer-join-windowed
[_ other-kstream value-joiner-fn windows]
(configured-kstream
config
(outer-join-windowed kstream
other-kstream
value-joiner-fn
windows)))
(outer-join-windowed
[_ other-kstream value-joiner-fn windows topic-config other-topic-config]
(configured-kstream
config
(outer-join-windowed kstream
other-kstream
value-joiner-fn
windows
topic-config
other-topic-config)))
(process!
[_ processor-supplier-fn state-store-names]
(process! kstream processor-supplier-fn state-store-names))
(select-key
[_ key-value-mapper-fn]
(configured-kstream
config
(select-key kstream key-value-mapper-fn)))
(transform
[this transformer-supplier-fn]
(transform this transformer-supplier-fn []))
(transform
[_ transformer-supplier-fn state-store-names]
(configured-kstream
config
(transform kstream transformer-supplier-fn state-store-names)))
(transform-values
[this value-transformer-supplier-fn]
(transform-values this value-transformer-supplier-fn []))
(transform-values
[_ value-transformer-supplier-fn state-store-names]
(configured-kstream
config
(transform-values kstream value-transformer-supplier-fn state-store-names)))
(left-join-global
[_ global-ktable kv-mapper joiner]
(configured-kstream
config
(left-join-global kstream global-ktable kv-mapper joiner)))
(join-global
[_ global-ktable kv-mapper joiner]
(configured-kstream
config
(join-global kstream global-ktable kv-mapper joiner)))
(kstream* [_]
(kstream* kstream))
IConfigurable
(config [_]
config)
(configure [_ key value]
(configured-kstream
(assoc config key value)
kstream)))
(defn configured-kstream
"Makes a ConfiguredStream object."
[config kstream]
(ConfiguredKStream. config kstream))
(deftype ConfiguredKTable [config ktable]
IKStreamBase
(left-join
[_ other-ktable value-joiner-fn]
(configured-ktable
config
(left-join ktable other-ktable value-joiner-fn)))
(filter
[_ predicate-fn]
(configured-ktable
config
(filter ktable predicate-fn)))
(filter-not
[_ predicate-fn]
(configured-ktable
config
(filter-not ktable predicate-fn)))
(map-values
[_ value-mapper-fn]
(configured-ktable
config
(map-values ktable value-mapper-fn)))
IKTable
(group-by
[_ key-value-mapper-fn]
(configured-kgroupedtable
config
(group-by ktable key-value-mapper-fn)))
(group-by
[_ key-value-mapper-fn topic-config]
(configured-kgroupedtable
config
(group-by ktable key-value-mapper-fn topic-config)))
(join
[_ other-ktable value-joiner-fn]
(configured-ktable
config
(join ktable other-ktable value-joiner-fn)))
(outer-join
[_ other-ktable value-joiner-fn]
(configured-ktable
config
(outer-join ktable other-ktable value-joiner-fn)))
(suppress
[_ suppressed]
(configured-ktable
config
(suppress ktable suppressed)))
(to-kstream
[_]
(configured-kstream
config
(to-kstream ktable)))
(to-kstream
[_ key-value-mapper-fn]
(configured-kstream
config
(to-kstream ktable key-value-mapper-fn)))
(ktable* [_]
(ktable* ktable))
IConfigurable
(config [_]
config)
(configure [_ key value]
(configured-ktable
(assoc config key value)
ktable)))
(defn configured-ktable
"Makes a ConfiguredKTable object."
[config ktable]
(ConfiguredKTable. config ktable))
(deftype ConfiguredKGroupedTable [config kgroupedtable]
IKGroupedBase
(aggregate
[_ initializer-fn adder-fn subtractor-fn topic-config]
(configured-ktable
config
(aggregate kgroupedtable initializer-fn adder-fn subtractor-fn topic-config)))
(aggregate
[_ initializer-fn adder-fn subtractor-fn]
(configured-ktable
config
(aggregate kgroupedtable initializer-fn adder-fn subtractor-fn)))
(count
[_]
(configured-ktable
config
(count kgroupedtable)))
(count
[_ store-name]
(configured-ktable
config
(count kgroupedtable store-name)))
(reduce
[_ adder-fn subtractor-fn topic-config]
(configured-ktable
config
(reduce kgroupedtable adder-fn subtractor-fn topic-config)))
(reduce
[_ adder-fn subtractor-fn]
(configured-ktable
config
(reduce kgroupedtable adder-fn subtractor-fn)))
IKGroupedTable
(kgroupedtable*
[_]
(kgroupedtable* kgroupedtable))
IConfigurable
(config [_]
config)
(configure [_ key value]
(configured-kgroupedtable
(assoc config key value)
kgroupedtable)))
(defn configured-kgroupedtable
"Makes a ConfiguredKGroupedTable object."
[config kgroupedtable]
(ConfiguredKGroupedTable. config kgroupedtable))
(deftype ConfiguredKGroupedStream [config kgroupedstream]
IKGroupedBase
(aggregate
[_ initializer-fn aggregator-fn topic-config]
(configured-ktable
config
(aggregate kgroupedstream initializer-fn aggregator-fn topic-config)))
(aggregate
[_ initializer-fn aggregator-fn]
(configured-ktable
config
(aggregate kgroupedstream initializer-fn aggregator-fn)))
(count
[_]
(configured-ktable
config
(count kgroupedstream)))
(count
[_ store-name]
(configured-ktable
config
(count kgroupedstream store-name)))
(reduce
[_ reducer-fn topic-config]
(configured-ktable
config
(reduce kgroupedstream reducer-fn topic-config)))
(reduce
[_ reducer-fn]
(configured-ktable
config
(reduce kgroupedstream reducer-fn)))
IKGroupedStream
(windowed-by-time
[_ windows]
(configured-time-windowed-kstream
config
(windowed-by-time kgroupedstream windows)))
(windowed-by-session
[_ windows]
(configured-session-windowed-kstream
config
(windowed-by-session kgroupedstream windows)))
(kgroupedstream*
[_]
kgroupedstream))
(defn configured-kgroupedstream
"Makes a ConfiguredKGroupedStream object."
[config kgroupedstream]
(ConfiguredKGroupedStream. config kgroupedstream))
(deftype ConfiguredTimeWindowedKStream [config kgroupedstream]
IKGroupedBase
(aggregate
[_ initializer-fn aggregator-fn topic-config]
(configured-ktable
config
(aggregate kgroupedstream initializer-fn aggregator-fn topic-config)))
(count
[_]
(configured-ktable
config
(count kgroupedstream)))
(count
[_ store-name]
(configured-ktable
config
(count kgroupedstream store-name)))
(reduce
[_ reducer-fn topic-config]
(configured-ktable
config
(reduce kgroupedstream reducer-fn topic-config)))
(reduce
[_ reducer-fn]
(configured-ktable
config
(reduce kgroupedstream reducer-fn)))
ITimeWindowedKStream
(time-windowed-kstream*
[_]
kgroupedstream))
(defn configured-time-windowed-kstream
"Makes a ConfiguredKGroupedStream object."
[config kgroupedstream]
(ConfiguredTimeWindowedKStream. config kgroupedstream))
(deftype ConfiguredSessionWindowedKStream [config kgroupedstream]
IKGroupedBase
(aggregate
[_ initializer-fn aggregator-fn merger-fn topic-config]
(configured-ktable
config
(aggregate kgroupedstream initializer-fn aggregator-fn merger-fn topic-config)))
(count
[_]
(configured-ktable
config
(count kgroupedstream)))
(count
[_ store-name]
(configured-ktable
config
(count kgroupedstream store-name)))
(reduce
[_ reducer-fn topic-config]
(configured-ktable
config
(reduce kgroupedstream reducer-fn topic-config)))
ISessionWindowedKStream
(session-windowed-kstream*
[_]
kgroupedstream))
(defn configured-session-windowed-kstream
"Makes a ConfiguredKGroupedStream object."
[config kgroupedstream]
(ConfiguredSessionWindowedKStream. config kgroupedstream))
(deftype ConfiguredGlobalKTable [config global-ktable]
IGlobalKTable
(global-ktable*
[_]
(global-ktable* global-ktable))
IConfigurable
(config [_]
config)
(configure [_ key value]
(configured-global-ktable
(assoc config key value)
global-ktable)))
(defn configured-global-ktable
"Makes a ConfiguredKTable object."
[config global-ktable]
(ConfiguredGlobalKTable. config global-ktable))