This repository was archived by the owner on Oct 25, 2022. It is now read-only.
forked from hakimel/reveal.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
417 lines (373 loc) · 13.2 KB
/
index.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Kafka 101: Schema Registry</title>
<meta name="description" content="An introductory presentation on the Kafka's RESTful interface for storing and retrieving schemas">
<meta name="author" content="Frank Wisniewski, Lars Pfannenschmidt">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/night.css" id="theme">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Custom stylesheet -->
<link rel="stylesheet" href="css/custom.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section data-background="img/front-page-blur.png" id="front-page">
<h3>Kafka 101</h3>
<h1>Schema Registry</h1>
<p>
<small><a href="https://github.com/frankwis">Frank</a> / <a href="http://twitter.com/ultraknackig">@ultraknackig</a></small>
<small>& <a href="https://github.com/larsp">Lars</a> / <a href="http://twitter.com/leastangle">@leastangle</a></small>
</p>
</section>
<section data-background="img/front-page-blur.png" id="content">
<h2>What to expect</h2>
<ul>
<li>Serialization</li>
<li>Apache Avro™</li>
<li>Schema Registry</li>
<ul>
<li>REST API</li>
<li>Producer</li>
<li>Consumer</li>
</ul>
</ul>
</section>
<section id="motivation" data-background="#FFB03B">
<section>
<h1>Serialization</h1>
</section>
<section>
<h2>The Evolution of Serialization</h2>
<ol>
<li>Built-in Serialization</li>
<li>JSON/XML</li>
<li>Binary</li>
<li>Schema</li>
</ol>
<aside class="notes">
<ul>
<li>Programming language’s native frameworks.</li>
<li>Language-agnostic, not locked into particular PL.</li>
<li>Reduces verbosity, increases parsing performance, differentiates between int and longs</li>
<li>Separation of Schema and Data Persistence
<ul>
<li>cross-language</li>
<li>no more data with inconsistent type; generate model for static typed PLs</li>
<li>save even more space by omitting field names</li>
</ul>
</li>
</ul>
</aside>
</section>
<section>
<h2>Eventually, the schema changes</h2>
<aside class="notes">
<ul>
<li>code refactoring or DB schema changes</li>
<li>results in both ugly and unmaintainable code</li>
<li>developers who are tired of having to modify their scripts again and again.</li>
<li>schema changes happen frequently, and often without warning.</li>
</ul>
</aside>
</section>
<section>
<h2>Schema Evolution</h2>
<ul>
<li>Backward compatibility</li>
<li>Forward compatibility</li>
<li>Full compatibility</li>
</ul>
<aside class="notes">
<ul>
<li>new schema can be used to read the data written in all previous schemas</li>
<li>all previous schemas can read data written in this schema</li>
<li>backward and forward compatible</li>
</ul>
</aside>
</section>
</section>
<section id="avro" data-background="#B64926">
<section>
<h1>Avro</h1>
</section>
<section>
<h2>Structuring Data in Kafka</h2>
<pre><code data-trim>
curl -X POST -i -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{"schema":"{\"type\":\"fixed\", \"name\":\"IPv4\", \"size\":4}"}' \
http://127.0.0.1:8081/subjects/ip/versions
</code></pre>
<pre><code data-trim>
{
"type":"fixed",
"name":"IPv4",
"size":4
}
</code></pre>
<aside class="notes">
<ul>
<li>size: an integer, specifying the number of bytes per value (required).</li>
<li>IPv4 uses 32-bit (four-byte) addresses</li>
</ul>
</aside>
</section>
<section>
<h2>Schema Declaration</h2>
<h4>Primitive Types</h4>
null, boolean, int, long, float, double, bytes, string
<pre><code data-trim>
"string"
{"type": "int"}
</code></pre>
<span class="fragment">
<h4>Complex Types</h4>
records, enums, arrays, maps, unions, fixed
<pre><code data-trim>
{
"type":"record",
"name":"Click",
"namespace":"io.kafka101.clickstream.schema.domain",
"fields":[
{
"name":"time",
"type":"string"
},
{
"name":"page",
"type":"string"
},
...
]
}
</code></pre>
</p>
<aside class="notes">
<ul>
<li>schemas may be maintained manually or generated out of the domain model</li>
<li>API for handling schemas</li>
<li>Jackson like annotations</li>
</ul>
</aside>
</section>
<section>
<h2>Schema Evolution</h2>
Evlolving a schema using a <code data-trim>UNION</code>
<pre><code data-trim>
[
{
"type":"fixed",
"name":"IPv4",
"size":4
},
{
"type":"fixed",
"name":"IPv6",
"size":16
}
]
</code></pre>
</section>
<section>
<h2>Conflict Resolution</h2>
<pre><code data-trim>
@AvroDefault("\"unknown\"")
public final String user;
@Nullable
public final String origin;
@AvroIgnore
private boolean processed = false;
public Click(String time, String ip, String page, String user, String origin) {
super(time, ip, page);
this.user = user;
this.origin = origin;
}
</code></pre>
<aside class="notes">
<ul>
<li>@AvroEncode for CustomEncoding implementations</li>
<li>@AvroAlias old names maybe attached as an alias</li>
<li>Jackson like annotations</li>
</ul>
</aside>
</section>
</section>
<section id="schema-registry" data-background="#8E2800">
<section>
<h1>Schema Registry</h1>
</section>
<section>
<h2>Overview</h2>
<img width="50%" src="img/schema-registry.svg">
</section>
<section id="schema-api">
<h2>REST API</h2>
<pre class="fragment"><code data-trim>
curl -X POST -i -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{"schema":"{\"type\":\"fixed\", \"name\":\"IPv4\", \"size\":4}"}' \
http://127.0.0.1:8081/subjects/ip/versions
</code></pre>
<pre class="fragment"><code data-trim>
curl -i -H "Content-Type: application/vnd.schemaregistry.v1+json" \
http://127.0.0.1:8081/subjects/ip/versions/1
</code></pre>
<pre class="fragment"><code data-trim>
curl -X POST -i -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{"schema":"[ {\"type\":\"fixed\", \"name\":\"IPv4\", \"size\":4}, {\"type\":\"fixed\", \"name\":\"IPv6\", \"size\":16}]"}' \
http://127.0.0.1:8081/subjects/ip/versions
</code></pre>
<a class="fragment" href="http://docs.confluent.io/1.0/schema-registry/docs/api.html">API Reference</a>
</section>
<section id="producer">
<h2>Producer</h2>
<pre class="fragment"><code class="java" data-trim>
public class Producer {
...
public Producer(String topic, String broker, String registryUrl) throws JsonMappingException {
this.topic = topic;
this.producer = createProducer(broker, registryUrl);
this.translator = new AvroTranslator();
}
private KafkaProducer<String, GenericRecord> createProducer(String broker, String registryUrl) {
Properties config = new Properties();
config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, broker);
config.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, KafkaAvroSerializer.class.getName());
config.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KafkaAvroSerializer.class.getName());
config.put(AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, registryUrl);
return new KafkaProducer<>(config);
}
...
}
</code></pre>
</section>
<section>
<h2>send()</h2>
<pre><code class="java" data-trim>
public class Producer {
...
public RecordMetadata send(Click click) throws ExecutionException, InterruptedException {
GenericRecord genericRecord = translator.toAvro(click);
ProducerRecord<String, GenericRecord> record = new ProducerRecord<>(topic, click.ip, genericRecord);
return this.producer.send(record).get();
}
...
}
</code></pre>
</section>
<section>
<h2>AvroTranslator.java?</h2>
</section>
<section id="consumer">
<h2>Consumer</h2>
<pre class="fragment"><code class="java" data-trim>
public class Consumer<T> {
...
private Properties getConfiguration(String zookeeper, String schemaUrl, String groupId) {
...
props.put("schema.registry.url", schemaUrl);
return props;
}
...
public void run(int numThreads) {
Map<String, Integer> topicCountMap = new HashMap();
topicCountMap.put(topic, new Integer(numThreads));
KafkaAvroDecoder avroDecoder = new KafkaAvroDecoder(new VerifiableProperties(configuration));
Map<String, List<KafkaStream<Object, Object>>> consumerMap = consumerConnector.createMessageStreams(
topicCountMap, avroDecoder, avroDecoder);
List<KafkaStream<Object, Object>> streams = consumerMap.get(topic);
// create fixed size thread pool to launch all the threads
pool = Executors.newFixedThreadPool(numThreads);
// create consumer threads to handle the messages
int threadNumber = 0;
for (final KafkaStream stream : streams) {
String name = String.format("%s[%s]", consumer.getTopic(), threadNumber++);
Runnable runnable = new ConsumerThread(stream, name, consumer);
pool.submit(runnable);
}
}
}
</code></pre>
</section>
<section>
<h2>ConsumerThread</h2>
<pre><code class="java" data-trim>
public class ConsumerThread implements Runnable {
...
@Override
public void run() {
Thread.currentThread().setName(name);
logger.info("Started consumer thread {}", name);
ConsumerIterator<String, Object> it = messageStream.iterator();
while (it.hasNext()) {
relayMessage(it.next());
}
logger.info("Shutting down consumer thread {}", name);
}
private void relayMessage(MessageAndMetadata<String, Object> kafkaMessage) {
logger.debug("Received message with key '{}' and offset '{}' on partition '{}' for topic '{}'",
kafkaMessage.key(), kafkaMessage.offset(), kafkaMessage.partition(), kafkaMessage.topic());
GenericContainer record = (GenericContainer) kafkaMessage.message();
Click click = translator.toObject(record, Click.class);
consumer.consume(click);
}
}
</code></pre>
</section>
<section>
Sample Code: <a href="https://github.com/kafka101/clickstream-schema">github.com/kafka101/clickstream-schema</a><br>
Chef & Vagrantfile: <a href="https://supermarket.chef.io/cookbooks/confluent-cookbook">supermarket.chef.io/cookbooks/confluent-cookbook</a><br>
Kafka intro: <a href="https://github.com/kafka101/java-news-feed">github.com/kafka101/java-news-feed</a><br>
</section>
</section>
<section id="end">
<h2>Questions?</h2>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
width: 1280,
height: 800,
margin: 0.1,
minScale: 1,
maxScale: 1.2,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, condition: function() { return !!document.querySelector( 'pre code' ); }, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true },
{ src: 'plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>