SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
Reactive Applications with
Apache Pulsar and Spring Boot
Lari Hotari @lhotari
Senior Software Engineer, DataStax, Inc
Apache Pulsar committer
Presentation at SpringOne 2021
September 2, 2021
Who
2
Lari Hotari @lhotari
Software Engineer @DataStax, working on Luna Streaming powered by Apache Pulsar
Open-source contributor, Apache Pulsar committer
Journey with Spring:
○ Spring Framework user since 0.9 (2003)
○ Early Spring Framework contributor (2007, WebSphere DataSource support
for Spring Transaction Management)
○ Grails contributor (2009-2020)
Member of Groovy and Grails team (part of the Spring team) at Pivotal (2014-2015)
Grails team released Grails 3.0 built on Spring Boot in March 2015
○ Spring Boot contributor (heapdump actuator)
○ Project Reactor contributor (dns reverse lookup optimization & few others
in reactor-netty, 1 minor in reactor-core)
2004
2002
2005
2003
3
Pulsar & Reactive
Messaging
01
Sample use case &
Live coding
02
Scaling performance
of message
processing
03
Agenda
4
Pulsar & Reactive
Messaging
01
Sample use case &
Live coding
02
Scaling performance
of message
processing
03
Agenda
Apache Pulsar - Favourite properties
5
Many options for
scaling - not just about
partitions
02
Streaming, pub-sub
and queuing come
together
01
Cloud Native
Architecture
Layered storage
architecture
Stateless Brokers
First class support
for Kubernetes
03
Reactive Message handling - why?
6
Fault tolerance with
fallbacks, retries and
timeouts
Compatibility with
Reactive Streams to
achieve reactive from
end-to-end
Performance by
parallelism and
pipelining in
processing
Resilience with flow
control (backpressure)
Efficiency by optimal
resource usage
Simplification by
data orientation &
functional approach
Reactive Pulsar Adapter library
● https://github.com/lhotari/reactive-pulsar , License: ASL 2.0
● Wraps the Apache Pulsar Java Client async API with a simple and intuitive reactive API
● Goes beyond a wrapper
● Back-pressure support for provided interfaces
● Pulsar client resource lifecycle management
● Message producer caching
● In-order parallel processing at the application level
● Spring Boot starter for auto configuring a Pulsar Java client and a ReactivePulsarClient
7
Reactive Messaging Application building blocks
provided by the Reactive Pulsar Adapter library
8
Message Sender
Message Consumer
Message Listener Container
Message Reader
● Sender - for sending messages with a specific
configuration to a specific destination topic.
● Consumer - for guaranteed message delivery and handling.
The broker redelivers unacknowledged messages. Used for
both “always on” use cases and batch processing or
short-time message consuming or polling use cases.
● Reader - The application decides the position where to start
reading messages. Position can be earliest, latest, or an
absolute or time based position. Suitable also for
short-time message polling.
● Message Listener Container - integrates a consumer with
the Spring application lifecycle.
*) The abstractions of the Reactive Pulsar Adapter library are slightly different from the abstractions in Pulsar Java Client. The sender
is one example of a difference. The lifecycles of the abstractions are completely different. The ReactiveMessageSender,
ReactiveMessageReader and ReactiveMessageConsumer instances themselves are stateless.
“Nothing happens until you subscribe” - the key difference in the Reactive programming model.
Basics of Reactive APIs
9
- “Nothing happens until you subscribe”
- Assembly-time vs Runtime
- API calls return a reactive publisher type
- Flux<T> or Mono<T> when using Project Reactor
- Mono<Void> for calls that don’t return data
Reactive Pulsar Adapter
public interface ReactivePulsarClient {
<T> ReactiveMessageSenderBuilder<T> messageSender(Schema<T> schema);
<T> ReactiveMessageReaderBuilder<T> messageReader(Schema<T> schema);
<T> ReactiveMessageConsumerBuilder<T> messageConsumer(Schema<T> schema);
}
10
public interface ReactiveMessageReader<T> {
Mono<Message<T>> readMessage();
Flux<Message<T>> readMessages();
}
public interface ReactiveMessageSender<T> {
Mono<MessageId> sendMessage(Mono<MessageSpec<T>> messageSpec);
Flux<MessageId> sendMessages(Flux<MessageSpec<T>> messageSpecs);
}
public interface ReactiveMessageConsumer<T> {
<R> Mono<R> consumeMessage(
Function<Mono<Message<T>>, Mono<MessageResult<R>>> messageHandler);
<R> Flux<R> consumeMessages(
Function<Flux<Message<T>>, Flux<MessageResult<R>>> messageHandler);
}
Sample use cases - simplified IoT backend
11
Telemetry ingestion
from IoT devices
Telemetry processing
Streaming of telemetry values
to other applications
Sending alerts to
external application - webhook
interface
https://github.com/lhotari/reactive-pulsar-showcase for complete sample (work in progress)
12
Pulsar & Reactive
Messaging
01
Sample use case &
Live coding
02
Scaling performance
of message
processing
03
Agenda
Our goal for live coding
13
14
Pulsar & Reactive
Messaging
01
Sample use case &
Live coding
02
Scaling performance
of message
processing
03
Agenda
All significant improvements in
system scalability come from
parallelism.
15
Pipelining
16
“This idea is an extension of the idea of
parallelism. It is essentially handling the
activities involved in instruction execution
as an assembly line. As soon as the first
activity of an instruction is done you move
it to the second activity and start the first
activity of a new instruction. This results in
executing more instructions per unit time
compared to waiting for all activities of the
first instruction to complete before
starting the second instruction.”
https://www.d.umn.edu/~gshute/arch/great-ideas.html
Parallel Pipelining with Project Reactor:
Without ordering requirements
17
● When there are no ordering requirements, parallelism/concurrency can be achieved in two ways:
Using .parallel operator
(parallelism, for computations)
Flux
.range(1, 10)
.parallel(10)
.runOn(Schedulers.parallel())
.concatMap(i -> {
// CPU bound
…
// that returns a publisher
}
)
.sequential()
.subscribe()
Using .flatMap + .subscribeOn for inner publisher
(concurrency, for I/O tasks)
Flux
.range(1, 10)
.flatMap(
i -> {
// IO bound
…
// that returns a publisher
}.subscribeOn(Schedulers.parallel()),
10
)
.subscribe()
In-order parallel processing strategies
● System level: Multiple topic partitions
● Message is mapped to a specific partition by hashing the key
partition = hash(message key) % number_of_partitions
● Application level: Message consumer parallelism
● Micro-batching
● Messages are consumed in batches which is limited by time and number of entries.
● The processing can sort and group the entries for parallel processing.
● Stream splitting / routing / grouping
● Message is mapped to a specific processing group based on the hash of the message key
processing group = hash(message key) % number_of_processing_groups
● This is well suited for splitting the stream with Project Reactor’s .groupBy
● Benefit over micro-batching: no extra latency caused by batching
18
Parallel Pipelining with Project Reactor:
In-order processing requirements
19
When there is a requirement of in-order processing by key:
● .groupBy operator splits the stream by a key. The total
number of keys should be limited and relatively small
(hundreds).
● The concurrency level parameter for flatMap should be
set to the total number of groups to prevent the stream
processing from stalling (explained in Flux.groupBy
javadoc). In addition, the “prefetch” parameter of
.groupBy should be set to a value >= total number of
groups.
Flux
.range(1, 10)
// simulation of key: 0 (even) or 1 (odd)
.groupBy(i -> i % 2, Math.max(10, 32))
.flatMap(
groupedFlux ->
groupedFlux
.publishOn(Schedulers.parallel())
.concatMap(x -> {
// IO bound
…
// that returns a publisher
})
10,
1
)
.subscribe()
Parallel processing with ReactiveMessageConsumer
20
● An enabler is the the special signature of the
consumeMessages method on the
ReactiveMessageConsumer interface.
● The method accepts a function that takes
Flux<Message<T>> input and produces
Flux<MessageResult<R>>> output.
● MessageResult combines
acknowledgement and the result. The
implementation consumes the
Flux<MessageResult<R>>> , handles the
acknowledgements, and returns a Flux<R> .
● This enables guaranteed message delivery
combined with stream transformations.
public interface MessageResult<T> {
static <T> MessageResult<T> acknowledge(MessageId messageId, T value) {}
static <T> MessageResult<T> negativeAcknowledge(MessageId messageId, T
value) {}
static MessageResult<Void> acknowledge(MessageId messageId) {}
static MessageResult<Void> negativeAcknowledge(MessageId messageId) {}
static <V> MessageResult<Message<V>> acknowledgeAndReturn(Message<V>
message) {}
boolean isAcknowledgeMessage();
MessageId getMessageId();
T getValue();
}
public interface ReactiveMessageConsumer<T> {
<R> Flux<R> consumeMessages(
Function<Flux<Message<T>>, Flux<MessageResult<R>>>
messageHandler);
}
In-order parallel processing with Reactive Pulsar Adapter:
Implementation details
21
private static Integer resolveGroupKey(Message<?> message, int concurrency) {
byte[] keyBytes = null;
if (message.hasOrderingKey()) {
keyBytes = message.getOrderingKey();
} else if (message.hasKey()) {
keyBytes = message.getKeyBytes();
}
if (keyBytes == null || keyBytes.length == 0) {
// derive from the message id
keyBytes = message.getMessageId().toByteArray();
}
int keyHash = Murmur3_32Hash.getInstance().makeHash(keyBytes);
return keyHash % concurrency;
}
messageFlux
.groupBy(message -> resolveGroupKey(message, concurrency), Math.max(concurrency, 32))
.flatMap(
groupedFlux ->
groupedFlux
.publishOn(Schedulers.parallel())
.concatMap(message -> handleMessage(message)),
concurrency
);
actual implementation has been refactored:
https://github.com/lhotari/reactive-pulsar/blob/master/reactive-pulsar-adapter/src/main/java/com/github/lhotari/reactive/pulsar/internal/adapter/InKeyOrderMessageProcessors.java
References
22
Apache Pulsar: https://pulsar.apache.org/
Spring Reactive: https://spring.io/reactive
Reactive Pulsar adapter: https://github.com/lhotari/reactive-pulsar
Status: experimental version 0.0.7 available for use, API is subject to change until 1.0 is
released.
Reactive Pulsar showcase application: https://github.com/lhotari/reactive-pulsar-showcase
Status: work in progress, demonstrates the usage of the Reactive Pulsar Adapter.
For usage questions, please use apache-pulsar and reactive-pulsar tags on Stackoverflow.
Thank you !
23
We are hiring: https://www.datastax.com/company/careers

