SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
Paris Apache Kafka
Meetup
Florian HUSSONNOIS
Zenika
@fhussonnois
Async, Sync, Batch, Partitioner et Retries
Properties config = new Properties();
config.put("bootstrap.servers", "localhost:9092");
KafkaProducer<String, String> producer = new KafkaProducer(config);
ProducerRecord record = new ProducerRecord("my_topic", "my_key", "my_value");
producer.send(record);
producer.close();
L’appel à la méthode send()est asynchrone et retourne immédiatement
Le message est ajouté à un buffer avant d’être envoyé
//...
config.put("batch.size", 16384);
config.put("linger.ms", 1);
//... Latence entre chaque transmission de messages
Taille maximum d’un batch
List<ProducerRecord> batchRecords = new ArrayList<>();
//...
for(ProducerRecord record : batchRecords)
producer.send(record);
producer.flush();
producer.close(); Force l’envoi des messages et bloque jusqu’à leur
complétion
Future<RecordMetadata> future = producer.send(record);
RecordMetadata metadata = future.get(); // BLOCK
LOG.info("message sent to topic {}, partition {}, offset {}",
metadata.topic(),
metadata.partition(),
metadata.offset());
ProducerRecord record = new ProducerRecord("my_topic", "my_key", "my_value");
Future<RecordMetadata> future = producer.send(record, (metadata, e) -> {
if(e != null)
LOG.info("Message sent to topic {}, partition {}, offset {}",
metadata.topic(),
metadata.partition(),
metadata.offset());
else
LOG.error("Damn it!", e);
});
Configuration
config.put("partitioner.class", DefaultPartitioner.class.getName()
Implémenter un Partitioner
public interface Partitioner {
int partition(String topic,
Object key, byte[] keyBytes,
Object value, byte[] valueBytes, Cluster cluster);
}
Spécifier directement la partition cible
new ProducerRecord("my_topic", 0, "my_key", "my_value");
Acknowledgments
config.put("ack", "all "); // plus lent, messages répliqués par tous les ISR
Le Producer peut rejouer automatiquement les messages en erreurs
config.put("retries", "0 "); // désactivé
/! Peut provoquer des doublons (At-Least Once)
/! Peut changer l’ordre de publication des messages
Event Loop, Polling Model, Offset et Group
Management
Properties config = new Properties();
config.put("bootstrap.servers", "localhost:9092");
KafkaConsumer<Object, Object> consumer = new KafkaConsumer<>(config);
consumer.subscribe(Arrays.asList("topic1, topic2"));
while(true) {
ConsumerRecords<Object, Object> records = consumer.poll(1000);
records.forEach(record ->
LOG.info("key={}, value={}", record.key(), record.value()));
}
Event Loop, Polling Model
Properties config = new Properties();
config.put("bootstrap.servers", "localhost:9092");
config.put("enable.auto.commit", false); // désactive auto-commit
config.put("auto.commit.interval.ms", 100);
KafkaConsumer<Object, Object> consumer = new KafkaConsumer<>(config);
consumer.subscribe(Arrays.asList("topic1, topic2"));
while(true) {
ConsumerRecords<Object, Object> records = consumer.poll(1000);
records.forEach(record ->
LOG.info("key={}, value={}", record.key(), record.value()));
consumer.commitAsync();
}
}
while(true) {
ConsumerRecords<Object, Object> records = consumer.poll(1000);
consumer.commitSync(); // Commit offsets before processing messages.
records.forEach(record ->
LOG.info("key={}, value={}", record.key(), record.value()));
}
Properties config = new Properties();
config.put("bootstrap.servers", "localhost:9092");
config.put("group.id", "my_group");
KafkaConsumer<Object, Object> consumer = new KafkaConsumer<>(config);
consumer.subscribe(Arrays.asList("topic1, topic2"));
KafkaConsumer<Object, Object> consumer = new KafkaConsumer<>(config);
consumer.subscribe(Arrays.asList("topic1, topic2"), new
ConsumerRebalanceListener() {
@Override
public void onPartitionsRevoked(Collection<TopicPartition> partitions) {
//do some stuff
}
@Override
public void onPartitionsAssigned(Collection<TopicPartition> partitions) {
//do some stuff
}
});
Chaque consumer d’un groupe doit notifier le coordinateur
Uniquement possible sur un appel aux méthodes poll, commit, etc.
Déclenché si un consumer rejoint ou quitte un groupe
L’opération de « rebalance » est impactée par les paramètres :
• session.timeout.ms (30 secondes)
• heartbeat.interval.ms
Rebalance intempestif en cas de traitement d’un message trop long
ConsumerRecords<Object, Object> records = consumer.poll(1000);
if( ! records.isEmpty() ) {
consumer.pause(consumer.assignment().toArray(new TopicPartition[0]));
Future<Boolean> future = executorService.submit(() -> {
records.forEach(record -> LOG.info("key={}, value={}", record.key(), record.value()));
return true;
});
Boolean isCompleted = false;
while(!isCompleted) {
try {
isCompleted = future.get(5, TimeUnit.SECONDS); // Wait before polling
} catch (TimeoutException e) {
consumer.poll(0); // heart-beat
} catch (CancellationException |ExecutionException | InterruptedException e) {
break;
}
}
consumer.resume(consumer.assignment().toArray(new TopicPartition[0]));
consumer.commitSync();
}
ExecutorService
Se positionner à un offset spécifique
consumer.seek(new TopicPartition("my_topic", 0), 42);
consumer.seekToEnd(new TopicPartition("my_topic", 0));
consumer.seekToBeginning(new TopicPartition("my_topic", 0));
Assignements manuel
consumer.assign(Arrays.asList(new TopicPartition("my_topic", 0)));
Obtenir les métriques
consumer.metrics();
Nous recrutons ! jobs@zenika.com
@ZenikaIT
Prochain Meetup le

