SlideShare uma empresa Scribd logo
1 de 59
Baixar para ler offline
Let the Alpakka
pull your stream
Enno Runne
Java Forum Nord 2019-09-24
Reactive Principles
The Reactive Manifesto discusses how we can
build responsive systems.
Akka Streams
Akka Streams is library to model and run high-
performance, non-blocking data flows supporting
back-pressure, with concise APIs for Java and
Scala.
Alpakka
Alpakka is a Reactive Enterprise Integration
library for Java and Scala, based on Reactive
Streams and Akka.
The short version: “Endpoints for Akka Streams”
• Alpakka Tech Lead @ Lightbend
• Stockholm, Sweden
Enno Runne
Reactive?
Why do we talk about
Responsive: The system responds in a timely
manner if at all possible. Responsiveness is the
cornerstone of usability and utility, but more than
that, responsiveness means that problems may
be detected quickly and dealt with effectively.
Responsive systems focus on providing rapid
and consistent response times, establishing
reliable upper bounds so they deliver a
consistent quality of service. This consistent
behaviour in turn simplifies error handling, builds
end user confidence, and encourages further
interaction.
https://www.reactivemanifesto.org/
Customer support
Customer support via chat
Message-driven architecture
• enables resource utilisation
• is easier to scale
• allows for distribution
Lightbend Reactive Architecture
A free, online learning experience by Lightbend and IBM
https://lightbend.com/learn/lightbend-reactive-architecture
Akka?
How does streaming relate to
Build powerful reactive, concurrent,
and distributed applications more easily
Akka
Akka Actors
(typed and classic)
Akka Cluster &
Sharding
Akka Persistence &
Distributed Data
Akka Streams
Akka HTTP
Akka gRPC
Alpakka
(reactive integrations)
Akka Management
Akka Enhancements
(persistence & resilience)
Extends Reactive Streams to be used
• for local file access
• over TCP as TCP supports flow control
• for HTTP with Akka HTTP
• for gRPC with Akka gRPC
Akka Streams
Akka Streams
Akka HTTP
Akka gRPC
Alpakka
(reactive integrations)
• Domain Specific Language to describe streams
• Mechanics to map these stream to be executed on top of actors
• Full support to connect to any Reactive Streams compliant library
When to use what abstraction
modelling power
complexity
actors
streams
(completable)
futures
java.concurrency
Data flow
Step 1 Step 4Step 2 Step 3
Buffering data
• May cure the immediate issue
• All buffering is limited
Dynamic push/pull
• Push when downstream is faster
• Pull when upstream is faster
Downstream
Source SinkFlow Flow
Streaming with back-pressure
Reactive Streams
reactive-streams.org
Part of the JDK since version 9 (java.util.concurrent.Flow)
http://reactive-streams.org/
Compliant libraries allow full interoperability.
Reactive Streams
A standard for asynchronous
stream processing with non-
blocking back-pressure.
What is a
stream?
Photo by blucolt - originally posted to Flickr as spearfish creek, CC BY-SA 2.0
50,000 / s
10 / s
1 / month
Inter-system
messages with Kafka
De-couple systems
Buffering (Queues)
Distribution
Multiple consumers to same data
“Inter-system message-driven”
Alpakka Kafka with Akka Streams
Consumer.DrainingControl<Done> control =
Consumer
.sourceWithOffsetContext(consumerSettings, Subscriptions.topics(topic))
.mapAsync(
parallelism: 1,
record -> business(record.key(), record.value())
)
.toMat(Committer.sinkWithOffsetContext(committerSettings), Keep.both())
.mapMaterializedValue(Consumer::createDrainingControl)
.run(materializer);
Alpakka Kafka with Akka Streams
Consumer.DrainingControl<Done> control =
Consumer
.sourceWithOffsetContext(consumerSettings, Subscriptions.topics(topic))
.mapAsync(
parallelism: 1,
record -> business(record.key(), record.value())
)
.toMat(Committer.sinkWithOffsetContext(committerSettings), Keep.both())
.mapMaterializedValue(Consumer::createDrainingControl)
.run(materializer);
Source
ConsumerRecord<String, String>
Alpakka Kafka with Akka Streams
Consumer.DrainingControl<Done> control =
Consumer
.sourceWithOffsetContext(consumerSettings, Subscriptions.topics(topic))
.mapAsync(
parallelism: 1,
record -> business(record.key(), record.value())
)
.toMat(Committer.sinkWithOffsetContext(committerSettings), Keep.both())
.mapMaterializedValue(Consumer::createDrainingControl)
.run(materializer);
Sink
Alpakka Kafka with Akka Streams
Consumer.DrainingControl<Done> control =
Consumer
.sourceWithOffsetContext(consumerSettings, Subscriptions.topics(topic))
.mapAsync(
parallelism: 1,
record -> business(record.key(), record.value())
)
.toMat(Committer.sinkWithOffsetContext(committerSettings), Keep.both())
.mapMaterializedValue(Consumer::createDrainingControl)
.run(materializer);
Alpakka Kafka with Akka Streams
Consumer.DrainingControl<Done> control =
Consumer
.sourceWithOffsetContext(consumerSettings, Subscriptions.topics(topic))
.mapAsync(
parallelism: 1,
record -> business(record.key(), record.value())
)
.toMat(Committer.sinkWithOffsetContext(committerSettings), Keep.both())
.mapMaterializedValue(Consumer::createDrainingControl)
.run(materializer);
Flow
ConsumerRecord<String, String> ?
Collecting data
via MQTT
Collect measurements
Light-weight
Different quality of service
The messaging protocol of the IoT world.
(Eclipse Paho)
Alpakka MQTT with Akka Streams
CompletionStage<Done> result =
MqttSource.atLeastOnce(
connectionSettings,
MqttSubscriptions.create(topic, MqttQoS.atLeastOnce()),
bufferSize)
.mapAsync(
parallelism: 1,
msg -> business(msg)
)
.mapAsync(1, MqttMessageWithAck::ack)
.runWith(Sink.ignore(), materializer);
Alpakka MQTT with Akka Streams
CompletionStage<Done> result =
MqttSource.atLeastOnce(
connectionSettings,
MqttSubscriptions.create(topic, MqttQoS.atLeastOnce()),
bufferSize)
.mapAsync(1,.mapAsync(
parallelism: 1,
msg -> business(msg)
)
.mapAsync(1, MqttMessageWithAck::ack)
.runWith(Sink.ignore(), materializer);
Source
MqttMessageWithAck
Alpakka MQTT with Akka Streams
CompletionStage<Done> result =
MqttSource.atLeastOnce(
connectionSettings,
MqttSubscriptions.create(topic, MqttQoS.atLeastOnce()),
bufferSize)
.mapAsync(
parallelism: 1,
msg -> business(msg)
)
.mapAsync(1, MqttMessageWithAck::ack)
.runWith(Sink.ignore(), materializer);
Sink
MqttMessageWithAck
Alpakka MQTT with Akka Streams
CompletionStage<Done> result =
MqttSource.atLeastOnce(
connectionSettings,
MqttSubscriptions.create(topic, MqttQoS.atLeastOnce()),
bufferSize)
.mapAsync(
parallelism: 1,
msg -> business(msg)
)
.mapAsync(1, MqttMessageWithAck::ack)
.runWith(Sink.ignore(), materializer);Flow
MqttMessageWithAck MqttMessageWithAck
Listening to
JMS topics
Alpakka JMS with Akka Streams
JmsConsumerControl control =
JmsConsumer
.ackSource(consumerSettings)
.mapAsync(
parallelism: 1,
msg -> business(msg)
)
.toMat(Sink.foreach(AckEnvelope::acknowledge), Keep.left())
.run(materializer);
Alpakka JMS with Akka Streams
JmsConsumerControl control =
JmsConsumer
.ackSource(consumerSettings)
.mapAsync(
parallelism: 1,
msg -> business(msg)
)
.toMat(Sink.foreach(AckEnvelope::acknowledge), Keep.left())
.run(materializer);
Source
AckEnvelope
Alpakka JMS with Akka Streams
JmsConsumerControl control =
JmsConsumer
.ackSource(consumerSettings)
.mapAsync(
parallelism: 1,
msg -> business(msg)
)
.toMat(Sink.foreach(AckEnvelope::acknowledge), Keep.left())
.run(materializer);
Sink
AckEnvelope
Alpakka JMS with Akka Streams
JmsConsumerControl control =
JmsConsumer
.ackSource(consumerSettings)
.mapAsync(
parallelism: 1,
msg -> business(msg)
)
.toMat(Sink.foreach(AckEnvelope::acknowledge), Keep.left())
.run(materializer);
Flow
AckEnvelope AckEnvelope
Akka Streams
The power of
Source
T
Parts of a Stream
Sink
S
A B
Flow
A B
Stream operators
map
A B
mapAsync
A B
via
Flow
CompletionStage
A Collection<A>
Stream operators
groupedWithin
A A
idleTimeout
A A
throttle
{
{
{
{
Composability
Composability
Flow<ConsumerRecord<String, String>,
ConsumerRecord<String, String>,
NotUsed> flow =
Flow.<ConsumerRecord<String, String>>create()
.mapAsync(1, msg -> business(msg));
Flow<MqttMessageWithAck,
MqttMessageWithAck,
NotUsed> flow =
Flow.<MqttMessageWithAck>create()
.mapAsync(1, msg -> business(msg));
A B
via
Flow
Asynchronous
Threads
Memory
Network
DB Connections
Akka Streams & resources
Backpressure
Multi-core
Multi-processor
Resource utilisation Resource bounds
enables
to make use of
enables to respect
to not exhaust
Akka Streams: Message order
1234
Akka Streams: Concurrent execution
1
2
3
4
Akka Streams: At-least-once delivery
1123
Alpakka
Alpakka is a Reactive Enterprise Integration
library for Java and Scala, based on Reactive
Streams and Akka.
The short version: “Endpoints for Akka Streams”
Alpakka connectors for cloud services
Amazon DynamoDB
Amazon Kinesis data
streams & firehose
AWS Lambda
Amazon S3
Amazon SNS
Amazon SQS
Google Cloud Pub/Sub
+ gRPC-based
Google Firebase Cloud
Messaging
Google Cloud Storage
Azure Storage Queue
Alpakka connectors for data stores
Elasticsearch
Alpakka connectors for messaging
(Eclipse Paho &
Akka native)
AMQP
(RabbitMQ)
IronMQ
JMS
Java Messaging Service
… not as fancy logos, but very well suited for the streaming approach.
Community connectors to Akka Streams
Apache Camel
Eventuate
FS2
Pulsar
… if you know of more, please tell us.
Code, Issues, Pull Requests @ Github
• https://github.com/akka/alpakka
• https://github.com/akka/alpakka-kafka
Questions, Discussions
• https://discuss.akka.io
Alpakka community
Thank you!
@ennru
enno.runne@lightbend.com
https://akka.io
@akkateam
Join the Alpakka community
at github.com/akka/alpakka

Mais conteúdo relacionado

Mais procurados

Introduction to Stream Processing
Introduction to Stream ProcessingIntroduction to Stream Processing
Introduction to Stream Processing
Guido Schmutz
 

Mais procurados (20)

Kafka Tutorial - Introduction to Apache Kafka (Part 1)
Kafka Tutorial - Introduction to Apache Kafka (Part 1)Kafka Tutorial - Introduction to Apache Kafka (Part 1)
Kafka Tutorial - Introduction to Apache Kafka (Part 1)
 
Apache Kafka
Apache Kafka Apache Kafka
Apache Kafka
 
Floating on a RAFT: HBase Durability with Apache Ratis
Floating on a RAFT: HBase Durability with Apache RatisFloating on a RAFT: HBase Durability with Apache Ratis
Floating on a RAFT: HBase Durability with Apache Ratis
 
KSQL and Security: The Current State of Affairs (Victoria Xia, Confluent) Kaf...
KSQL and Security: The Current State of Affairs (Victoria Xia, Confluent) Kaf...KSQL and Security: The Current State of Affairs (Victoria Xia, Confluent) Kaf...
KSQL and Security: The Current State of Affairs (Victoria Xia, Confluent) Kaf...
 
Twitter Finagle
Twitter FinagleTwitter Finagle
Twitter Finagle
 
Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?
 
Kafka 101
Kafka 101Kafka 101
Kafka 101
 
Microservices with Kafka Ecosystem
Microservices with Kafka EcosystemMicroservices with Kafka Ecosystem
Microservices with Kafka Ecosystem
 
Reliability Guarantees for Apache Kafka
Reliability Guarantees for Apache KafkaReliability Guarantees for Apache Kafka
Reliability Guarantees for Apache Kafka
 
Testing Kafka components with Kafka for JUnit
Testing Kafka components with Kafka for JUnitTesting Kafka components with Kafka for JUnit
Testing Kafka components with Kafka for JUnit
 
Kafka 101
Kafka 101Kafka 101
Kafka 101
 
Apache Kafka 0.8 basic training - Verisign
Apache Kafka 0.8 basic training - VerisignApache Kafka 0.8 basic training - Verisign
Apache Kafka 0.8 basic training - Verisign
 
Reducing Microservice Complexity with Kafka and Reactive Streams
Reducing Microservice Complexity with Kafka and Reactive StreamsReducing Microservice Complexity with Kafka and Reactive Streams
Reducing Microservice Complexity with Kafka and Reactive Streams
 
Introduction to Stream Processing
Introduction to Stream ProcessingIntroduction to Stream Processing
Introduction to Stream Processing
 
Why My Streaming Job is Slow - Profiling and Optimizing Kafka Streams Apps (L...
Why My Streaming Job is Slow - Profiling and Optimizing Kafka Streams Apps (L...Why My Streaming Job is Slow - Profiling and Optimizing Kafka Streams Apps (L...
Why My Streaming Job is Slow - Profiling and Optimizing Kafka Streams Apps (L...
 
Introduction to Apache Kafka and Confluent... and why they matter
Introduction to Apache Kafka and Confluent... and why they matterIntroduction to Apache Kafka and Confluent... and why they matter
Introduction to Apache Kafka and Confluent... and why they matter
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability Patterns
 
Managing multiple event types in a single topic with Schema Registry | Bill B...
Managing multiple event types in a single topic with Schema Registry | Bill B...Managing multiple event types in a single topic with Schema Registry | Bill B...
Managing multiple event types in a single topic with Schema Registry | Bill B...
 
Stream processing using Kafka
Stream processing using KafkaStream processing using Kafka
Stream processing using Kafka
 
GKE Tip Series - Usage Metering
GKE Tip Series -  Usage MeteringGKE Tip Series -  Usage Metering
GKE Tip Series - Usage Metering
 

Semelhante a Let the alpakka pull your stream

Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
confluent
 
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache KafkaExploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Lightbend
 
ReactiveStream-meetup-Jan102015ppt
ReactiveStream-meetup-Jan102015pptReactiveStream-meetup-Jan102015ppt
ReactiveStream-meetup-Jan102015ppt
Rahul Kumar
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka Streams
Konrad Malawski
 

Semelhante a Let the alpakka pull your stream (20)

Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
 
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYCBuilding a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
 
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
 
Scala usergroup stockholm - reactive integrations with akka streams
Scala usergroup stockholm - reactive integrations with akka streamsScala usergroup stockholm - reactive integrations with akka streams
Scala usergroup stockholm - reactive integrations with akka streams
 
Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsAsynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka Streams
 
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache KafkaExploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
 
Alpakka - Connecting Kafka and ElasticSearch to Akka Streams
Alpakka - Connecting Kafka and ElasticSearch to Akka StreamsAlpakka - Connecting Kafka and ElasticSearch to Akka Streams
Alpakka - Connecting Kafka and ElasticSearch to Akka Streams
 
Reactive integrations with Akka Streams
Reactive integrations with Akka StreamsReactive integrations with Akka Streams
Reactive integrations with Akka Streams
 
DevOps Fest 2020. Сергій Калінець. Building Data Streaming Platform with Apac...
DevOps Fest 2020. Сергій Калінець. Building Data Streaming Platform with Apac...DevOps Fest 2020. Сергій Калінець. Building Data Streaming Platform with Apac...
DevOps Fest 2020. Сергій Калінець. Building Data Streaming Platform with Apac...
 
ReactiveStream-meetup-Jan102015ppt
ReactiveStream-meetup-Jan102015pptReactiveStream-meetup-Jan102015ppt
ReactiveStream-meetup-Jan102015ppt
 
AI&BigData Lab 2016. Сарапин Виктор: Размер имеет значение: анализ по требова...
AI&BigData Lab 2016. Сарапин Виктор: Размер имеет значение: анализ по требова...AI&BigData Lab 2016. Сарапин Виктор: Размер имеет значение: анализ по требова...
AI&BigData Lab 2016. Сарапин Виктор: Размер имеет значение: анализ по требова...
 
Sigmoid akka stream
Sigmoid akka streamSigmoid akka stream
Sigmoid akka stream
 
Big Data Streams Architectures. Why? What? How?
Big Data Streams Architectures. Why? What? How?Big Data Streams Architectures. Why? What? How?
Big Data Streams Architectures. Why? What? How?
 
Reactive Streams - László van den Hoek
Reactive Streams - László van den HoekReactive Streams - László van den Hoek
Reactive Streams - László van den Hoek
 
Streaming all the things with akka streams
Streaming all the things with akka streams   Streaming all the things with akka streams
Streaming all the things with akka streams
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
Reactive Streams 1.0 and Akka Streams
Reactive Streams 1.0 and Akka StreamsReactive Streams 1.0 and Akka Streams
Reactive Streams 1.0 and Akka Streams
 
How to manage large amounts of data with akka streams
How to manage large amounts of data with akka streamsHow to manage large amounts of data with akka streams
How to manage large amounts of data with akka streams
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka Streams
 
Large scale, distributed and reliable messaging with Kafka
Large scale, distributed and reliable messaging with KafkaLarge scale, distributed and reliable messaging with Kafka
Large scale, distributed and reliable messaging with Kafka
 

Mais de Enno Runne

Mais de Enno Runne (6)

From Overnight to Always On @ Jfokus 2019
From Overnight to Always On @ Jfokus 2019From Overnight to Always On @ Jfokus 2019
From Overnight to Always On @ Jfokus 2019
 
Always on. 2018-10 Reactive Summit
Always on. 2018-10 Reactive SummitAlways on. 2018-10 Reactive Summit
Always on. 2018-10 Reactive Summit
 
Webinar Alpakka 2018-08-16
Webinar Alpakka 2018-08-16Webinar Alpakka 2018-08-16
Webinar Alpakka 2018-08-16
 
Programming in pain
Programming in painProgramming in pain
Programming in pain
 
Real generics
Real genericsReal generics
Real generics
 
Scala For Java Programmers
Scala For Java ProgrammersScala For Java Programmers
Scala For Java Programmers
 

Último

Último (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

Let the alpakka pull your stream

  • 1. Let the Alpakka pull your stream Enno Runne Java Forum Nord 2019-09-24
  • 2. Reactive Principles The Reactive Manifesto discusses how we can build responsive systems.
  • 3. Akka Streams Akka Streams is library to model and run high- performance, non-blocking data flows supporting back-pressure, with concise APIs for Java and Scala.
  • 4. Alpakka Alpakka is a Reactive Enterprise Integration library for Java and Scala, based on Reactive Streams and Akka. The short version: “Endpoints for Akka Streams”
  • 5. • Alpakka Tech Lead @ Lightbend • Stockholm, Sweden Enno Runne
  • 6. Reactive? Why do we talk about
  • 7.
  • 8. Responsive: The system responds in a timely manner if at all possible. Responsiveness is the cornerstone of usability and utility, but more than that, responsiveness means that problems may be detected quickly and dealt with effectively. Responsive systems focus on providing rapid and consistent response times, establishing reliable upper bounds so they deliver a consistent quality of service. This consistent behaviour in turn simplifies error handling, builds end user confidence, and encourages further interaction. https://www.reactivemanifesto.org/
  • 9.
  • 10.
  • 12. Customer support via chat Message-driven architecture • enables resource utilisation • is easier to scale • allows for distribution
  • 13. Lightbend Reactive Architecture A free, online learning experience by Lightbend and IBM https://lightbend.com/learn/lightbend-reactive-architecture
  • 15. Build powerful reactive, concurrent, and distributed applications more easily Akka Akka Actors (typed and classic) Akka Cluster & Sharding Akka Persistence & Distributed Data Akka Streams Akka HTTP Akka gRPC Alpakka (reactive integrations) Akka Management Akka Enhancements (persistence & resilience)
  • 16. Extends Reactive Streams to be used • for local file access • over TCP as TCP supports flow control • for HTTP with Akka HTTP • for gRPC with Akka gRPC Akka Streams Akka Streams Akka HTTP Akka gRPC Alpakka (reactive integrations) • Domain Specific Language to describe streams • Mechanics to map these stream to be executed on top of actors • Full support to connect to any Reactive Streams compliant library
  • 17. When to use what abstraction modelling power complexity actors streams (completable) futures java.concurrency
  • 18. Data flow Step 1 Step 4Step 2 Step 3 Buffering data • May cure the immediate issue • All buffering is limited
  • 19. Dynamic push/pull • Push when downstream is faster • Pull when upstream is faster Downstream Source SinkFlow Flow Streaming with back-pressure
  • 21. Part of the JDK since version 9 (java.util.concurrent.Flow) http://reactive-streams.org/ Compliant libraries allow full interoperability. Reactive Streams A standard for asynchronous stream processing with non- blocking back-pressure.
  • 22. What is a stream? Photo by blucolt - originally posted to Flickr as spearfish creek, CC BY-SA 2.0 50,000 / s 10 / s 1 / month
  • 24. De-couple systems Buffering (Queues) Distribution Multiple consumers to same data “Inter-system message-driven”
  • 25. Alpakka Kafka with Akka Streams Consumer.DrainingControl<Done> control = Consumer .sourceWithOffsetContext(consumerSettings, Subscriptions.topics(topic)) .mapAsync( parallelism: 1, record -> business(record.key(), record.value()) ) .toMat(Committer.sinkWithOffsetContext(committerSettings), Keep.both()) .mapMaterializedValue(Consumer::createDrainingControl) .run(materializer);
  • 26. Alpakka Kafka with Akka Streams Consumer.DrainingControl<Done> control = Consumer .sourceWithOffsetContext(consumerSettings, Subscriptions.topics(topic)) .mapAsync( parallelism: 1, record -> business(record.key(), record.value()) ) .toMat(Committer.sinkWithOffsetContext(committerSettings), Keep.both()) .mapMaterializedValue(Consumer::createDrainingControl) .run(materializer); Source ConsumerRecord<String, String>
  • 27. Alpakka Kafka with Akka Streams Consumer.DrainingControl<Done> control = Consumer .sourceWithOffsetContext(consumerSettings, Subscriptions.topics(topic)) .mapAsync( parallelism: 1, record -> business(record.key(), record.value()) ) .toMat(Committer.sinkWithOffsetContext(committerSettings), Keep.both()) .mapMaterializedValue(Consumer::createDrainingControl) .run(materializer); Sink
  • 28. Alpakka Kafka with Akka Streams Consumer.DrainingControl<Done> control = Consumer .sourceWithOffsetContext(consumerSettings, Subscriptions.topics(topic)) .mapAsync( parallelism: 1, record -> business(record.key(), record.value()) ) .toMat(Committer.sinkWithOffsetContext(committerSettings), Keep.both()) .mapMaterializedValue(Consumer::createDrainingControl) .run(materializer);
  • 29. Alpakka Kafka with Akka Streams Consumer.DrainingControl<Done> control = Consumer .sourceWithOffsetContext(consumerSettings, Subscriptions.topics(topic)) .mapAsync( parallelism: 1, record -> business(record.key(), record.value()) ) .toMat(Committer.sinkWithOffsetContext(committerSettings), Keep.both()) .mapMaterializedValue(Consumer::createDrainingControl) .run(materializer); Flow ConsumerRecord<String, String> ?
  • 31. Collect measurements Light-weight Different quality of service The messaging protocol of the IoT world. (Eclipse Paho)
  • 32. Alpakka MQTT with Akka Streams CompletionStage<Done> result = MqttSource.atLeastOnce( connectionSettings, MqttSubscriptions.create(topic, MqttQoS.atLeastOnce()), bufferSize) .mapAsync( parallelism: 1, msg -> business(msg) ) .mapAsync(1, MqttMessageWithAck::ack) .runWith(Sink.ignore(), materializer);
  • 33. Alpakka MQTT with Akka Streams CompletionStage<Done> result = MqttSource.atLeastOnce( connectionSettings, MqttSubscriptions.create(topic, MqttQoS.atLeastOnce()), bufferSize) .mapAsync(1,.mapAsync( parallelism: 1, msg -> business(msg) ) .mapAsync(1, MqttMessageWithAck::ack) .runWith(Sink.ignore(), materializer); Source MqttMessageWithAck
  • 34. Alpakka MQTT with Akka Streams CompletionStage<Done> result = MqttSource.atLeastOnce( connectionSettings, MqttSubscriptions.create(topic, MqttQoS.atLeastOnce()), bufferSize) .mapAsync( parallelism: 1, msg -> business(msg) ) .mapAsync(1, MqttMessageWithAck::ack) .runWith(Sink.ignore(), materializer); Sink MqttMessageWithAck
  • 35. Alpakka MQTT with Akka Streams CompletionStage<Done> result = MqttSource.atLeastOnce( connectionSettings, MqttSubscriptions.create(topic, MqttQoS.atLeastOnce()), bufferSize) .mapAsync( parallelism: 1, msg -> business(msg) ) .mapAsync(1, MqttMessageWithAck::ack) .runWith(Sink.ignore(), materializer);Flow MqttMessageWithAck MqttMessageWithAck
  • 37. Alpakka JMS with Akka Streams JmsConsumerControl control = JmsConsumer .ackSource(consumerSettings) .mapAsync( parallelism: 1, msg -> business(msg) ) .toMat(Sink.foreach(AckEnvelope::acknowledge), Keep.left()) .run(materializer);
  • 38. Alpakka JMS with Akka Streams JmsConsumerControl control = JmsConsumer .ackSource(consumerSettings) .mapAsync( parallelism: 1, msg -> business(msg) ) .toMat(Sink.foreach(AckEnvelope::acknowledge), Keep.left()) .run(materializer); Source AckEnvelope
  • 39. Alpakka JMS with Akka Streams JmsConsumerControl control = JmsConsumer .ackSource(consumerSettings) .mapAsync( parallelism: 1, msg -> business(msg) ) .toMat(Sink.foreach(AckEnvelope::acknowledge), Keep.left()) .run(materializer); Sink AckEnvelope
  • 40. Alpakka JMS with Akka Streams JmsConsumerControl control = JmsConsumer .ackSource(consumerSettings) .mapAsync( parallelism: 1, msg -> business(msg) ) .toMat(Sink.foreach(AckEnvelope::acknowledge), Keep.left()) .run(materializer); Flow AckEnvelope AckEnvelope
  • 42. Source T Parts of a Stream Sink S A B Flow
  • 43. A B Stream operators map A B mapAsync A B via Flow CompletionStage
  • 44. A Collection<A> Stream operators groupedWithin A A idleTimeout A A throttle { { { {
  • 46. Composability Flow<ConsumerRecord<String, String>, ConsumerRecord<String, String>, NotUsed> flow = Flow.<ConsumerRecord<String, String>>create() .mapAsync(1, msg -> business(msg)); Flow<MqttMessageWithAck, MqttMessageWithAck, NotUsed> flow = Flow.<MqttMessageWithAck>create() .mapAsync(1, msg -> business(msg)); A B via Flow
  • 47. Asynchronous Threads Memory Network DB Connections Akka Streams & resources Backpressure Multi-core Multi-processor Resource utilisation Resource bounds enables to make use of enables to respect to not exhaust
  • 48. Akka Streams: Message order 1234
  • 49. Akka Streams: Concurrent execution 1 2 3 4
  • 51.
  • 52. Alpakka Alpakka is a Reactive Enterprise Integration library for Java and Scala, based on Reactive Streams and Akka. The short version: “Endpoints for Akka Streams”
  • 53. Alpakka connectors for cloud services Amazon DynamoDB Amazon Kinesis data streams & firehose AWS Lambda Amazon S3 Amazon SNS Amazon SQS Google Cloud Pub/Sub + gRPC-based Google Firebase Cloud Messaging Google Cloud Storage Azure Storage Queue
  • 54. Alpakka connectors for data stores Elasticsearch
  • 55. Alpakka connectors for messaging (Eclipse Paho & Akka native) AMQP (RabbitMQ) IronMQ JMS Java Messaging Service … not as fancy logos, but very well suited for the streaming approach.
  • 56. Community connectors to Akka Streams Apache Camel Eventuate FS2 Pulsar … if you know of more, please tell us.
  • 57.
  • 58. Code, Issues, Pull Requests @ Github • https://github.com/akka/alpakka • https://github.com/akka/alpakka-kafka Questions, Discussions • https://discuss.akka.io Alpakka community