Contenu connexe

Tendances

Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018Scrum Breakfast Vietnam
 
Kafka Tutorial - basics of the Kafka streaming platform
Kafka Tutorial - basics of the Kafka streaming platformKafka Tutorial - basics of the Kafka streaming platform
Kafka Tutorial - basics of the Kafka streaming platformJean-Paul Azar
 
Introduction to Spring webflux
Introduction to Spring webfluxIntroduction to Spring webflux
Introduction to Spring webfluxKnoldus Inc.
 
End-to-end Streaming Between gRPC Services Via Kafka with John Fallows
End-to-end Streaming Between gRPC Services Via Kafka with John FallowsEnd-to-end Streaming Between gRPC Services Via Kafka with John Fallows
End-to-end Streaming Between gRPC Services Via Kafka with John FallowsHostedbyConfluent
 
Introduction to Grafana Loki
Introduction to Grafana LokiIntroduction to Grafana Loki
Introduction to Grafana LokiJulien Pivotto
 
Data Loss and Duplication in Kafka
Data Loss and Duplication in KafkaData Loss and Duplication in Kafka
Data Loss and Duplication in KafkaJayesh Thakrar
 
Why is My Stream Processing Job Slow? with Xavier Leaute
Why is My Stream Processing Job Slow? with Xavier LeauteWhy is My Stream Processing Job Slow? with Xavier Leaute
Why is My Stream Processing Job Slow? with Xavier LeauteDatabricks
 
