Akka in Action, Second Edition

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Akka solves the big problems of distributed systems, from multithreading and concurrency to scalability and failure. Learn how to use it effectively. In Akka in Action, Second Edition you will learn how to: Create basic programs with Akka Typed Work with clusters to build robust, fault-tolerant programs Use Akka with Kubernetes Build microservices with Akka Create and maintain distributed state with strong consistency guarantees Employ actor-based concurrency and parallelism Test Akka software Akka in Action, Second Edition teaches you to use Akka Typed to solve common problems of distributed systems. You’ll learn how to bring together all of Akka’s moving parts to design and implement highly scalable and maintainable software. Extensively revised by Akka contributor Francisco López-Sancho Abraham, this new edition demonstrates Akka’s complex concepts through engaging hands-on examples. Discover the power of the Actor Model, how Akka works with Kubernetes, and how to utilize Akka modules to create microservices that are reliable and fault tolerant. about the technology: For large software systems, the action is in the “-ilities.” Scalability. Reliability. Maintainability. Capability. Akka, toolkit for building distributed message-driven applications, delivers on the “ilities.” And recent innovations, including Akka Typed, ensure that this amazing platform will remain the best way to build and deploy distributed Java and Scala applications for years to come. about the book: Akka in Action, Second Edition is your guide to building message-centric distributed applications systems. This new edition covers all features of Akka, including Akka Typed. You’ll learn to create microservices using Akka’s powerful suite of tools, Akka Sharding, Persistence, Streams, Persistence Query, Projections, and gRPC. Practical examples taken directly from industry guide you through clustering, deploying to Kubernetes, and taking full advantage of Akka’s Actors-based approach to concurrency. what's inside: Work with clusters to build robust, fault-tolerant programs Maintain distributed systems with strong consistency guarantees Utilize concurrency and parallelism Test Akka software about the reader: A minimally qualified reader is a developer with two to three years of experience as a developer, preferably in Java or Scala. You are familiar with object-oriented ideas such as methods, classes, and inheritance. You are also at least aware of the principles of functional programming. Finally, the idea of threads and the complexity of concurrent, distributed programming are not foreign to you, but previous experience solving those problems is not required.

Author(s): Francisco López-Sancho Abraham
Edition: 2
Publisher: Manning Publications Co.
Year: 2023

Language: English
Pages: 400