Weitere ähnliche Inhalte

Was ist angesagt?

Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQLPeter Eisentraut
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Tom Croucher
 
What's new in Ansible 2.0
What's new in Ansible 2.0What's new in Ansible 2.0
What's new in Ansible 2.0Allan Denot
 
Lambda Jam 2015: Event Processing in Clojure
Lambda Jam 2015: Event Processing in ClojureLambda Jam 2015: Event Processing in Clojure
Lambda Jam 2015: Event Processing in ClojureAndy Marks
 
Redis as a message queue
Redis as a message queueRedis as a message queue
Redis as a message queueBrandon Lamb
 
Hopping in clouds: a tale of migration from one cloud provider to another
Hopping in clouds: a tale of migration from one cloud provider to anotherHopping in clouds: a tale of migration from one cloud provider to another
Hopping in clouds: a tale of migration from one cloud provider to anotherMichele Orselli
 
Lightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMRLightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMRShinji Tanaka
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationrjsmelo
 
Application Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.keyApplication Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.keyTim Bunce
 
Using ngx_lua in UPYUN 2
Using ngx_lua in UPYUN 2Using ngx_lua in UPYUN 2
Using ngx_lua in UPYUN 2Cong Zhang
 
MySQL Audit using Percona audit plugin and ELK
MySQL Audit using Percona audit plugin and ELKMySQL Audit using Percona audit plugin and ELK
MySQL Audit using Percona audit plugin and ELKYoungHeon (Roy) Kim
 
Using Cerberus and PySpark to validate semi-structured datasets
Using Cerberus and PySpark to validate semi-structured datasetsUsing Cerberus and PySpark to validate semi-structured datasets
Using Cerberus and PySpark to validate semi-structured datasetsBartosz Konieczny
 
More than syntax
More than syntaxMore than syntax
More than syntaxWooga
 
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018Codemotion
 
Apache Spark Structured Streaming + Apache Kafka = ♡
Apache Spark Structured Streaming + Apache Kafka = ♡Apache Spark Structured Streaming + Apache Kafka = ♡
Apache Spark Structured Streaming + Apache Kafka = ♡Bartosz Konieczny
 
Elk with Openstack
Elk with OpenstackElk with Openstack
Elk with OpenstackArun prasath
 
glance replicator
glance replicatorglance replicator
glance replicatoririx_jp
 
2015 05 27 JSConf - concurrency and parallelism final
2015 05 27   JSConf - concurrency and parallelism final2015 05 27   JSConf - concurrency and parallelism final
2015 05 27 JSConf - concurrency and parallelism finalNaveed Ihsanullah
 

Was ist angesagt? (20)

Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012
 
What's new in Ansible 2.0
What's new in Ansible 2.0What's new in Ansible 2.0
What's new in Ansible 2.0
 
Lambda Jam 2015: Event Processing in Clojure
Lambda Jam 2015: Event Processing in ClojureLambda Jam 2015: Event Processing in Clojure
Lambda Jam 2015: Event Processing in Clojure
 
Redis as a message queue
Redis as a message queueRedis as a message queue
Redis as a message queue
 