Grafana Loki: like Prometheus, but for Logs
Grafana Loki: like Prometheus, but for LogsGrafana Loki: like Prometheus, but for Logs
Grafana Loki: like Prometheus, but for LogsMarco Pracucci
 
Apache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals ExplainedApache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals Explainedconfluent
 
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안SANG WON PARK
 
Spring I/O 2022: Knative and Spring - Bringing back the `func`
Spring I/O 2022: Knative and Spring - Bringing back the `func`Spring I/O 2022: Knative and Spring - Bringing back the `func`
Spring I/O 2022: Knative and Spring - Bringing back the `func`Mauricio (Salaboy) Salatino
 
Producer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache KafkaProducer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache KafkaJiangjie Qin
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJSBrainhub
 
Building an Event Streaming Architecture with Apache Pulsar
Building an Event Streaming Architecture with Apache PulsarBuilding an Event Streaming Architecture with Apache Pulsar
Building an Event Streaming Architecture with Apache PulsarScyllaDB
 
CDC Stream Processing With Apache Flink With Timo Walther | Current 2022
CDC Stream Processing With Apache Flink With Timo Walther | Current 2022CDC Stream Processing With Apache Flink With Timo Walther | Current 2022
CDC Stream Processing With Apache Flink With Timo Walther | Current 2022HostedbyConfluent
 

