SlideShare a Scribd company logo
Edgar Domingues
October 2021
Kafka Client and Emitters
01
02
03
04
Agenda
Apache Kafka
Kafka vs. Message Broker
Quarkus Extension for Apache Kafka
Testing a Kafka application
2
Apache Kafka
Open-source distributed event streaming platform
“event streaming is the practice of
• capturing data in real-time from event sources (like databases, sensors, mobile
devices, cloud services, and software applications) in the form of streams of
events;
• storing these event streams durably for later retrieval;
• manipulating, processing, and reacting to the event streams in real-time as well
as retrospectively; and
• routing the event streams to different destination technologies as needed.”
-- https://kafka.apache.org/documentation/
3
4
https://miro.medium.com/max/3720/1*5DMYoWniIyN7YRoJof4K_w.png
Topics & Partitions
5
https://linuxhint.com/wp-content/uploads/2018/10/1-31.png
Partitioner
Producer will decide target partition to place any message, depending on:
1. Partition id, if it's specified within the message
2. key % num partitions, if no partition id is mentioned
3. Round robin if neither partition id nor message key are available in message,
meaning only value is available
6
Consumer Groups
7
https://betterprogramming.pub/rabbitmq-vs-kafka-1ef22a041793
Kafka vs. Message Broker
Kafka
8
• Dumb-Broker and Smart-Consumer
• Pull
• Topics/Partitions/Groups
• Connectors
• Stronger guarantees of messages
ordering
• Persisted events
Message Broker (e.g. RabbitMQ
• Smart-Broker and Dumb-Consumer
• Push
• Queues/Exchanges/Routing
• Superior support when it comes to
routing and filtering messages for
consumers to use.
• Message Time-To-Live and
delayed/scheduled messages
• Delivery retries and dead-letter
exchanges/queues
9
Quarkus Extension for Apache Kafka
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-reactive-messaging-kafka</artifactId>
</dependency>
10
Disable kafka health check
# Keep kafka health disabled to avoid leaking the address of the kafka instances
quarkus.kafka.health.enabled=false
11
Receiving messages from kafka
@Incoming("accounts")
@Blocking
public void consumeAccountEvent(final JsonObject json) {
// handle event
}
12
Configuring Receiver
#kafka.bootstrap.servers # from environment
mp.messaging.incoming.accounts.connector=smallrye-kafka
mp.messaging.incoming.accounts.topic=event-splitter.accounts
mp.messaging.incoming.accounts.value.deserializer=io.vertx.kafka.client.serialization.JsonObjectDeserializer
mp.messaging.incoming.accounts.group.id=wfm-mercury-accounts
mp.messaging.incoming.accounts.auto.offset.reset=earliest
mp.messaging.incoming.accounts.security.protocol=SASL_SSL
mp.messaging.incoming.accounts.sasl.mechanism=SCRAM-SHA-512
mp.messaging.incoming.accounts.sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule
required username=${kafka.username} password="${kafka.password}";
mp.messaging.incoming.accounts.ssl.truststore.location=${kafka.truststore.location}
mp.messaging.incoming.accounts.ssl.truststore.password=${kafka.truststore.password}
13
Sending messages to kafka
@Inject
@Channel("timeseries-data-reporting")
@OnOverflow(value = OnOverflow.Strategy.UNBOUNDED_BUFFER)
Emitter<TimeSeriesReportEvent> emitter;
void publish(final TimeSeriesReportEvent event) {
// emitter.send(event);
String key = event.getAccountId() + "-" + event.getQueueId();
emitter.send(KafkaRecord.of(key, event));
}
14
Configuring Emitter
#kafka.bootstrap.servers # from environment
mp.messaging.outgoing.timeseries-data-reporting.connector=smallrye-kafka
mp.messaging.outgoing.timeseries-data-reporting.topic=wfm-timeseries.timeseries-data-reporting
mp.messaging.outgoing.timeseries-data-reporting.value.serializer=io.quarkus.kafka.client.serialization.JsonbSerializer
mp.messaging.outgoing.timeseries-data-reporting.security.protocol=SASL_SSL
mp.messaging.outgoing.timeseries-data-reporting.sasl.mechanism=SCRAM-SHA-512
mp.messaging.outgoing.timeseries-data-reporting.sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule
required username=${kafka.username} password="${kafka.password}";
mp.messaging.outgoing.timeseries-data-reporting.ssl.truststore.location=${kafka.truststore.location}
mp.messaging.outgoing.timeseries-data-reporting.ssl.truststore.password=${kafka.truststore.password}
mp.messaging.outgoing.timeseries-data-reporting.compression.type=zstd
Overflow management
// Set the max size to 10 and fail if reached
@OnOverflow(value = OnOverflow.Strategy.BUFFER, bufferSize = 10)
@Inject @Channel("channel") Emitter<String> emitterWithBuffer;
// [DANGER ZONE] no limit
@OnOverflow(OnOverflow.Strategy.UNBOUNDED_BUFFER)
@Inject @Channel("channel") Emitter<String> danger;
// Drop the new messages if the size is reached
@OnOverflow(OnOverflow.Strategy.DROP)
@Inject @Channel("channel") Emitter<String> dropping;
// Drop the previously sent messages if the size is reached
@OnOverflow(OnOverflow.Strategy.LATEST)
@Inject @Channel("channel") Emitter<String> dropOldMessages;
https://smallrye.io/smallrye-reactive-messaging/smallrye-reactive-messaging/3.2/emitter/emitter.html#emitter-overflow
16
Testing a Kafka application
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-reactive-messaging-in-memory</artifactId>
<scope>test</scope>
</dependency>
17
Kafka Test Resource Lifecycle Manager
public class KafkaTestResourceLifecycleManager implements QuarkusTestResourceLifecycleManager {
@Override
public Map<String, String> start() {
return InMemoryConnector.switchIncomingChannelsToInMemory("accounts");
}
@Override
public void stop() {
InMemoryConnector.clear();
}
}
18
Test class
@QuarkusTest
@QuarkusTestResource(KafkaTestResourceLifecycleManager.class)
class KafkaListenerIT {
@Inject
@Any
InMemoryConnector connector;
19
Test receiving messages from kafka
@Test
void handleAccountEvent() {
// Arrange
InMemorySource<JsonObject> emitter = connector.source("accounts");
// Act
emitter.send(...);
// Assert
// assert event handled as expected…
20
Test sending messages to Kafka
@Test
public void sendTimeSeriesReportEvent() {
// Arrange
InMemorySink<TimeSeriesReportEvent> events = connector.sink("timeseries-data-reporting");
//...
// Act
service.publish(event);
// Assert
assertThat(events.received().size(), is(1));
// assert event key and payload as expected...
}
Questions?
21
22
23
https://betterprogramming.pub/rabbitmq-vs-kafka-1ef22a041793

More Related Content

What's hot

Kafka presentation
Kafka presentationKafka presentation
Kafka presentation
Mohammed Fazuluddin
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
Kumar Shivam
 
ksqlDB: A Stream-Relational Database System
ksqlDB: A Stream-Relational Database SystemksqlDB: A Stream-Relational Database System
ksqlDB: A Stream-Relational Database System
confluent
 
Apache Kafka® and API Management
Apache Kafka® and API ManagementApache Kafka® and API Management
Apache Kafka® and API Management
confluent
 
Kafka Tutorial - DevOps, Admin and Ops
Kafka Tutorial - DevOps, Admin and OpsKafka Tutorial - DevOps, Admin and Ops
Kafka Tutorial - DevOps, Admin and Ops
Jean-Paul Azar
 
3 Kafka patterns to deliver Streaming Machine Learning models with Andrea Spi...
3 Kafka patterns to deliver Streaming Machine Learning models with Andrea Spi...3 Kafka patterns to deliver Streaming Machine Learning models with Andrea Spi...
3 Kafka patterns to deliver Streaming Machine Learning models with Andrea Spi...
HostedbyConfluent
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
AIMDek Technologies
 
Kafka 101
Kafka 101Kafka 101
Kafka 101
Clement Demonchy
 
Apache kafka performance(latency)_benchmark_v0.3
Apache kafka performance(latency)_benchmark_v0.3Apache kafka performance(latency)_benchmark_v0.3
Apache kafka performance(latency)_benchmark_v0.3
SANG WON PARK
 
Apache Kafka - Martin Podval
Apache Kafka - Martin PodvalApache Kafka - Martin Podval
Apache Kafka - Martin Podval
Martin Podval
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
Jeff Holoman
 
Messaging queue - Kafka
Messaging queue - KafkaMessaging queue - Kafka
Messaging queue - Kafka
Mayank Bansal
 
Apache Pulsar Development 101 with Python
Apache Pulsar Development 101 with PythonApache Pulsar Development 101 with Python
Apache Pulsar Development 101 with Python
Timothy Spann
 
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
SANG WON PARK
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
Viswanath J
 
Introduction to Kafka connect
Introduction to Kafka connectIntroduction to Kafka connect
Introduction to Kafka connect
Knoldus Inc.
 
IBM WebSphere MQ: Managing Workloads, Scaling and Availability with MQ Clusters
IBM WebSphere MQ: Managing Workloads, Scaling and Availability with MQ ClustersIBM WebSphere MQ: Managing Workloads, Scaling and Availability with MQ Clusters
IBM WebSphere MQ: Managing Workloads, Scaling and Availability with MQ Clusters
David Ware
 
Spring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise PlatformSpring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise Platform
VMware Tanzu
 
From Zero to Hero with Kafka Connect
From Zero to Hero with Kafka ConnectFrom Zero to Hero with Kafka Connect
From Zero to Hero with Kafka Connect
confluent
 
Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?
confluent
 

What's hot (20)

Kafka presentation
Kafka presentationKafka presentation
Kafka presentation
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
ksqlDB: A Stream-Relational Database System
ksqlDB: A Stream-Relational Database SystemksqlDB: A Stream-Relational Database System
ksqlDB: A Stream-Relational Database System
 
Apache Kafka® and API Management
Apache Kafka® and API ManagementApache Kafka® and API Management
Apache Kafka® and API Management
 
Kafka Tutorial - DevOps, Admin and Ops
Kafka Tutorial - DevOps, Admin and OpsKafka Tutorial - DevOps, Admin and Ops
Kafka Tutorial - DevOps, Admin and Ops
 
3 Kafka patterns to deliver Streaming Machine Learning models with Andrea Spi...
3 Kafka patterns to deliver Streaming Machine Learning models with Andrea Spi...3 Kafka patterns to deliver Streaming Machine Learning models with Andrea Spi...
3 Kafka patterns to deliver Streaming Machine Learning models with Andrea Spi...
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
 
Kafka 101
Kafka 101Kafka 101
Kafka 101
 
Apache kafka performance(latency)_benchmark_v0.3
Apache kafka performance(latency)_benchmark_v0.3Apache kafka performance(latency)_benchmark_v0.3
Apache kafka performance(latency)_benchmark_v0.3
 
Apache Kafka - Martin Podval
Apache Kafka - Martin PodvalApache Kafka - Martin Podval
Apache Kafka - Martin Podval
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
 
Messaging queue - Kafka
Messaging queue - KafkaMessaging queue - Kafka
Messaging queue - Kafka
 
Apache Pulsar Development 101 with Python
Apache Pulsar Development 101 with PythonApache Pulsar Development 101 with Python
Apache Pulsar Development 101 with Python
 
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
Introduction to Kafka connect
Introduction to Kafka connectIntroduction to Kafka connect
Introduction to Kafka connect
 
IBM WebSphere MQ: Managing Workloads, Scaling and Availability with MQ Clusters
IBM WebSphere MQ: Managing Workloads, Scaling and Availability with MQ ClustersIBM WebSphere MQ: Managing Workloads, Scaling and Availability with MQ Clusters
IBM WebSphere MQ: Managing Workloads, Scaling and Availability with MQ Clusters
 
Spring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise PlatformSpring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise Platform
 
From Zero to Hero with Kafka Connect
From Zero to Hero with Kafka ConnectFrom Zero to Hero with Kafka Connect
From Zero to Hero with Kafka Connect
 
Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?
 

Similar to Kafka clients and emitters

Writing Blazing Fast, and Production-Ready Kafka Streams apps in less than 30...
Writing Blazing Fast, and Production-Ready Kafka Streams apps in less than 30...Writing Blazing Fast, and Production-Ready Kafka Streams apps in less than 30...
Writing Blazing Fast, and Production-Ready Kafka Streams apps in less than 30...
HostedbyConfluent
 
Training
TrainingTraining
Training
HemantDunga1
 
Kafka Connect & Kafka Streams/KSQL - the ecosystem around Kafka
Kafka Connect & Kafka Streams/KSQL - the ecosystem around KafkaKafka Connect & Kafka Streams/KSQL - the ecosystem around Kafka
Kafka Connect & Kafka Streams/KSQL - the ecosystem around Kafka
Guido Schmutz
 
Productionalizing spark streaming applications
Productionalizing spark streaming applicationsProductionalizing spark streaming applications
Productionalizing spark streaming applications
Robert Sanders
 
Monitoring and Resiliency Testing our Apache Kafka Clusters at Goldman Sachs ...
Monitoring and Resiliency Testing our Apache Kafka Clusters at Goldman Sachs ...Monitoring and Resiliency Testing our Apache Kafka Clusters at Goldman Sachs ...
Monitoring and Resiliency Testing our Apache Kafka Clusters at Goldman Sachs ...
HostedbyConfluent
 
Apache kafka configuration-guide
Apache kafka configuration-guideApache kafka configuration-guide
Apache kafka configuration-guide
Chetan Khatri
 
Kafka On YARN (KOYA): An Open Source Initiative to integrate Kafka & YARN
Kafka On YARN (KOYA): An Open Source Initiative to integrate Kafka & YARNKafka On YARN (KOYA): An Open Source Initiative to integrate Kafka & YARN
Kafka On YARN (KOYA): An Open Source Initiative to integrate Kafka & YARN
DataWorks Summit
 
Event streaming webinar feb 2020
Event streaming webinar feb 2020Event streaming webinar feb 2020
Event streaming webinar feb 2020
Maheedhar Gunturu
 
Building a Real-time Streaming ETL Framework Using ksqlDB and NoSQL
Building a Real-time Streaming ETL Framework Using ksqlDB and NoSQLBuilding a Real-time Streaming ETL Framework Using ksqlDB and NoSQL
Building a Real-time Streaming ETL Framework Using ksqlDB and NoSQL
ScyllaDB
 
Sparkstreaming
SparkstreamingSparkstreaming
Sparkstreaming
Marilyn Waldman
 
Spark Streaming Info
Spark Streaming InfoSpark Streaming Info
Spark Streaming InfoDoug Chang
 
Reactive messaging Quarkus and Kafka
Reactive messaging Quarkus and KafkaReactive messaging Quarkus and Kafka
Reactive messaging Quarkus and Kafka
Bruno Horta
 
Devoxx Morocco 2016 - Microservices with Kafka
Devoxx Morocco 2016 - Microservices with KafkaDevoxx Morocco 2016 - Microservices with Kafka
Devoxx Morocco 2016 - Microservices with Kafka
László-Róbert Albert
 
Apache Kafka - Scalable Message Processing and more!
Apache Kafka - Scalable Message Processing and more!Apache Kafka - Scalable Message Processing and more!
Apache Kafka - Scalable Message Processing and more!
Guido Schmutz
 
Introduction to Apache Kafka and Confluent... and why they matter
Introduction to Apache Kafka and Confluent... and why they matterIntroduction to Apache Kafka and Confluent... and why they matter
Introduction to Apache Kafka and Confluent... and why they matter
confluent
 
Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !
Guido Schmutz
 
Introduction to Apache Kafka and Confluent... and why they matter!
Introduction to Apache Kafka and Confluent... and why they matter!Introduction to Apache Kafka and Confluent... and why they matter!
Introduction to Apache Kafka and Confluent... and why they matter!
Paolo Castagna
 
Changing landscapes in data integration - Kafka Connect for near real-time da...
Changing landscapes in data integration - Kafka Connect for near real-time da...Changing landscapes in data integration - Kafka Connect for near real-time da...
Changing landscapes in data integration - Kafka Connect for near real-time da...
HostedbyConfluent
 
Implementing Domain Events with Kafka
Implementing Domain Events with KafkaImplementing Domain Events with Kafka
Implementing Domain Events with Kafka
Andrei Rugina
 

Similar to Kafka clients and emitters (20)

Writing Blazing Fast, and Production-Ready Kafka Streams apps in less than 30...
Writing Blazing Fast, and Production-Ready Kafka Streams apps in less than 30...Writing Blazing Fast, and Production-Ready Kafka Streams apps in less than 30...
Writing Blazing Fast, and Production-Ready Kafka Streams apps in less than 30...
 
Training
TrainingTraining
Training
 
Kafka Connect & Kafka Streams/KSQL - the ecosystem around Kafka
Kafka Connect & Kafka Streams/KSQL - the ecosystem around KafkaKafka Connect & Kafka Streams/KSQL - the ecosystem around Kafka
Kafka Connect & Kafka Streams/KSQL - the ecosystem around Kafka
 
Productionalizing spark streaming applications
Productionalizing spark streaming applicationsProductionalizing spark streaming applications
Productionalizing spark streaming applications
 
Monitoring and Resiliency Testing our Apache Kafka Clusters at Goldman Sachs ...
Monitoring and Resiliency Testing our Apache Kafka Clusters at Goldman Sachs ...Monitoring and Resiliency Testing our Apache Kafka Clusters at Goldman Sachs ...
Monitoring and Resiliency Testing our Apache Kafka Clusters at Goldman Sachs ...
 
Apache kafka configuration-guide
Apache kafka configuration-guideApache kafka configuration-guide
Apache kafka configuration-guide
 
Kafka On YARN (KOYA): An Open Source Initiative to integrate Kafka & YARN
Kafka On YARN (KOYA): An Open Source Initiative to integrate Kafka & YARNKafka On YARN (KOYA): An Open Source Initiative to integrate Kafka & YARN
Kafka On YARN (KOYA): An Open Source Initiative to integrate Kafka & YARN
 
Event streaming webinar feb 2020
Event streaming webinar feb 2020Event streaming webinar feb 2020
Event streaming webinar feb 2020
 
Building a Real-time Streaming ETL Framework Using ksqlDB and NoSQL
Building a Real-time Streaming ETL Framework Using ksqlDB and NoSQLBuilding a Real-time Streaming ETL Framework Using ksqlDB and NoSQL
Building a Real-time Streaming ETL Framework Using ksqlDB and NoSQL
 
Sparkstreaming
SparkstreamingSparkstreaming
Sparkstreaming
 
Spark Streaming Info
Spark Streaming InfoSpark Streaming Info
Spark Streaming Info
 
Reactive messaging Quarkus and Kafka
Reactive messaging Quarkus and KafkaReactive messaging Quarkus and Kafka
Reactive messaging Quarkus and Kafka
 
Devoxx Morocco 2016 - Microservices with Kafka
Devoxx Morocco 2016 - Microservices with KafkaDevoxx Morocco 2016 - Microservices with Kafka
Devoxx Morocco 2016 - Microservices with Kafka
 
Apache Kafka - Scalable Message Processing and more!
Apache Kafka - Scalable Message Processing and more!Apache Kafka - Scalable Message Processing and more!
Apache Kafka - Scalable Message Processing and more!
 
Introduction to Apache Kafka and Confluent... and why they matter
Introduction to Apache Kafka and Confluent... and why they matterIntroduction to Apache Kafka and Confluent... and why they matter
Introduction to Apache Kafka and Confluent... and why they matter
 
Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !
 
Introduction to Apache Kafka and Confluent... and why they matter!
Introduction to Apache Kafka and Confluent... and why they matter!Introduction to Apache Kafka and Confluent... and why they matter!
Introduction to Apache Kafka and Confluent... and why they matter!
 
KAFKA Quickstart
KAFKA QuickstartKAFKA Quickstart
KAFKA Quickstart
 
Changing landscapes in data integration - Kafka Connect for near real-time da...
Changing landscapes in data integration - Kafka Connect for near real-time da...Changing landscapes in data integration - Kafka Connect for near real-time da...
Changing landscapes in data integration - Kafka Connect for near real-time da...
 
Implementing Domain Events with Kafka
Implementing Domain Events with KafkaImplementing Domain Events with Kafka
Implementing Domain Events with Kafka
 

Recently uploaded

SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 

Recently uploaded (20)

SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 

Kafka clients and emitters

  • 2. 01 02 03 04 Agenda Apache Kafka Kafka vs. Message Broker Quarkus Extension for Apache Kafka Testing a Kafka application 2
  • 3. Apache Kafka Open-source distributed event streaming platform “event streaming is the practice of • capturing data in real-time from event sources (like databases, sensors, mobile devices, cloud services, and software applications) in the form of streams of events; • storing these event streams durably for later retrieval; • manipulating, processing, and reacting to the event streams in real-time as well as retrospectively; and • routing the event streams to different destination technologies as needed.” -- https://kafka.apache.org/documentation/ 3
  • 6. Partitioner Producer will decide target partition to place any message, depending on: 1. Partition id, if it's specified within the message 2. key % num partitions, if no partition id is mentioned 3. Round robin if neither partition id nor message key are available in message, meaning only value is available 6
  • 8. Kafka vs. Message Broker Kafka 8 • Dumb-Broker and Smart-Consumer • Pull • Topics/Partitions/Groups • Connectors • Stronger guarantees of messages ordering • Persisted events Message Broker (e.g. RabbitMQ • Smart-Broker and Dumb-Consumer • Push • Queues/Exchanges/Routing • Superior support when it comes to routing and filtering messages for consumers to use. • Message Time-To-Live and delayed/scheduled messages • Delivery retries and dead-letter exchanges/queues
  • 9. 9 Quarkus Extension for Apache Kafka <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-smallrye-reactive-messaging-kafka</artifactId> </dependency>
  • 10. 10 Disable kafka health check # Keep kafka health disabled to avoid leaking the address of the kafka instances quarkus.kafka.health.enabled=false
  • 11. 11 Receiving messages from kafka @Incoming("accounts") @Blocking public void consumeAccountEvent(final JsonObject json) { // handle event }
  • 12. 12 Configuring Receiver #kafka.bootstrap.servers # from environment mp.messaging.incoming.accounts.connector=smallrye-kafka mp.messaging.incoming.accounts.topic=event-splitter.accounts mp.messaging.incoming.accounts.value.deserializer=io.vertx.kafka.client.serialization.JsonObjectDeserializer mp.messaging.incoming.accounts.group.id=wfm-mercury-accounts mp.messaging.incoming.accounts.auto.offset.reset=earliest mp.messaging.incoming.accounts.security.protocol=SASL_SSL mp.messaging.incoming.accounts.sasl.mechanism=SCRAM-SHA-512 mp.messaging.incoming.accounts.sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username=${kafka.username} password="${kafka.password}"; mp.messaging.incoming.accounts.ssl.truststore.location=${kafka.truststore.location} mp.messaging.incoming.accounts.ssl.truststore.password=${kafka.truststore.password}
  • 13. 13 Sending messages to kafka @Inject @Channel("timeseries-data-reporting") @OnOverflow(value = OnOverflow.Strategy.UNBOUNDED_BUFFER) Emitter<TimeSeriesReportEvent> emitter; void publish(final TimeSeriesReportEvent event) { // emitter.send(event); String key = event.getAccountId() + "-" + event.getQueueId(); emitter.send(KafkaRecord.of(key, event)); }
  • 14. 14 Configuring Emitter #kafka.bootstrap.servers # from environment mp.messaging.outgoing.timeseries-data-reporting.connector=smallrye-kafka mp.messaging.outgoing.timeseries-data-reporting.topic=wfm-timeseries.timeseries-data-reporting mp.messaging.outgoing.timeseries-data-reporting.value.serializer=io.quarkus.kafka.client.serialization.JsonbSerializer mp.messaging.outgoing.timeseries-data-reporting.security.protocol=SASL_SSL mp.messaging.outgoing.timeseries-data-reporting.sasl.mechanism=SCRAM-SHA-512 mp.messaging.outgoing.timeseries-data-reporting.sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username=${kafka.username} password="${kafka.password}"; mp.messaging.outgoing.timeseries-data-reporting.ssl.truststore.location=${kafka.truststore.location} mp.messaging.outgoing.timeseries-data-reporting.ssl.truststore.password=${kafka.truststore.password} mp.messaging.outgoing.timeseries-data-reporting.compression.type=zstd
  • 15. Overflow management // Set the max size to 10 and fail if reached @OnOverflow(value = OnOverflow.Strategy.BUFFER, bufferSize = 10) @Inject @Channel("channel") Emitter<String> emitterWithBuffer; // [DANGER ZONE] no limit @OnOverflow(OnOverflow.Strategy.UNBOUNDED_BUFFER) @Inject @Channel("channel") Emitter<String> danger; // Drop the new messages if the size is reached @OnOverflow(OnOverflow.Strategy.DROP) @Inject @Channel("channel") Emitter<String> dropping; // Drop the previously sent messages if the size is reached @OnOverflow(OnOverflow.Strategy.LATEST) @Inject @Channel("channel") Emitter<String> dropOldMessages; https://smallrye.io/smallrye-reactive-messaging/smallrye-reactive-messaging/3.2/emitter/emitter.html#emitter-overflow
  • 16. 16 Testing a Kafka application <dependency> <groupId>io.smallrye.reactive</groupId> <artifactId>smallrye-reactive-messaging-in-memory</artifactId> <scope>test</scope> </dependency>
  • 17. 17 Kafka Test Resource Lifecycle Manager public class KafkaTestResourceLifecycleManager implements QuarkusTestResourceLifecycleManager { @Override public Map<String, String> start() { return InMemoryConnector.switchIncomingChannelsToInMemory("accounts"); } @Override public void stop() { InMemoryConnector.clear(); } }
  • 19. 19 Test receiving messages from kafka @Test void handleAccountEvent() { // Arrange InMemorySource<JsonObject> emitter = connector.source("accounts"); // Act emitter.send(...); // Assert // assert event handled as expected…
  • 20. 20 Test sending messages to Kafka @Test public void sendTimeSeriesReportEvent() { // Arrange InMemorySink<TimeSeriesReportEvent> events = connector.sink("timeseries-data-reporting"); //... // Act service.publish(event); // Assert assertThat(events.received().size(), is(1)); // assert event key and payload as expected... }
  • 22. 22