SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

C++からWebRTC (DataChannel)を利用する
C++からWebRTC (DataChannel)を利用するC++からWebRTC (DataChannel)を利用する
C++からWebRTC (DataChannel)を利用する祐司 伊藤
 
When apache pulsar meets apache flink
When apache pulsar meets apache flinkWhen apache pulsar meets apache flink
When apache pulsar meets apache flinkStreamNative
 
MySQL Monitoring using Prometheus & Grafana
MySQL Monitoring using Prometheus & GrafanaMySQL Monitoring using Prometheus & Grafana
MySQL Monitoring using Prometheus & GrafanaYoungHeon (Roy) Kim
 
Data processing with celery and rabbit mq
Data processing with celery and rabbit mqData processing with celery and rabbit mq
Data processing with celery and rabbit mqJeff Peck
 
Java11 New Features
Java11 New FeaturesJava11 New Features
Java11 New FeaturesHaim Michael
 
Message Redelivery: An Unexpected Journey - Pulsar Summit SF 2022
Message Redelivery: An Unexpected Journey - Pulsar Summit SF 2022Message Redelivery: An Unexpected Journey - Pulsar Summit SF 2022
Message Redelivery: An Unexpected Journey - Pulsar Summit SF 2022StreamNative
 
Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaKasun Indrasiri
 
Scaling Apache Pulsar to 10 Petabytes/Day
Scaling Apache Pulsar to 10 Petabytes/DayScaling Apache Pulsar to 10 Petabytes/Day
Scaling Apache Pulsar to 10 Petabytes/DayScyllaDB
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive ProgrammingAndres Almiray
 
Microservices Architectures: Become a Unicorn like Netflix, Twitter and Hailo
Microservices Architectures: Become a Unicorn like Netflix, Twitter and HailoMicroservices Architectures: Become a Unicorn like Netflix, Twitter and Hailo
Microservices Architectures: Become a Unicorn like Netflix, Twitter and Hailogjuljo
 
Introduction To RabbitMQ
Introduction To RabbitMQIntroduction To RabbitMQ
Introduction To RabbitMQKnoldus Inc.
 
Living the Stream Dream with Pulsar and Spring Boot
Living the Stream Dream with Pulsar and Spring BootLiving the Stream Dream with Pulsar and Spring Boot
Living the Stream Dream with Pulsar and Spring BootTimothy Spann
 
Spring IO 2023 - Dynamic OpenAPIs with Spring Cloud Gateway
Spring IO 2023 - Dynamic OpenAPIs with Spring Cloud GatewaySpring IO 2023 - Dynamic OpenAPIs with Spring Cloud Gateway
Spring IO 2023 - Dynamic OpenAPIs with Spring Cloud GatewayIván López Martín
 
Hadoop REST API Security with Apache Knox Gateway
Hadoop REST API Security with Apache Knox GatewayHadoop REST API Security with Apache Knox Gateway
Hadoop REST API Security with Apache Knox GatewayDataWorks Summit
 

Was ist angesagt? (20)

C++からWebRTC (DataChannel)を利用する
C++からWebRTC (DataChannel)を利用するC++からWebRTC (DataChannel)を利用する
C++からWebRTC (DataChannel)を利用する
 
When apache pulsar meets apache flink
When apache pulsar meets apache flinkWhen apache pulsar meets apache flink
When apache pulsar meets apache flink
 
Project Reactor By Example
Project Reactor By ExampleProject Reactor By Example
Project Reactor By Example
 
MySQL Monitoring using Prometheus & Grafana
MySQL Monitoring using Prometheus & GrafanaMySQL Monitoring using Prometheus & Grafana
MySQL Monitoring using Prometheus & Grafana
 
Data processing with celery and rabbit mq
Data processing with celery and rabbit mqData processing with celery and rabbit mq
Data processing with celery and rabbit mq
 
Grafana 7.0
Grafana 7.0Grafana 7.0
Grafana 7.0
 
Java11 New Features
Java11 New FeaturesJava11 New Features
Java11 New Features
 
WebAssembly Overview
WebAssembly OverviewWebAssembly Overview
WebAssembly Overview
 
Message Redelivery: An Unexpected Journey - Pulsar Summit SF 2022
Message Redelivery: An Unexpected Journey - Pulsar Summit SF 2022Message Redelivery: An Unexpected Journey - Pulsar Summit SF 2022
Message Redelivery: An Unexpected Journey - Pulsar Summit SF 2022
 
Reactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-JavaReactive Programming in Java 8 with Rx-Java
Reactive Programming in Java 8 with Rx-Java
 
Scaling Apache Pulsar to 10 Petabytes/Day
Scaling Apache Pulsar to 10 Petabytes/DayScaling Apache Pulsar to 10 Petabytes/Day
Scaling Apache Pulsar to 10 Petabytes/Day
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive Programming
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Graylog
GraylogGraylog
Graylog
 
Microservices Architectures: Become a Unicorn like Netflix, Twitter and Hailo
Microservices Architectures: Become a Unicorn like Netflix, Twitter and HailoMicroservices Architectures: Become a Unicorn like Netflix, Twitter and Hailo
Microservices Architectures: Become a Unicorn like Netflix, Twitter and Hailo
 
Introduction To RabbitMQ
Introduction To RabbitMQIntroduction To RabbitMQ
Introduction To RabbitMQ
 
Living the Stream Dream with Pulsar and Spring Boot
Living the Stream Dream with Pulsar and Spring BootLiving the Stream Dream with Pulsar and Spring Boot
Living the Stream Dream with Pulsar and Spring Boot
 
Spring IO 2023 - Dynamic OpenAPIs with Spring Cloud Gateway
Spring IO 2023 - Dynamic OpenAPIs with Spring Cloud GatewaySpring IO 2023 - Dynamic OpenAPIs with Spring Cloud Gateway
Spring IO 2023 - Dynamic OpenAPIs with Spring Cloud Gateway
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
Hadoop REST API Security with Apache Knox Gateway
Hadoop REST API Security with Apache Knox GatewayHadoop REST API Security with Apache Knox Gateway
Hadoop REST API Security with Apache Knox Gateway
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
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
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
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
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
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
 

Kürzlich hochgeladen (20)

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
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
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
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...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
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
 

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