Tendances (20)

Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
Reactive programming by spring webflux - DN Scrum Breakfast - Nov 2018
 
Spring Webflux
Spring WebfluxSpring Webflux
Spring Webflux
 
Kafka Tutorial - basics of the Kafka streaming platform
Kafka Tutorial - basics of the Kafka streaming platformKafka Tutorial - basics of the Kafka streaming platform
Kafka Tutorial - basics of the Kafka streaming platform
 
Introduction to Spring webflux
Introduction to Spring webfluxIntroduction to Spring webflux
Introduction to Spring webflux
 
gRPC Overview
gRPC OverviewgRPC Overview
gRPC Overview
 
End-to-end Streaming Between gRPC Services Via Kafka with John Fallows
End-to-end Streaming Between gRPC Services Via Kafka with John FallowsEnd-to-end Streaming Between gRPC Services Via Kafka with John Fallows
End-to-end Streaming Between gRPC Services Via Kafka with John Fallows
 
Introduction to Grafana Loki
Introduction to Grafana LokiIntroduction to Grafana Loki
Introduction to Grafana Loki
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
 
Data Loss and Duplication in Kafka
Data Loss and Duplication in KafkaData Loss and Duplication in Kafka
Data Loss and Duplication in Kafka
 
Reactive programming intro
Reactive programming introReactive programming intro
Reactive programming intro
 
Why is My Stream Processing Job Slow? with Xavier Leaute
Why is My Stream Processing Job Slow? with Xavier LeauteWhy is My Stream Processing Job Slow? with Xavier Leaute
Why is My Stream Processing Job Slow? with Xavier Leaute
 
Grafana Loki: like Prometheus, but for Logs
Grafana Loki: like Prometheus, but for LogsGrafana Loki: like Prometheus, but for Logs
Grafana Loki: like Prometheus, but for Logs
 
Apache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals ExplainedApache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals Explained
 
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
 
Kafka 101
Kafka 101Kafka 101
Kafka 101
 
Spring I/O 2022: Knative and Spring - Bringing back the `func`
Spring I/O 2022: Knative and Spring - Bringing back the `func`Spring I/O 2022: Knative and Spring - Bringing back the `func`
Spring I/O 2022: Knative and Spring - Bringing back the `func`
 
Producer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache KafkaProducer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache Kafka
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
 
Building an Event Streaming Architecture with Apache Pulsar
Building an Event Streaming Architecture with Apache PulsarBuilding an Event Streaming Architecture with Apache Pulsar
Building an Event Streaming Architecture with Apache Pulsar
 
CDC Stream Processing With Apache Flink With Timo Walther | Current 2022
CDC Stream Processing With Apache Flink With Timo Walther | Current 2022CDC Stream Processing With Apache Flink With Timo Walther | Current 2022
CDC Stream Processing With Apache Flink With Timo Walther | Current 2022
 