Hopping in clouds: a tale of migration from one cloud provider to another
Hopping in clouds: a tale of migration from one cloud provider to anotherHopping in clouds: a tale of migration from one cloud provider to another
Hopping in clouds: a tale of migration from one cloud provider to another
 
Lightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMRLightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMR
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
 
Winform
WinformWinform
Winform
 
Application Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.keyApplication Logging in the 21st century - 2014.key
Application Logging in the 21st century - 2014.key
 
Using ngx_lua in UPYUN 2
Using ngx_lua in UPYUN 2Using ngx_lua in UPYUN 2
Using ngx_lua in UPYUN 2
 
MySQL Audit using Percona audit plugin and ELK
MySQL Audit using Percona audit plugin and ELKMySQL Audit using Percona audit plugin and ELK
MySQL Audit using Percona audit plugin and ELK
 
Using Cerberus and PySpark to validate semi-structured datasets
Using Cerberus and PySpark to validate semi-structured datasetsUsing Cerberus and PySpark to validate semi-structured datasets
Using Cerberus and PySpark to validate semi-structured datasets
 
More than syntax
More than syntaxMore than syntax
More than syntax
 
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
 
Apache Spark Structured Streaming + Apache Kafka = ♡
Apache Spark Structured Streaming + Apache Kafka = ♡Apache Spark Structured Streaming + Apache Kafka = ♡
Apache Spark Structured Streaming + Apache Kafka = ♡
 
Elk with Openstack
Elk with OpenstackElk with Openstack
Elk with Openstack
 
glance replicator
glance replicatorglance replicator
glance replicator
 
Unqlite
UnqliteUnqlite
Unqlite
 
2015 05 27 JSConf - concurrency and parallelism final
2015 05 27   JSConf - concurrency and parallelism final2015 05 27   JSConf - concurrency and parallelism final
2015 05 27 JSConf - concurrency and parallelism final
 

Ähnlich wie Paris Kafka Meetup - How to develop with Kafka

Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraDeependra Ariyadewa
 
Leveraging Azure Databricks to minimize time to insight by combining Batch an...
Leveraging Azure Databricks to minimize time to insight by combining Batch an...Leveraging Azure Databricks to minimize time to insight by combining Batch an...
Leveraging Azure Databricks to minimize time to insight by combining Batch an...Microsoft Tech Community
 
Hazelcast
HazelcastHazelcast
Hazelcastoztalip
 
Getting Started with Couchbase Ruby
Getting Started with Couchbase RubyGetting Started with Couchbase Ruby
Getting Started with Couchbase RubySergey Avseyev
 
I can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and SpringI can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and SpringJoe Kutner
 
Secure .NET programming
Secure .NET programmingSecure .NET programming
Secure .NET programmingAnte Gulam
 
Kafka Streams: the easiest way to start with stream processing
Kafka Streams: the easiest way to start with stream processingKafka Streams: the easiest way to start with stream processing
Kafka Streams: the easiest way to start with stream processingYaroslav Tkachenko
 
The Wonderful World of Apache Kafka®
The Wonderful World of Apache Kafka®The Wonderful World of Apache Kafka®
The Wonderful World of Apache Kafka®confluent
 
Designing a Scalable Data Platform
Designing a Scalable Data PlatformDesigning a Scalable Data Platform
Designing a Scalable Data PlatformAlex Silva
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to NodejsGabriele Lana
 
Flux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul DixFlux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul DixInfluxData
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksMongoDB
 
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...confluent
 
Functional streams with Kafka - A comparison between Akka-streams and FS2
Functional streams with Kafka - A comparison between Akka-streams and FS2Functional streams with Kafka - A comparison between Akka-streams and FS2
Functional streams with Kafka - A comparison between Akka-streams and FS2Luis Miguel Reis
 
Hadoop Integration in Cassandra
Hadoop Integration in CassandraHadoop Integration in Cassandra
Hadoop Integration in CassandraJairam Chandar
 
Streaming twitter data using kafka
Streaming twitter data using kafkaStreaming twitter data using kafka
Streaming twitter data using kafkaKiran Krishna
 
Artimon - Apache Flume (incubating) NYC Meetup 20111108
Artimon - Apache Flume (incubating) NYC Meetup 20111108Artimon - Apache Flume (incubating) NYC Meetup 20111108
Artimon - Apache Flume (incubating) NYC Meetup 20111108Mathias Herberts
 
Testing Kafka - The Developer Perspective
Testing Kafka - The Developer PerspectiveTesting Kafka - The Developer Perspective
Testing Kafka - The Developer Perspectivemaiktoepfer
 
