SlideShare a Scribd company logo
Pulsar For Kafka People
1 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Introducing Pulsar
Architectures
API and Programming Differences
Use Cases
Pulsar For Kafka People
2 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Apache Pulsar is a distributed
event streaming system
Apache Pulsar
• It uses a distributed log to
durably store messages
• Pulsar was originally created
at Yahoo
• Open sourced in 2016
• Graduated to a top-level
Apache project in 2018
3 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Kafka is a distributed publish
subscribe system
Apache Kafka
• It uses a commit log to track
changes
• Kafka was originally created
at LinkedIn
• Open sourced in 2011
• Graduated to a top-level
Apache project in 2012
4 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Introducing Pulsar
Architectures
API and Programming Differences
Use Cases
Pulsar For Kafka People
5 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Basic Kafka Architecture
Publisher SubscriberKafka
Publisher sends data and
doesn't know about the
subscribers or their status.
Subscriber recieves data from
publisher and never directly
interacts with it.
All interactions go through
Kafka and it handles all
communication.
6 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Basic Pulsar Architecture
Producer ConsumerPulsar
Producers do not directly
interact with the BookKeeper
cluster.
Consumers do not directly
interact with the BookKeeper
cluster.
All Brokers in the Pulsar
cluster are stateless and can
be scaled independently.
BookKeeper All Bookies in the BookKeeper
cluster are stateful and can
be scaled independently.
7 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Kafka Partitions
Producer 0
Data is divided into partitions.
Partitions are both logical
and physical divisions.
Producer 1
Topic
Partition 0 Partition 1 Partition 2
All data is sent and received
on topics. Topics group like
data together.
8 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Pulsar Ledgers
The individual messages that
are produced are stored as
records in the ledger.
Stream
Ledger 1 Ledger 2 Ledger 3
Record 1 Record 2 Record 3 Record 4
Each topic has it's own stream
and all data for a topic
is stored in it.
As more data is added to a
topic, new ledgers are
allocated to store the data.
9 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Kafka Consumers
Producer 0
Consumer recieves data from
all topic partitions and connects
to brokers 0, 1, and 2.
Producer 1
Broker 0 Broker 1 Broker 2
Topic
Partition 0 Partition 1 Partition 2
Consumer (P012)
10 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Pulsar Subscriptions
Producer 0
In failover, all partitions are
consumed by one consumer and
will fail over to hot spare on fail.
Producer 1
Broker 0 Broker 1 Broker 2
Topic
Partition 0 Partition 1 Partition 2
Failover Sub. (P012)
Shared Sub. (P012)
In shared, messages are
sent in a round robin way to
all consumers.
Shared Sub. (P012)
Key Shared (P012)
Key Shared (P012)
Failover Sub. (P)
In key shared, messages with
the same key are consistently
routed to the same consumer.
11 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Introducing Pulsar
Architectures
API and Programming Differences
Use Cases
Pulsar For Kafka People
12 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import static org.apache.kafka.clients.producer.ProducerConfig.*;
Properties props = new Properties();
// Configure brokers to connect to
props.put(BOOTSTRAP_SERVERS_CONFIG, "broker1:9092");
// Create a producer with the key as a string and value as a string
KafkaProducer<String, String> producer = new KafkaProducer<>(props,
new StringSerializer(), new StringSerializer());
// Create ProducerRecord and send it
String key = "mykey";
String value = "myvalue";
ProducerRecord<String, String> record = new
ProducerRecord<>("hello_topic", key, value);
producer.send(record);
producer.close();
Kafka Producer API
13 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
PulsarClient client = PulsarClient.builder()
.serviceUrl("pulsar://broker1:6650")
.build();
// Create a producer that will send values as strings
// Default is byte[]
Producer<String> producer = client
.newProducer(Schema.STRING)
.topic("hellotopic")
.create();
// Create a new message, send it, and block until it is
// acknowledged
producer.newMessage()
.key("mykey")
.value("myvalue")
.send();
// Create a new message, send it, and don't block until it is
// acknowledged
producer.newMessage()
.key("mykey2")
.value("myvalue2")
.sendAsync();
// Close producer and client
producer.close();
client.close();
Pulsar Producer API
14 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import static org.apache.kafka.clients.consumer.ConsumerConfig.*;
@SuppressWarnings("unused")
public class HelloConsumer {
KafkaConsumer<String, String> consumer;
public void createConsumer() {
String topic = "hello_topic";
Properties props = new Properties();
// Configure initial location bootstrap servers
props.put(BOOTSTRAP_SERVERS_CONFIG, "broker1:9092");
// Configure consumer group
props.put(GROUP_ID_CONFIG, "group1");
// Create the consumer with the key as a string and value as a string
consumer = new KafkaConsumer<>(props, new StringDeserializer(),
new StringDeserializer());
Kafka Consumer API (1/2)
15 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
consumer.subscribe(Arrays.asList(topic));
while (true) {
// Poll for ConsumerRecords for a certain amount of time
ConsumerRecords<String, String> records = consumer.poll(
Duration.ofMillis(100));
// Process the ConsumerRecords, if any, that came back
for (ConsumerRecord<String, String> record : records) {
String key = record.key();
String value = record.value();
// Do something with message
}
}
}
public void close() {
consumer.close();
}
public static void main(String[] args) {
HelloConsumer consumer = new HelloConsumer();
consumer.createConsumer();
consumer.close();
}
Kafka Consumer API (2/2)
16 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
client = PulsarClient.builder()
.serviceUrl("pulsar://broker1:6650")
.build();
String myTopic = "hellotopic";
String mySubscriptionName = "my-subscription";
// Create a consumer that will receive values as strings
// Default is byte[]
consumer = client.newConsumer(Schema.STRING)
.topic(myTopic)
.subscriptionName(mySubscriptionName)
.subscribe();
while (true) {
// Block and wait until a single message is available
Message<String> message = consumer.receive();
try {
// Do something with the message
System.out.println("Key is "" + message.getKey()
+ "" value is "" + message.getValue()
+ """);
// Acknowledge the message so that it can be
// deleted by the message broker
consumer.acknowledgeCumulative(message);
} catch (Exception e) {
// Message failed to process, redeliver later
consumer.negativeAcknowledge(message);
}
}
Pulsar Consumer API
17 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Both projects have an ecosystem
associated with them
Ecosystem
Projects
• Kafka Streams -> Pulsar
Functions
• KSQLDB (prop) -> Pulsar SQL
• Kafka Connect -> Pulsar IO
• Kafka API compatibility for
Pulsar
18 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Introducing Pulsar
Architectures
API and Programming Differences
Use Cases
Pulsar For Kafka People
19 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Kafka++
All Kafka use cases plus
more
20 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Work Queues
http://tiny.bdi.io/workqueues
21 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Geo-Replication
Built-in geo-replication
22 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Unified
Do both MQ-style and
Pub/Sub-style with the
same cluster
23 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Lots of Topics
Supports millions of topics
24 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
Thank You
bigdatainstitute.io
25 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9

More Related Content

PDF
Improvements in OpenStack Integration for Application Developers
PDF
Autoscale a self-healing cluster in OpenStack with Heat
PPTX
Scala API - Azure Event Hub Integration
PPTX
Azure Blob Storage API for Scala and Spark
PPTX
Azure Service Bus Queue Scala API
PPTX
Spring Cloud and Netflix Components
PPTX
Azure Service Bus Queue API for Scala
PDF
AWS IoT 핸즈온 워크샵 - 실습 6. 긴급 데이터를 Kinesis Streams으로 보내기 (김무현 솔루션즈 아키텍트)
Improvements in OpenStack Integration for Application Developers
Autoscale a self-healing cluster in OpenStack with Heat
Scala API - Azure Event Hub Integration
Azure Blob Storage API for Scala and Spark
Azure Service Bus Queue Scala API
Spring Cloud and Netflix Components
Azure Service Bus Queue API for Scala
AWS IoT 핸즈온 워크샵 - 실습 6. 긴급 데이터를 Kinesis Streams으로 보내기 (김무현 솔루션즈 아키텍트)

What's hot (17)

PDF
Microservices with Netflix OSS and Spring Cloud
PDF
Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes
PDF
Monitoring Docker Containers with Metricbeat, Elasticsearch, and Kibana
PDF
Three Degrees of Mediation: Challenges and Lessons in building Cloud-agnostic...
PDF
OpenStack 101 Technical Overview
PPTX
Building IAM for OpenStack
PPTX
How to scheduled jobs in a cloudera cluster without oozie
PPTX
Don't Wait! Develop Responsive Applications with Java EE7 Instead
PPTX
Building Microservices with Spring Cloud and Netflix OSS
PPTX
Processing messages in a sqs with lambda function
PDF
5 things you don't know about Amazon Web Services
PDF
Cloud Native Microservices with Spring Cloud
PPTX
Introduction to OpenStack Architecture (Grizzly Edition)
DOCX
Virtual private cloud fundamentals
PDF
Bt0083 server side programing
PPTX
Aws object storage and cdn(s3, glacier and cloud front) part 2
PDF
Event Sourcing on AWS Using Akka in Java
Microservices with Netflix OSS and Spring Cloud
Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes
Monitoring Docker Containers with Metricbeat, Elasticsearch, and Kibana
Three Degrees of Mediation: Challenges and Lessons in building Cloud-agnostic...
OpenStack 101 Technical Overview
Building IAM for OpenStack
How to scheduled jobs in a cloudera cluster without oozie
Don't Wait! Develop Responsive Applications with Java EE7 Instead
Building Microservices with Spring Cloud and Netflix OSS
Processing messages in a sqs with lambda function
5 things you don't know about Amazon Web Services
Cloud Native Microservices with Spring Cloud
Introduction to OpenStack Architecture (Grizzly Edition)
Virtual private cloud fundamentals
Bt0083 server side programing
Aws object storage and cdn(s3, glacier and cloud front) part 2
Event Sourcing on AWS Using Akka in Java
Ad

Similar to Pulsar for Kafka People (20)

PDF
Kafka on Pulsar
PDF
bigdata 2022_ FLiP Into Pulsar Apps
PDF
The Dream Stream Team for Pulsar and Spring
PDF
Timothy Spann: Apache Pulsar for ML
PDF
Python Web Conference 2022 - Apache Pulsar Development 101 with Python (FLiP-Py)
PDF
Princeton Dec 2022 Meetup_ StreamNative and Cloudera Streaming
PDF
October 2016 HUG: Pulsar,  a highly scalable, low latency pub-sub messaging s...
PDF
Machine Intelligence Guild_ Build ML Enhanced Event Streaming Applications wi...
PDF
Living the Stream Dream with Pulsar and Spring Boot
PDF
Preview of Apache Pulsar 2.5.0
PDF
Living the Stream Dream with Pulsar and Spring Boot
PDF
Python web conference 2022 apache pulsar development 101 with python (f li-...
PDF
Let's keep it simple and streaming.pdf
PDF
Let's keep it simple and streaming
PDF
OSS EU: Deep Dive into Building Streaming Applications with Apache Pulsar
PDF
Pulsar - flexible pub-sub for internet scale
PDF
Apache Pulsar Seattle - Meetup
PDF
Deep Dive into Building Streaming Applications with Apache Pulsar
PDF
Pulsar - Distributed pub/sub platform
PDF
Unified Messaging and Data Streaming 101
Kafka on Pulsar
bigdata 2022_ FLiP Into Pulsar Apps
The Dream Stream Team for Pulsar and Spring
Timothy Spann: Apache Pulsar for ML
Python Web Conference 2022 - Apache Pulsar Development 101 with Python (FLiP-Py)
Princeton Dec 2022 Meetup_ StreamNative and Cloudera Streaming
October 2016 HUG: Pulsar,  a highly scalable, low latency pub-sub messaging s...
Machine Intelligence Guild_ Build ML Enhanced Event Streaming Applications wi...
Living the Stream Dream with Pulsar and Spring Boot
Preview of Apache Pulsar 2.5.0
Living the Stream Dream with Pulsar and Spring Boot
Python web conference 2022 apache pulsar development 101 with python (f li-...
Let's keep it simple and streaming.pdf
Let's keep it simple and streaming
OSS EU: Deep Dive into Building Streaming Applications with Apache Pulsar
Pulsar - flexible pub-sub for internet scale
Apache Pulsar Seattle - Meetup
Deep Dive into Building Streaming Applications with Apache Pulsar
Pulsar - Distributed pub/sub platform
Unified Messaging and Data Streaming 101
Ad

More from Jesse Anderson (13)

PDF
Managing Real-Time Data Teams
PDF
Big Data and Analytics in the COVID-19 Era
PDF
Working Together As Data Teams V1
PDF
What Does an Exec Need to About Architecture and Why
PDF
The Five Dysfunctions of a Data Engineering Team
PPTX
HBaseCon 2014-Just the Basics
PPTX
Million Monkeys User Group
PPTX
Strata 2012 Million Monkeys
PPTX
EC2 Performance, Spot Instance ROI and EMR Scalability
PPT
Introduction to Regular Expressions
ODP
Why Use MVC?
ODP
How to Use MVC
PPT
Introduction to Android
Managing Real-Time Data Teams
Big Data and Analytics in the COVID-19 Era
Working Together As Data Teams V1
What Does an Exec Need to About Architecture and Why
The Five Dysfunctions of a Data Engineering Team
HBaseCon 2014-Just the Basics
Million Monkeys User Group
Strata 2012 Million Monkeys
EC2 Performance, Spot Instance ROI and EMR Scalability
Introduction to Regular Expressions
Why Use MVC?
How to Use MVC
Introduction to Android

Recently uploaded (20)

PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Modernizing your data center with Dell and AMD
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Approach and Philosophy of On baking technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
KodekX | Application Modernization Development
PDF
Electronic commerce courselecture one. Pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Empathic Computing: Creating Shared Understanding
Understanding_Digital_Forensics_Presentation.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Modernizing your data center with Dell and AMD
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Advanced methodologies resolving dimensionality complications for autism neur...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Approach and Philosophy of On baking technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Reach Out and Touch Someone: Haptics and Empathic Computing
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
KodekX | Application Modernization Development
Electronic commerce courselecture one. Pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Empathic Computing: Creating Shared Understanding

Pulsar for Kafka People

  • 1. Pulsar For Kafka People 1 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 2. Introducing Pulsar Architectures API and Programming Differences Use Cases Pulsar For Kafka People 2 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 3. Apache Pulsar is a distributed event streaming system Apache Pulsar • It uses a distributed log to durably store messages • Pulsar was originally created at Yahoo • Open sourced in 2016 • Graduated to a top-level Apache project in 2018 3 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 4. Kafka is a distributed publish subscribe system Apache Kafka • It uses a commit log to track changes • Kafka was originally created at LinkedIn • Open sourced in 2011 • Graduated to a top-level Apache project in 2012 4 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 5. Introducing Pulsar Architectures API and Programming Differences Use Cases Pulsar For Kafka People 5 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 6. Basic Kafka Architecture Publisher SubscriberKafka Publisher sends data and doesn't know about the subscribers or their status. Subscriber recieves data from publisher and never directly interacts with it. All interactions go through Kafka and it handles all communication. 6 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 7. Basic Pulsar Architecture Producer ConsumerPulsar Producers do not directly interact with the BookKeeper cluster. Consumers do not directly interact with the BookKeeper cluster. All Brokers in the Pulsar cluster are stateless and can be scaled independently. BookKeeper All Bookies in the BookKeeper cluster are stateful and can be scaled independently. 7 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 8. Kafka Partitions Producer 0 Data is divided into partitions. Partitions are both logical and physical divisions. Producer 1 Topic Partition 0 Partition 1 Partition 2 All data is sent and received on topics. Topics group like data together. 8 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 9. Pulsar Ledgers The individual messages that are produced are stored as records in the ledger. Stream Ledger 1 Ledger 2 Ledger 3 Record 1 Record 2 Record 3 Record 4 Each topic has it's own stream and all data for a topic is stored in it. As more data is added to a topic, new ledgers are allocated to store the data. 9 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 10. Kafka Consumers Producer 0 Consumer recieves data from all topic partitions and connects to brokers 0, 1, and 2. Producer 1 Broker 0 Broker 1 Broker 2 Topic Partition 0 Partition 1 Partition 2 Consumer (P012) 10 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 11. Pulsar Subscriptions Producer 0 In failover, all partitions are consumed by one consumer and will fail over to hot spare on fail. Producer 1 Broker 0 Broker 1 Broker 2 Topic Partition 0 Partition 1 Partition 2 Failover Sub. (P012) Shared Sub. (P012) In shared, messages are sent in a round robin way to all consumers. Shared Sub. (P012) Key Shared (P012) Key Shared (P012) Failover Sub. (P) In key shared, messages with the same key are consistently routed to the same consumer. 11 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 12. Introducing Pulsar Architectures API and Programming Differences Use Cases Pulsar For Kafka People 12 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 13. import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.ProducerRecord; import static org.apache.kafka.clients.producer.ProducerConfig.*; Properties props = new Properties(); // Configure brokers to connect to props.put(BOOTSTRAP_SERVERS_CONFIG, "broker1:9092"); // Create a producer with the key as a string and value as a string KafkaProducer<String, String> producer = new KafkaProducer<>(props, new StringSerializer(), new StringSerializer()); // Create ProducerRecord and send it String key = "mykey"; String value = "myvalue"; ProducerRecord<String, String> record = new ProducerRecord<>("hello_topic", key, value); producer.send(record); producer.close(); Kafka Producer API 13 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 14. PulsarClient client = PulsarClient.builder() .serviceUrl("pulsar://broker1:6650") .build(); // Create a producer that will send values as strings // Default is byte[] Producer<String> producer = client .newProducer(Schema.STRING) .topic("hellotopic") .create(); // Create a new message, send it, and block until it is // acknowledged producer.newMessage() .key("mykey") .value("myvalue") .send(); // Create a new message, send it, and don't block until it is // acknowledged producer.newMessage() .key("mykey2") .value("myvalue2") .sendAsync(); // Close producer and client producer.close(); client.close(); Pulsar Producer API 14 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 15. import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.consumer.ConsumerRecords; import org.apache.kafka.clients.consumer.KafkaConsumer; import static org.apache.kafka.clients.consumer.ConsumerConfig.*; @SuppressWarnings("unused") public class HelloConsumer { KafkaConsumer<String, String> consumer; public void createConsumer() { String topic = "hello_topic"; Properties props = new Properties(); // Configure initial location bootstrap servers props.put(BOOTSTRAP_SERVERS_CONFIG, "broker1:9092"); // Configure consumer group props.put(GROUP_ID_CONFIG, "group1"); // Create the consumer with the key as a string and value as a string consumer = new KafkaConsumer<>(props, new StringDeserializer(), new StringDeserializer()); Kafka Consumer API (1/2) 15 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 16. consumer.subscribe(Arrays.asList(topic)); while (true) { // Poll for ConsumerRecords for a certain amount of time ConsumerRecords<String, String> records = consumer.poll( Duration.ofMillis(100)); // Process the ConsumerRecords, if any, that came back for (ConsumerRecord<String, String> record : records) { String key = record.key(); String value = record.value(); // Do something with message } } } public void close() { consumer.close(); } public static void main(String[] args) { HelloConsumer consumer = new HelloConsumer(); consumer.createConsumer(); consumer.close(); } Kafka Consumer API (2/2) 16 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 17. client = PulsarClient.builder() .serviceUrl("pulsar://broker1:6650") .build(); String myTopic = "hellotopic"; String mySubscriptionName = "my-subscription"; // Create a consumer that will receive values as strings // Default is byte[] consumer = client.newConsumer(Schema.STRING) .topic(myTopic) .subscriptionName(mySubscriptionName) .subscribe(); while (true) { // Block and wait until a single message is available Message<String> message = consumer.receive(); try { // Do something with the message System.out.println("Key is "" + message.getKey() + "" value is "" + message.getValue() + """); // Acknowledge the message so that it can be // deleted by the message broker consumer.acknowledgeCumulative(message); } catch (Exception e) { // Message failed to process, redeliver later consumer.negativeAcknowledge(message); } } Pulsar Consumer API 17 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 18. Both projects have an ecosystem associated with them Ecosystem Projects • Kafka Streams -> Pulsar Functions • KSQLDB (prop) -> Pulsar SQL • Kafka Connect -> Pulsar IO • Kafka API compatibility for Pulsar 18 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 19. Introducing Pulsar Architectures API and Programming Differences Use Cases Pulsar For Kafka People 19 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 20. Kafka++ All Kafka use cases plus more 20 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 21. Work Queues http://tiny.bdi.io/workqueues 21 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 22. Geo-Replication Built-in geo-replication 22 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 23. Unified Do both MQ-style and Pub/Sub-style with the same cluster 23 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 24. Lots of Topics Supports millions of topics 24 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9
  • 25. Thank You bigdatainstitute.io 25 / 25Copyright © 2020 Smoking Hand LLC. All rights Reserved. Version: 82982da9