Similaire à Reactive Applications with Apache Pulsar and Spring Boot

Microservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingMicroservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingAraf Karsh Hamid
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programmingAraf Karsh Hamid
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideMohanraj Thirumoorthy
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx javaCongTrung Vnit
 
IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016Trayan Iliev
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaAli Muzaffar
 
The hitchhiker’s guide to Prometheus
The hitchhiker’s guide to PrometheusThe hitchhiker’s guide to Prometheus
The hitchhiker’s guide to PrometheusBol.com Techlab
 
The hitchhiker’s guide to Prometheus
The hitchhiker’s guide to PrometheusThe hitchhiker’s guide to Prometheus
The hitchhiker’s guide to PrometheusBol.com Techlab
 
Project Reactor Now and Tomorrow
Project Reactor Now and TomorrowProject Reactor Now and Tomorrow
Project Reactor Now and TomorrowVMware Tanzu
 
Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018Trayan Iliev
 
Microservices with Spring 5 Webflux - jProfessionals
Microservices  with Spring 5 Webflux - jProfessionalsMicroservices  with Spring 5 Webflux - jProfessionals
Microservices with Spring 5 Webflux - jProfessionalsTrayan Iliev
 

Similaire à Reactive Applications with Apache Pulsar and Spring Boot (20)

Microservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive ProgrammingMicroservices Part 4: Functional Reactive Programming
Microservices Part 4: Functional Reactive Programming
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programming
 
1844 1849
1844 18491844 1849
1844 1849
 
1844 1849
1844 18491844 1849
1844 1849
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's Guide
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
 
Map reduce prashant
Map reduce prashantMap reduce prashant
Map reduce prashant
 
Smart Migration to JDK 8
Smart Migration to JDK 8Smart Migration to JDK 8
Smart Migration to JDK 8
 
KrakenD API Gateway
KrakenD API GatewayKrakenD API Gateway
KrakenD API Gateway
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx java
 
Java 8 streams
Java 8 streams Java 8 streams
Java 8 streams
 
IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJava
 
The hitchhiker’s guide to Prometheus
The hitchhiker’s guide to PrometheusThe hitchhiker’s guide to Prometheus
The hitchhiker’s guide to Prometheus
 
The hitchhiker’s guide to Prometheus
The hitchhiker’s guide to PrometheusThe hitchhiker’s guide to Prometheus
The hitchhiker’s guide to Prometheus
 
Prometheus monitoring
Prometheus monitoringPrometheus monitoring
Prometheus monitoring
 
Project Reactor Now and Tomorrow
Project Reactor Now and TomorrowProject Reactor Now and Tomorrow
Project Reactor Now and Tomorrow
 
Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018
 
Reactive Applications in Java
Reactive Applications in JavaReactive Applications in Java
Reactive Applications in Java
 
Microservices with Spring 5 Webflux - jProfessionals
Microservices  with Spring 5 Webflux - jProfessionalsMicroservices  with Spring 5 Webflux - jProfessionals
Microservices with Spring 5 Webflux - jProfessionals
 

Plus de VMware Tanzu

What AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About ItWhat AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About ItVMware Tanzu
 
Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023VMware Tanzu
 
Enhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at ScaleEnhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at ScaleVMware Tanzu
 
Spring Update | July 2023
Spring Update | July 2023Spring Update | July 2023
Spring Update | July 2023VMware Tanzu
 
Platforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a ProductPlatforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a ProductVMware Tanzu
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready AppsVMware Tanzu
 
Spring Boot 3 And Beyond
Spring Boot 3 And BeyondSpring Boot 3 And Beyond
Spring Boot 3 And BeyondVMware Tanzu
 
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdfSpring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdfVMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023VMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023VMware Tanzu
 
tanzu_developer_connect.pptx
tanzu_developer_connect.pptxtanzu_developer_connect.pptx
tanzu_developer_connect.pptxVMware Tanzu
 
Tanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchTanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchVMware Tanzu
 
Tanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishTanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishVMware Tanzu
 
Virtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVirtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVMware Tanzu
 
Tanzu Developer Connect - French
Tanzu Developer Connect - FrenchTanzu Developer Connect - French
Tanzu Developer Connect - FrenchVMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023VMware Tanzu
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootSpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootVMware Tanzu
 
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerSpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerVMware Tanzu
 
SpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeSpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeVMware Tanzu
 
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsSpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsVMware Tanzu
 

Plus de VMware Tanzu (20)

What AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About ItWhat AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About It
 
Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023
 
Enhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at ScaleEnhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at Scale
 
Spring Update | July 2023
Spring Update | July 2023Spring Update | July 2023
Spring Update | July 2023
 
Platforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a ProductPlatforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a Product
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready Apps
 
Spring Boot 3 And Beyond
Spring Boot 3 And BeyondSpring Boot 3 And Beyond
Spring Boot 3 And Beyond
 
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdfSpring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
 
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
 
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
 
tanzu_developer_connect.pptx
tanzu_developer_connect.pptxtanzu_developer_connect.pptx
tanzu_developer_connect.pptx
 
Tanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchTanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - French
 
Tanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishTanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - English
 
Virtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVirtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - English
 
Tanzu Developer Connect - French
Tanzu Developer Connect - FrenchTanzu Developer Connect - French
Tanzu Developer Connect - French
 
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootSpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
 
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerSpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software Engineer
 
SpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeSpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs Practice
 
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsSpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
 

Dernier

DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
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
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
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
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
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
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 

Dernier (20)

DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
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...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
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
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
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
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 