inside front cover
Praise for the first edition
Akka in Action
Copyright
dedication
contents
front matter
preface
acknowledgments
about this book
Who should read this book
How this book is organized: A roadmap
About the code
liveBook discussion forum
about the author
Authors of the previous edition
about the cover illustration
1 Introducing Akka
1.1 What is Akka?
1.2 Actors: A quick overview
1.3 Two approaches to scaling: Setting up the example
1.4 Traditional scaling
1.4.1 Traditional scaling and durability: Moving everything to the database
1.4.2 Traditional scaling and interactive use: Polling
1.4.3 Traditional scaling: Transactions
1.5 Scaling with Akka
1.5.1 Scaling with Akka and durability: Sending and receiving messages
1.5.2 Scaling with Akka and interactive use: Pushing messages
1.5.3 Scaling with Akka and failure: Asynchronous decoupling
1.5.4 The Akka approach: Sending and receiving messages
1.6 Actors: One programming model to rule up and out
1.6.1 An asynchronous model
1.6.2 Actor operations
1.7 Akka actors
1.7.1 ActorSystem
1.7.2 ActorRef, mailboxes, and actors
1.7.3 Dispatchers
1.7.4 Actors and the network
Summary
2 Up and running
2.1 Printing money
2.2 Starting to code
2.2.1 The protocol of the actor
2.2.2 Creating an application and instantiating the actor
2.2.3 Sending messages
2.2.4 Implementing the actor: Receiving messages
2.2.5 Terminating the system
2.2.6 The application
2.2.7 The solution in Git
2.2.8 Running the app
2.3 Keeping state with a variable
2.4 Keeping state with behaviors
2.5 Scheduling a message
Summary
3 One actor is no actor
3.1 Simple parser example
3.1.1 Coding the app
3.1.2 Coding the guardian and spawning
3.1.3 Sending messages back and forth: Adapting responses
3.1.4 The protocol with the adapter’s message
3.1.5 The adapter’s function
3.1.6 Delegating
3.1.7 A protocol with commands and responses as traits
3.1.8 Coding the worker
3.2 Asking and expecting a reply
3.2.1 A simple question
3.2.2 Coding the manager
3.2.3 The protocols
3.2.4 Asking
3.2.5 Coding the worker
3.2.6 Using context
3.2.7 Ask signature
3.3 Ask with a payload
Summary
4 Akka test kit
4.1 Testing approaches
4.2 Sync testing
4.2.1 Effects
4.2.2 More than one actor
4.2.3 Testing the logs
4.3 Async testing
4.3.1 Using probes
4.3.2 Fishing for messages
4.3.3 Logging
4.3.4 Log capturing
Summary
5 Fault tolerance
5.1 What fault tolerance is (and what it isn’t)
5.1.1 Plain old objects and exceptions
5.1.2 Wrap it up and let it crash
5.2 Actor lifecycle events: Signals
5.3 Supervision strategies and signals
5.3.1 Uneventful resuming
5.3.2 Stopping and the PostStop signal
5.3.3 Restart and the PreRestart signal
5.3.4 Custom strategy
5.4 Watching signals from an actor
5.5 Back to the initial use case
5.5.1 Supervisor hierarchy initial design
5.5.2 Supervision hierarchy alternative design
Summary
6 Discovery and routing
6.1 Discovery: The receptionist
6.2 The built-in integration router pattern
6.3 Balancing load using built-in routers
6.3.1 Akka pool router
6.3.2 Changing strategies
6.3.3 Akka group router
6.3.4 Consistent hashing strategy
6.4 Implementing the router pattern using actors
6.4.1 Content-based routing
6.4.2 State-based routing
Summary
7 Configuration
7.1 Trying out Akka configuration
7.1.1 Order
7.1.2 Subtrees
7.1.3 Substitutions
7.1.4 Using defaults
7.2 Akka configuration
7.3 Multiple systems
7.3.1 Lifting with Fallback
7.4 Configuration in tests
7.4.1 Lifting in tests
Summary
8 Clustering
8.1 On top of Akka Cluster
8.2 Why use clustering?
8.2.1 Cluster membership: Joining a cluster
8.2.2 Minimal cluster example
8.2.3 Starting the cluster
8.2.4 Leaving the cluster
8.2.5 Unreachable
8.2.6 Downing a reachable node
8.3 Akka Management and the Cluster HTTP extension
8.3.1 Cluster subscriptions
8.4 Clustered job processing
8.4.1 In practice
8.4.2 The code
8.4.3 Work distribution in the master
8.4.4 Starting the cluster
8.5 Resilient job
8.5.1 Serialization
8.5.2 Testing is no different
Summary
9 Sharding and persistence
9.1 Akka sharding and stateful systems
9.1.1 The big picture
9.1.2 An example: A shipping container
9.1.3 The simplicity of the sharded entities
9.1.4 Rebalancing configuration
9.1.5 Passivation
9.1.6 Remembering entities
9.2 Persistence
9.2.1 The ingredients
9.2.2 Persistence combined with sharding: A persistent entity
9.2.3 Available effects
9.3 Customizing the persistent entity
9.3.1 Failure
9.3.2 Recovery
9.3.3 Snapshotting
9.3.4 Tagging
9.3.5 A peek at serialization and schema evolution
9.4 Running example
Summary
10 Streams, persistence queries, and projections
10.1 Akka Streams
10.1.1 Basic semantics
10.1.2 Finite streams
10.1.3 Source
10.1.4 Flow
10.1.5 Sink
10.1.6 Blueprint
10.1.7 Materialization
10.1.8 Infinite streams
10.2 Akka Persistence Query
10.2.1 Where the rubber meets the road
10.3 Projections
10.3.1 Reading
10.3.2 Writing
10.3.3 Putting everything together
10.3.4 The ShardedDaemonProcess
10.3.5 Back to the SPContainer projection
10.3.6 All the main parts
10.4 Projections in action
Summary
11 Akka ports
11.1 Akka HTTP
11.1.1 Akka HTTP servers
11.1.2 The path
11.1.3 Directives
11.1.4 Route directives
11.1.5 Marshalling and unmarshalling
11.1.6 Akka HTTP communicating with actors
11.2 Akka gRPC
11.2.1 The Protocol Buffers side
11.2.2 The RPC side
11.2.3 The plugin and the .proto file
11.2.4 Akka gRPC in action
11.2.5 Running the service
11.2.6 Akka gRPC with an actor
11.2.7 Running the example
Summary
12 Real-world example: An Akka betting house
12.1 The actors
12.1.1 The wallet
12.1.2 The market
12.1.3 The bet
12.2 The ports
12.2.1 The market
Summary
13 Clustering, part 2
13.1 Akka Cluster Bootstrap
13.1.1 Clustering in local
13.1.2 Cluster in action
13.2 Clustering with the Kubernetes API
13.2.1 Creating the Docker image
13.2.2 Kubernetes deployment
13.2.3 Optional: Setting Java options
13.2.4 Kubernetes role and role binding
13.2.5 Service account
13.3 Split Brain Resolver
13.3.1 An unreachable problem
13.3.2 SBR strategies
13.4 Cluster singletons
Summary
14 Connecting to systems with Alpakka
14.1 Alpakka Kafka
14.1.1 Consuming from Kafka in action
14.1.2 Detecting consumer failures
14.1.3 Auto-commit
14.1.4 Committable sources
14.2 Pushing to Kafka
14.2.1 At-most-once delivery guarantee
14.2.2 At-least-once delivery guarantee
14.3 Effectively-once delivery
14.4 Alpakka CSV
14.4.1 Mapping by column
14.4.2 Reading and writing with FileIO
Summary
15 Akka betting house, part 2
15.1 Projections
15.1.1 Database projection
15.1.2 Kafka projection
15.1.3 The betting-house entry point
15.2 Configuration
15.2.1 Persistence
15.2.2 Cluster local
15.2.3 Cluster Kubernetes
15.2.4 Services, sharding, and projections
15.3 Deployment
15.3.1 Running local
15.3.2 Running in Kubernetes
Summary
16 Akka Streams, part 2
16.1 Processing elements through services
16.1.1 CPU-bounded services
16.1.2 Non-CPU bounded services
16.2 Connecting to an actor
16.3 Dealing with exceptions
16.3.1 Alternative 1: Deciders
16.3.2 Alternative 2: Modeling exceptions as data
16.3.3 divertTo
16.3.4 Restarting the source
16.4 Adding elements dynamically to a stream
Summary
Appendix A. Setting up
A.1 Installing the JDK
A.1.1 Installing SDKMAN!
A.1.2 Installing Java
A.2 Installing sbt
A.3 Installing Docker
A.4 Installing curl
A.5 Installing grpcurl
A.6 Installing kcat
A.7 Installing the AWS CLI
A.8 Installing Minikube
Appendix B. Microservices and architectural principles
B.1 Do microservices exist?
B.1.1 Let’s bound a context
B.1.2 Characteristics of better services: What were we missing?
B.1.3 Jailed services and other isolations
B.1.4 Some challenges from isolation
B.2 Architectural principles
B.2.1 Event-driven systems
B.2.2 Architectural patterns
B.2.3 Business abstractions
index