SlideShare una empresa de Scribd logo
1 de 23
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

IBM RedHat OCP Vs xKS.pptx
IBM RedHat OCP Vs xKS.pptxIBM RedHat OCP Vs xKS.pptx
IBM RedHat OCP Vs xKS.pptxssuser666667
 
Blue-green deploys with Pulsar & Envoy in an event-driven microservice ecosys...
Blue-green deploys with Pulsar & Envoy in an event-driven microservice ecosys...Blue-green deploys with Pulsar & Envoy in an event-driven microservice ecosys...
Blue-green deploys with Pulsar & Envoy in an event-driven microservice ecosys...StreamNative
 
Event Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQEvent Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQAraf Karsh Hamid
 
Micro services Architecture
Micro services ArchitectureMicro services Architecture
Micro services ArchitectureAraf Karsh Hamid
 
Microservices Architecture
Microservices ArchitectureMicroservices Architecture
Microservices ArchitectureIzzet Mustafaiev
 
The RabbitMQ Message Broker
The RabbitMQ Message BrokerThe RabbitMQ Message Broker
The RabbitMQ Message BrokerMartin Toshev
 
Gateway/APIC security
Gateway/APIC securityGateway/APIC security
Gateway/APIC securityShiu-Fun Poon
 
Prometheus: What is is, what is new, what is coming
Prometheus: What is is, what is new, what is comingPrometheus: What is is, what is new, what is coming
Prometheus: What is is, what is new, what is comingJulien Pivotto
 
Securing your Pulsar Cluster with Vault_Chris Kellogg
Securing your Pulsar Cluster with Vault_Chris KelloggSecuring your Pulsar Cluster with Vault_Chris Kellogg
Securing your Pulsar Cluster with Vault_Chris KelloggStreamNative
 
KubeFlow + GPU + Keras/TensorFlow 2.0 + TF Extended (TFX) + Kubernetes + PyTo...
KubeFlow + GPU + Keras/TensorFlow 2.0 + TF Extended (TFX) + Kubernetes + PyTo...KubeFlow + GPU + Keras/TensorFlow 2.0 + TF Extended (TFX) + Kubernetes + PyTo...
KubeFlow + GPU + Keras/TensorFlow 2.0 + TF Extended (TFX) + Kubernetes + PyTo...Chris Fregly
 
Monoliths and Microservices
Monoliths and Microservices Monoliths and Microservices
Monoliths and Microservices Bozhidar Bozhanov
 
Integrating PostgreSql with RabbitMQ
Integrating PostgreSql with RabbitMQIntegrating PostgreSql with RabbitMQ
Integrating PostgreSql with RabbitMQGavin Roy
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to Kubernetesrajdeep
 
Microservice architecture design principles
Microservice architecture design principlesMicroservice architecture design principles
Microservice architecture design principlesSanjoy Kumar Roy
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache KafkaJeff Holoman
 

La actualidad más candente (20)

IBM RedHat OCP Vs xKS.pptx
IBM RedHat OCP Vs xKS.pptxIBM RedHat OCP Vs xKS.pptx
IBM RedHat OCP Vs xKS.pptx
 
Blue-green deploys with Pulsar & Envoy in an event-driven microservice ecosys...
Blue-green deploys with Pulsar & Envoy in an event-driven microservice ecosys...Blue-green deploys with Pulsar & Envoy in an event-driven microservice ecosys...
Blue-green deploys with Pulsar & Envoy in an event-driven microservice ecosys...
 
Message Broker System and RabbitMQ
Message Broker System and RabbitMQMessage Broker System and RabbitMQ
Message Broker System and RabbitMQ
 
RabbitMQ
RabbitMQ RabbitMQ
RabbitMQ
 
Event Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQEvent Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQ
 
Micro services Architecture
Micro services ArchitectureMicro services Architecture
Micro services Architecture
 
Api Gateway
Api GatewayApi Gateway
Api Gateway
 
Microservices Architecture
Microservices ArchitectureMicroservices Architecture
Microservices Architecture
 
The RabbitMQ Message Broker
The RabbitMQ Message BrokerThe RabbitMQ Message Broker
The RabbitMQ Message Broker
 
Gateway/APIC security
Gateway/APIC securityGateway/APIC security
Gateway/APIC security
 
Cloud Monitoring tool Grafana
Cloud Monitoring  tool Grafana Cloud Monitoring  tool Grafana
Cloud Monitoring tool Grafana
 
Prometheus: What is is, what is new, what is coming
Prometheus: What is is, what is new, what is comingPrometheus: What is is, what is new, what is coming
Prometheus: What is is, what is new, what is coming
 
Securing your Pulsar Cluster with Vault_Chris Kellogg
Securing your Pulsar Cluster with Vault_Chris KelloggSecuring your Pulsar Cluster with Vault_Chris Kellogg
Securing your Pulsar Cluster with Vault_Chris Kellogg
 
KubeFlow + GPU + Keras/TensorFlow 2.0 + TF Extended (TFX) + Kubernetes + PyTo...
KubeFlow + GPU + Keras/TensorFlow 2.0 + TF Extended (TFX) + Kubernetes + PyTo...KubeFlow + GPU + Keras/TensorFlow 2.0 + TF Extended (TFX) + Kubernetes + PyTo...
KubeFlow + GPU + Keras/TensorFlow 2.0 + TF Extended (TFX) + Kubernetes + PyTo...
 
Monoliths and Microservices
Monoliths and Microservices Monoliths and Microservices
Monoliths and Microservices
 
Integrating PostgreSql with RabbitMQ
Integrating PostgreSql with RabbitMQIntegrating PostgreSql with RabbitMQ
Integrating PostgreSql with RabbitMQ
 
Introduction to Kubernetes
Introduction to KubernetesIntroduction to Kubernetes
Introduction to Kubernetes
 
Serverless
ServerlessServerless
Serverless
 
Microservice architecture design principles
Microservice architecture design principlesMicroservice architecture design principles
Microservice architecture design principles
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
 

Similar a 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
 

Similar a 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
 

Más 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
 

Más 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
 

Último

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
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
 
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
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
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
 
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
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
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
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
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
 
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
 

Último (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
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...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
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
 
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
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
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
 
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...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
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...
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
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)
 
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
 

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