Reactive Applications with Apache Pulsar and Spring Boot

  • 1. Reactive Applications with Apache Pulsar and Spring Boot Lari Hotari @lhotari Senior Software Engineer, DataStax, Inc Apache Pulsar committer Presentation at SpringOne 2021 September 2, 2021
  • 2. Who 2 Lari Hotari @lhotari Software Engineer @DataStax, working on Luna Streaming powered by Apache Pulsar Open-source contributor, Apache Pulsar committer Journey with Spring: ○ Spring Framework user since 0.9 (2003) ○ Early Spring Framework contributor (2007, WebSphere DataSource support for Spring Transaction Management) ○ Grails contributor (2009-2020) Member of Groovy and Grails team (part of the Spring team) at Pivotal (2014-2015) Grails team released Grails 3.0 built on Spring Boot in March 2015 ○ Spring Boot contributor (heapdump actuator) ○ Project Reactor contributor (dns reverse lookup optimization & few others in reactor-netty, 1 minor in reactor-core) 2004 2002 2005 2003
  • 3. 3 Pulsar & Reactive Messaging 01 Sample use case & Live coding 02 Scaling performance of message processing 03 Agenda
  • 4. 4 Pulsar & Reactive Messaging 01 Sample use case & Live coding 02 Scaling performance of message processing 03 Agenda
  • 5. Apache Pulsar - Favourite properties 5 Many options for scaling - not just about partitions 02 Streaming, pub-sub and queuing come together 01 Cloud Native Architecture Layered storage architecture Stateless Brokers First class support for Kubernetes 03
  • 6. Reactive Message handling - why? 6 Fault tolerance with fallbacks, retries and timeouts Compatibility with Reactive Streams to achieve reactive from end-to-end Performance by parallelism and pipelining in processing Resilience with flow control (backpressure) Efficiency by optimal resource usage Simplification by data orientation & functional approach
  • 7. Reactive Pulsar Adapter library ● https://github.com/lhotari/reactive-pulsar , License: ASL 2.0 ● Wraps the Apache Pulsar Java Client async API with a simple and intuitive reactive API ● Goes beyond a wrapper ● Back-pressure support for provided interfaces ● Pulsar client resource lifecycle management ● Message producer caching ● In-order parallel processing at the application level ● Spring Boot starter for auto configuring a Pulsar Java client and a ReactivePulsarClient 7
  • 8. Reactive Messaging Application building blocks provided by the Reactive Pulsar Adapter library 8 Message Sender Message Consumer Message Listener Container Message Reader ● Sender - for sending messages with a specific configuration to a specific destination topic. ● Consumer - for guaranteed message delivery and handling. The broker redelivers unacknowledged messages. Used for both “always on” use cases and batch processing or short-time message consuming or polling use cases. ● Reader - The application decides the position where to start reading messages. Position can be earliest, latest, or an absolute or time based position. Suitable also for short-time message polling. ● Message Listener Container - integrates a consumer with the Spring application lifecycle. *) The abstractions of the Reactive Pulsar Adapter library are slightly different from the abstractions in Pulsar Java Client. The sender is one example of a difference. The lifecycles of the abstractions are completely different. The ReactiveMessageSender, ReactiveMessageReader and ReactiveMessageConsumer instances themselves are stateless. “Nothing happens until you subscribe” - the key difference in the Reactive programming model.
  • 9. Basics of Reactive APIs 9 - “Nothing happens until you subscribe” - Assembly-time vs Runtime - API calls return a reactive publisher type - Flux<T> or Mono<T> when using Project Reactor - Mono<Void> for calls that don’t return data
  • 10. Reactive Pulsar Adapter public interface ReactivePulsarClient { <T> ReactiveMessageSenderBuilder<T> messageSender(Schema<T> schema); <T> ReactiveMessageReaderBuilder<T> messageReader(Schema<T> schema); <T> ReactiveMessageConsumerBuilder<T> messageConsumer(Schema<T> schema); } 10 public interface ReactiveMessageReader<T> { Mono<Message<T>> readMessage(); Flux<Message<T>> readMessages(); } public interface ReactiveMessageSender<T> { Mono<MessageId> sendMessage(Mono<MessageSpec<T>> messageSpec); Flux<MessageId> sendMessages(Flux<MessageSpec<T>> messageSpecs); } public interface ReactiveMessageConsumer<T> { <R> Mono<R> consumeMessage( Function<Mono<Message<T>>, Mono<MessageResult<R>>> messageHandler); <R> Flux<R> consumeMessages( Function<Flux<Message<T>>, Flux<MessageResult<R>>> messageHandler); }
  • 11. Sample use cases - simplified IoT backend 11 Telemetry ingestion from IoT devices Telemetry processing Streaming of telemetry values to other applications Sending alerts to external application - webhook interface https://github.com/lhotari/reactive-pulsar-showcase for complete sample (work in progress)
  • 12. 12 Pulsar & Reactive Messaging 01 Sample use case & Live coding 02 Scaling performance of message processing 03 Agenda
  • 13. Our goal for live coding 13
  • 14. 14 Pulsar & Reactive Messaging 01 Sample use case & Live coding 02 Scaling performance of message processing 03 Agenda
  • 15. All significant improvements in system scalability come from parallelism. 15
  • 16. Pipelining 16 “This idea is an extension of the idea of parallelism. It is essentially handling the activities involved in instruction execution as an assembly line. As soon as the first activity of an instruction is done you move it to the second activity and start the first activity of a new instruction. This results in executing more instructions per unit time compared to waiting for all activities of the first instruction to complete before starting the second instruction.” https://www.d.umn.edu/~gshute/arch/great-ideas.html
  • 17. Parallel Pipelining with Project Reactor: Without ordering requirements 17 ● When there are no ordering requirements, parallelism/concurrency can be achieved in two ways: Using .parallel operator (parallelism, for computations) Flux .range(1, 10) .parallel(10) .runOn(Schedulers.parallel()) .concatMap(i -> { // CPU bound … // that returns a publisher } ) .sequential() .subscribe() Using .flatMap + .subscribeOn for inner publisher (concurrency, for I/O tasks) Flux .range(1, 10) .flatMap( i -> { // IO bound … // that returns a publisher }.subscribeOn(Schedulers.parallel()), 10 ) .subscribe()
  • 18. In-order parallel processing strategies ● System level: Multiple topic partitions ● Message is mapped to a specific partition by hashing the key partition = hash(message key) % number_of_partitions ● Application level: Message consumer parallelism ● Micro-batching ● Messages are consumed in batches which is limited by time and number of entries. ● The processing can sort and group the entries for parallel processing. ● Stream splitting / routing / grouping ● Message is mapped to a specific processing group based on the hash of the message key processing group = hash(message key) % number_of_processing_groups ● This is well suited for splitting the stream with Project Reactor’s .groupBy ● Benefit over micro-batching: no extra latency caused by batching 18
  • 19. Parallel Pipelining with Project Reactor: In-order processing requirements 19 When there is a requirement of in-order processing by key: ● .groupBy operator splits the stream by a key. The total number of keys should be limited and relatively small (hundreds). ● The concurrency level parameter for flatMap should be set to the total number of groups to prevent the stream processing from stalling (explained in Flux.groupBy javadoc). In addition, the “prefetch” parameter of .groupBy should be set to a value >= total number of groups. Flux .range(1, 10) // simulation of key: 0 (even) or 1 (odd) .groupBy(i -> i % 2, Math.max(10, 32)) .flatMap( groupedFlux -> groupedFlux .publishOn(Schedulers.parallel()) .concatMap(x -> { // IO bound … // that returns a publisher }) 10, 1 ) .subscribe()
  • 20. Parallel processing with ReactiveMessageConsumer 20 ● An enabler is the the special signature of the consumeMessages method on the ReactiveMessageConsumer interface. ● The method accepts a function that takes Flux<Message<T>> input and produces Flux<MessageResult<R>>> output. ● MessageResult combines acknowledgement and the result. The implementation consumes the Flux<MessageResult<R>>> , handles the acknowledgements, and returns a Flux<R> . ● This enables guaranteed message delivery combined with stream transformations. public interface MessageResult<T> { static <T> MessageResult<T> acknowledge(MessageId messageId, T value) {} static <T> MessageResult<T> negativeAcknowledge(MessageId messageId, T value) {} static MessageResult<Void> acknowledge(MessageId messageId) {} static MessageResult<Void> negativeAcknowledge(MessageId messageId) {} static <V> MessageResult<Message<V>> acknowledgeAndReturn(Message<V> message) {} boolean isAcknowledgeMessage(); MessageId getMessageId(); T getValue(); } public interface ReactiveMessageConsumer<T> { <R> Flux<R> consumeMessages( Function<Flux<Message<T>>, Flux<MessageResult<R>>> messageHandler); }
  • 21. In-order parallel processing with Reactive Pulsar Adapter: Implementation details 21 private static Integer resolveGroupKey(Message<?> message, int concurrency) { byte[] keyBytes = null; if (message.hasOrderingKey()) { keyBytes = message.getOrderingKey(); } else if (message.hasKey()) { keyBytes = message.getKeyBytes(); } if (keyBytes == null || keyBytes.length == 0) { // derive from the message id keyBytes = message.getMessageId().toByteArray(); } int keyHash = Murmur3_32Hash.getInstance().makeHash(keyBytes); return keyHash % concurrency; } messageFlux .groupBy(message -> resolveGroupKey(message, concurrency), Math.max(concurrency, 32)) .flatMap( groupedFlux -> groupedFlux .publishOn(Schedulers.parallel()) .concatMap(message -> handleMessage(message)), concurrency ); actual implementation has been refactored: https://github.com/lhotari/reactive-pulsar/blob/master/reactive-pulsar-adapter/src/main/java/com/github/lhotari/reactive/pulsar/internal/adapter/InKeyOrderMessageProcessors.java
  • 22. References 22 Apache Pulsar: https://pulsar.apache.org/ Spring Reactive: https://spring.io/reactive Reactive Pulsar adapter: https://github.com/lhotari/reactive-pulsar Status: experimental version 0.0.7 available for use, API is subject to change until 1.0 is released. Reactive Pulsar showcase application: https://github.com/lhotari/reactive-pulsar-showcase Status: work in progress, demonstrates the usage of the Reactive Pulsar Adapter. For usage questions, please use apache-pulsar and reactive-pulsar tags on Stackoverflow.
  • 23. Thank you ! 23 We are hiring: https://www.datastax.com/company/careers