Setup 3 Node Kafka Cluster on AWS - Hands On
Setup 3 Node Kafka Cluster on AWS - Hands OnSetup 3 Node Kafka Cluster on AWS - Hands On
Setup 3 Node Kafka Cluster on AWS - Hands Onhkbhadraa
 

Ähnlich wie Paris Kafka Meetup - How to develop with Kafka (20)

Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and Cassandra
 
Leveraging Azure Databricks to minimize time to insight by combining Batch an...
Leveraging Azure Databricks to minimize time to insight by combining Batch an...Leveraging Azure Databricks to minimize time to insight by combining Batch an...
Leveraging Azure Databricks to minimize time to insight by combining Batch an...
 
Hazelcast
HazelcastHazelcast
Hazelcast
 
Getting Started with Couchbase Ruby
Getting Started with Couchbase RubyGetting Started with Couchbase Ruby
Getting Started with Couchbase Ruby
 
I can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and SpringI can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and Spring
 
Secure .NET programming
Secure .NET programmingSecure .NET programming
Secure .NET programming
 
Kafka Streams: the easiest way to start with stream processing
Kafka Streams: the easiest way to start with stream processingKafka Streams: the easiest way to start with stream processing
Kafka Streams: the easiest way to start with stream processing
 
The Wonderful World of Apache Kafka®
The Wonderful World of Apache Kafka®The Wonderful World of Apache Kafka®
The Wonderful World of Apache Kafka®
 
Designing a Scalable Data Platform
Designing a Scalable Data PlatformDesigning a Scalable Data Platform
Designing a Scalable Data Platform
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
Flux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul DixFlux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul Dix
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
 
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
 
Functional streams with Kafka - A comparison between Akka-streams and FS2
Functional streams with Kafka - A comparison between Akka-streams and FS2Functional streams with Kafka - A comparison between Akka-streams and FS2
Functional streams with Kafka - A comparison between Akka-streams and FS2
 
Apache Cassandra and Go
Apache Cassandra and GoApache Cassandra and Go
Apache Cassandra and Go
 
Hadoop Integration in Cassandra
Hadoop Integration in CassandraHadoop Integration in Cassandra
Hadoop Integration in Cassandra
 
Streaming twitter data using kafka
Streaming twitter data using kafkaStreaming twitter data using kafka
Streaming twitter data using kafka
 
Artimon - Apache Flume (incubating) NYC Meetup 20111108
Artimon - Apache Flume (incubating) NYC Meetup 20111108Artimon - Apache Flume (incubating) NYC Meetup 20111108
Artimon - Apache Flume (incubating) NYC Meetup 20111108
 
Testing Kafka - The Developer Perspective
Testing Kafka - The Developer PerspectiveTesting Kafka - The Developer Perspective
Testing Kafka - The Developer Perspective
 
Setup 3 Node Kafka Cluster on AWS - Hands On
Setup 3 Node Kafka Cluster on AWS - Hands OnSetup 3 Node Kafka Cluster on AWS - Hands On
Setup 3 Node Kafka Cluster on AWS - Hands On
 

Kürzlich hochgeladen

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 

Kürzlich hochgeladen (20)

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 

