itplanningandarchite
61 views
43 slides
May 03, 2024
Slide 1 of 110
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
About This Presentation
Read basic of implementing Apache Kafka.
Size: 8.96 MB
Language: en
Added: May 03, 2024
Slides: 43 pages
Slide Content
Apache Kafka ® 101
What’s Covered Introduction Hands On: Your First Kafka Application in 10 Minutes or Less Topics Partitioning Hands On: Partitioning Brokers Replication Producers Consumers Hands On: Consumers Ecosystem Kafka Connect Hands On: Kafka Connect Confluent Schema Registry Hands On: Confluent Schema Registry Kafka Streams ksqlDB Hands On: ksqlDB
Introduction
Event Internet of Things
Event Internet of Things Business process change
Event Internet of Things Business process change User Interaction
Event Internet of Things Business process change User Interaction Microservice output
Notification + State
Key Value
Hands On: Your First Kafka Application in 10 Minutes or Less
GET STARTED TODAY Confluent Cloud cnfl.io/confluent-cloud PROMO CODE: KAFKA101 $101 of free usage
Hands On: Your First Kafka Application in 10 Minutes or Less
Topics
Topics
Topics Named container for similar events
Topics Named container for similar events System contains lots of topics Can duplicate data between topics
Topics Named container for similar events System contains lots of topics Can duplicate data between topics Durable logs of events
Topics Named container for similar events System contains lots of topics Can duplicate data between topics Durable logs of events Append only
Topics Named container for similar events System contains lots of topics Can duplicate data between topics Durable logs of events Append only Can only seek by offset, not indexed
Topics Named container for similar events System contains lots of topics Can duplicate data between topics Durable logs of events Append only Can only seek by offset, not indexed Events are immutable
Brokers An computer, instance, or container running the Kafka process
Brokers An computer, instance, or container running the Kafka process Manage partitions Handle write and read requests
Brokers An computer, instance, or container running the Kafka process Manage partitions Handle write and read requests Manage replication of partitions
Brokers An computer, instance, or container running the Kafka process Manage partitions Handle write and read requests Manage replication of partitions Intentionally very simple
Replication Copies of data for fault tolerance One lead partition and N-1 followers
Replication Copies of data for fault tolerance One lead partition and N-1 followers In general, writes and reads happen to the leader
Replication Copies of data for fault tolerance One lead partition and N-1 followers In general, writes and reads happen to the leader An invisible process to most developers
Replication Copies of data for fault tolerance One lead partition and N-1 followers In general, writes and reads happen to the leader An invisible process to most developers Tunable in the producer
{ final Properties consumerAppProps = KafkaConsumerApplication. load Properties(args[0]); final String filePath = consumerAppProps.getProperty( “file.path” ); final Consumer<String, String> consumer = new KafkaConsumer <>(consumerAppProps); final ConsumerRecordsHandler<String, String> recordsHandler = new FilewritingrecordsHandler(Paths.get(filePa … final KafkaConsumerapplication consumerApplication = new KafkaConsumerApplication(consumer, recordsHandler);
@ public void runConsume ( final Properties consumerProps) { try { consumer . subscribe (Collections. singletonList (consumerProps.getProperty( “input.topic.name” ))); while ( keepConsuming ) { final ConsumerRecords<String, String> consumerRecords = v consumer .poll(Duration. ofSeconds ( 1 )); recordsHandler .process(consumerRecords); }
@ public void process ( final ConsumerRecords<String, String> consumerRecords ) { final List<String> valueList = new ArrayList<>(); consumer Records .forEach(record -> valueList .add(record.value())); if (!valueList.isEmpty()) { try { Files. write ( path, valueList, StandardOpenOption. CREATE , StandardOpenOption. WRITE , StandardOpenOption … } catch (IOException e) { throw new RuntimeException(e); } } }
Consumers Client application Reads messages from topics Connection pooling Network protocol Horizontally and elastically scalable Maintains ordering within partitions at scale
Partition 0 Partition 1 Partition 2 Partitioned Topic Consumer A Consumer B
Partition 0 Partition 1 Partition 2 Partitioned Topic Consumer A
Partition 0 Partition 1 Partition 2 Partitioned Topic Consumer A Consumer A Consumer B
java application > configuration > dev.properties 1 group.id =movie_ratings 2 3 bootstrap.servers =localhost:29092 4 5 key.serializer =org.apache.kafka.common.serialization.StringSerializer 6 value .serializer =org.apache.kafka.common.serialization.StringSerializer 7 acks =all 8 9 #Properties below this line are specific to code in this application 10 input.topic.name =input-topic 11 output.topic.name =output-topic
Partition 0 Partition 1 Partition 2 Partitioned Topic Consumer A Consumer A Consumer B Consumer A
Hands On: Consumers
Hands On: Consumers
Ecosystem
Kafka Connect
Kafka Connect Data integration system and ecosystem Because some other systems are not Kafka External client process; does not run on brokers
Cluster Data Source Kafka Connect Kafka Connect Data Sink
Kafka Connect Data integration system and ecosystem Because some other systems are not Kafka External client process; does not run on brokers Horizontally scalable Fault tolerant
Kafka Connect Data integration system and ecosystem Because some other systems are not Kafka External client process; does not run on brokers Horizontally scalable Fault tolerant Declarative
Connectors Pluggable software component
Connectors Pluggable software component Interfaces to external system and to Kafka
Connectors Pluggable software component Interfaces to external system and to Kafka Also exist as runtime entities
Connectors Pluggable software component Interfaces to external system and to Kafka Also exist as runtime entities Source connectors act as producers
Connectors Pluggable software component Interfaces to external system and to Kafka Also exist as runtime entities Source connectors act as producers Sink connectors act as consumers
Hands On: Kafka Connect
Hands On: Kafka Connect
Confluent Schema Registry
New consumers will emerge
Schemas evolve with the business
Schema Registry Server process external to Kafka brokers
Schema Registry Server process external to Kafka brokers Maintains a database of schemas
Schema Registry Server process external to Kafka brokers Maintains a database of schemas HA deployment option available
Schema Registry Server process external to Kafka brokers Maintains a database of schemas HA deployment option available Consumer/Producer API component
Schema Registry Defines schema compatibility rules per topic
Schema Registry Defines schema compatibility rules per topic Producer API prevents incompatible messages from being produced
Schema Registry Defines schema compatibility rules per topic Producer API prevents incompatible messages from being produced Consumer API prevents incompatible messages from being consumer
Kafka Streams Functional Java API Filtering, grouping, aggregating, joining, and more
Kafka Streams Functional Java API Filtering, grouping, aggregating, joining, and more Scalable, fault-tolerant state management
Kafka Streams Functional Java API Filtering, grouping, aggregating, joining, and more Scalable, fault-tolerant state management Scalable computation based on consumer groups
Kafka Streams Integrates within your services as a library
Kafka Streams Integrates within your services as a library Runs in the context of your application
Kafka Streams Integrates within your services as a library Runs in the context of your application Does not require special infrastructure
Insert Code: https://youtu.be/UbNoL5tJEjc?t=443
ksqlDB
ksqlDB A database optimized for stream processing
ksqlDB A database optimized for stream processing Runs on its own scalable, fault-tolerant cluster adjacent to the Kafka cluster
ksqlDB A database optimized for stream processing Runs on its own scalable, fault-tolerant cluster adjacent to the Kafka cluster Stream processing programs written in SQL
src > main > ksql > rate-movies.sql 1 2 CREATE TABLE rated_movies AS 3 SELECT title, 4 SUM (rating)/ COUNT (rating) AS avg_rating 5 FROM ratings 6 INNER JOIN movies 7 ON ratings.movie_id=movies.movie_id 8 GROUP BY title EMIT CHANGES;
ksqlDB Command line interface REST API for application integration
ksqlDB Command line interface REST API for application integration Java library
ksqlDB Command line interface REST API for application integration Java library Kafka Connect integration
Hands On: ksqlDB
Hands On: ksqlDB
Your Apache Kafka journey begins here developer.confluent.io