Paris Kafka Meetup - How to develop with Kafka

  • 1. Paris Apache Kafka Meetup Florian HUSSONNOIS Zenika @fhussonnois
  • 2. Async, Sync, Batch, Partitioner et Retries
  • 3. Properties config = new Properties(); config.put("bootstrap.servers", "localhost:9092"); KafkaProducer<String, String> producer = new KafkaProducer(config); ProducerRecord record = new ProducerRecord("my_topic", "my_key", "my_value"); producer.send(record); producer.close();
  • 4. L’appel à la méthode send()est asynchrone et retourne immédiatement Le message est ajouté à un buffer avant d’être envoyé //... config.put("batch.size", 16384); config.put("linger.ms", 1); //... Latence entre chaque transmission de messages Taille maximum d’un batch
  • 5. List<ProducerRecord> batchRecords = new ArrayList<>(); //... for(ProducerRecord record : batchRecords) producer.send(record); producer.flush(); producer.close(); Force l’envoi des messages et bloque jusqu’à leur complétion
  • 6. Future<RecordMetadata> future = producer.send(record); RecordMetadata metadata = future.get(); // BLOCK LOG.info("message sent to topic {}, partition {}, offset {}", metadata.topic(), metadata.partition(), metadata.offset());
  • 7. ProducerRecord record = new ProducerRecord("my_topic", "my_key", "my_value"); Future<RecordMetadata> future = producer.send(record, (metadata, e) -> { if(e != null) LOG.info("Message sent to topic {}, partition {}, offset {}", metadata.topic(), metadata.partition(), metadata.offset()); else LOG.error("Damn it!", e); });
  • 8. Configuration config.put("partitioner.class", DefaultPartitioner.class.getName() Implémenter un Partitioner public interface Partitioner { int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster); } Spécifier directement la partition cible new ProducerRecord("my_topic", 0, "my_key", "my_value");
  • 9. Acknowledgments config.put("ack", "all "); // plus lent, messages répliqués par tous les ISR Le Producer peut rejouer automatiquement les messages en erreurs config.put("retries", "0 "); // désactivé /! Peut provoquer des doublons (At-Least Once) /! Peut changer l’ordre de publication des messages
  • 10. Event Loop, Polling Model, Offset et Group Management
  • 11. Properties config = new Properties(); config.put("bootstrap.servers", "localhost:9092"); KafkaConsumer<Object, Object> consumer = new KafkaConsumer<>(config); consumer.subscribe(Arrays.asList("topic1, topic2")); while(true) { ConsumerRecords<Object, Object> records = consumer.poll(1000); records.forEach(record -> LOG.info("key={}, value={}", record.key(), record.value())); } Event Loop, Polling Model
  • 12. Properties config = new Properties(); config.put("bootstrap.servers", "localhost:9092"); config.put("enable.auto.commit", false); // désactive auto-commit config.put("auto.commit.interval.ms", 100); KafkaConsumer<Object, Object> consumer = new KafkaConsumer<>(config); consumer.subscribe(Arrays.asList("topic1, topic2")); while(true) { ConsumerRecords<Object, Object> records = consumer.poll(1000); records.forEach(record -> LOG.info("key={}, value={}", record.key(), record.value())); consumer.commitAsync(); } }
  • 13. while(true) { ConsumerRecords<Object, Object> records = consumer.poll(1000); consumer.commitSync(); // Commit offsets before processing messages. records.forEach(record -> LOG.info("key={}, value={}", record.key(), record.value())); }
  • 14.
  • 15. Properties config = new Properties(); config.put("bootstrap.servers", "localhost:9092"); config.put("group.id", "my_group"); KafkaConsumer<Object, Object> consumer = new KafkaConsumer<>(config); consumer.subscribe(Arrays.asList("topic1, topic2"));
  • 16. KafkaConsumer<Object, Object> consumer = new KafkaConsumer<>(config); consumer.subscribe(Arrays.asList("topic1, topic2"), new ConsumerRebalanceListener() { @Override public void onPartitionsRevoked(Collection<TopicPartition> partitions) { //do some stuff } @Override public void onPartitionsAssigned(Collection<TopicPartition> partitions) { //do some stuff } });
  • 17. Chaque consumer d’un groupe doit notifier le coordinateur Uniquement possible sur un appel aux méthodes poll, commit, etc. Déclenché si un consumer rejoint ou quitte un groupe L’opération de « rebalance » est impactée par les paramètres : • session.timeout.ms (30 secondes) • heartbeat.interval.ms Rebalance intempestif en cas de traitement d’un message trop long
  • 18. ConsumerRecords<Object, Object> records = consumer.poll(1000); if( ! records.isEmpty() ) { consumer.pause(consumer.assignment().toArray(new TopicPartition[0])); Future<Boolean> future = executorService.submit(() -> { records.forEach(record -> LOG.info("key={}, value={}", record.key(), record.value())); return true; }); Boolean isCompleted = false; while(!isCompleted) { try { isCompleted = future.get(5, TimeUnit.SECONDS); // Wait before polling } catch (TimeoutException e) { consumer.poll(0); // heart-beat } catch (CancellationException |ExecutionException | InterruptedException e) { break; } } consumer.resume(consumer.assignment().toArray(new TopicPartition[0])); consumer.commitSync(); } ExecutorService
  • 19. Se positionner à un offset spécifique consumer.seek(new TopicPartition("my_topic", 0), 42); consumer.seekToEnd(new TopicPartition("my_topic", 0)); consumer.seekToBeginning(new TopicPartition("my_topic", 0)); Assignements manuel consumer.assign(Arrays.asList(new TopicPartition("my_topic", 0))); Obtenir les métriques consumer.metrics();
  • 20. Nous recrutons ! jobs@zenika.com @ZenikaIT Prochain Meetup le