万本电子书0元读

万本电子书0元读

顶部广告

Mastering Akka电子书

售       价:¥

1人正在读 | 0人评论 9.8

作       者:Christian Baxter

出  版  社:Packt Publishing

出版时间:2016-10-21

字       数:726.4万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Master the art of creating scalable, concurrent, and reactive applications using AkkaAbout This Book·This book will help you cure anemic models with domain-driven design·We cover major Akka programming concepts such as concurrency, scalability, and reactivity·You will learn concepts like Event Sourcing and CQRS via Akka Persistence, Akka Streams, Akka Http as well as Akka ClusteringWho This Book Is ForIf you want to use the Lightbend platform to create highly performant reactive applications, then this book is for you. If you are a Scala developer looking for techniques to use all features of the new Akka release and want to incorporate these solutions in your current or new projects, then this book is for you. Expert Java developers who want to build scalable, concurrent, and reactive application will find this book helpful.What You Will Learn·Use Akka actors to enable parallel execution·Build out domain-driven design based components like entities and aggregates·Respond to command requests on that aggregate root that affect the internal state·Leverage Akka Persistence, protobuf and Cassandra to save the persistent state of you entities·Build out complex processing graphs with the Graph Builder DSL·Understand the dynamic push/pull nature of backpressure handling within Akka Streams·Route HTTP requests to an actor and return a response·Deploy actor instances across a set of nodes via ConductR for high availabilityIn DetailFor a programmer, writing multi-threaded applications is critical as it is important to break large tasks into smaller ones and run them simultaneously. Akka is a distributed computing toolkit that uses the abstraction of the Actor model, enabling developers to build correct, concurrent, and distributed applications using Java and Scala with ease. The book begins with a quick introduction that simplifies concurrent programming with actors. We then proceed to master all aspects of domain-driven design. We'll teach you how to scale out with Akka Remoting/Clustering. Finally, we introduce Conductr as a means to deploy to and manage microservices across a cluster.Style and approachThis comprehensive, fast-paced guide is packed with several real-world use cases that will help you understand concepts, issues, and resolutions while using Akka to create highly performant, scalable, and concurrency-proof reactive applications.
目录展开

Mastering Akka

Mastering Akka

Credits

About the Author

Acknowledgments

About the Reviewer

www.PacktPub.com

Why subscribe?

Preface

What this book covers

What you need for this book

Who this book is for

Conventions

Reader feedback

Customer support

Downloading the example code

Downloading the color images of this book

Errata

Piracy

Questions

1. Building a Better Reactive App

Understanding the initial example app

Working with the example application

Setting up Docker

Adding the boot2docker hosts entry

Understanding the bookstore Postgres schema

Running bash scripts on Windows

Starting up the example application

Interacting with the example application endpoints

Installing httpie on Mac OS X

Installing httpie on Windows

Interacting with the user endpoint

Interacting with the Book endpoint

Interacting with the Order endpoint

So what's wrong with this application?

Understanding the meanings of scalability

The scalability cube

X axis scaling

Microservices and Y axis scaling

Z axis scaling

Monolith versus microservices

Scale issues with our monolith

Issues with the size of deployments

Supporting different runtime characteristics of services

The pain of a shared domain model

Issues with our relational database usage

Sharing the same schema across all services

Fixing a single point of failure

Avoiding cross-domain transactions

Understanding the CAP theorem

Cassandra to the rescue

Assessing the application's domain model

Recognizing poorly written actors

Replacing our HTTP libraries

Summary

2. Simplifying Concurrent Programming with Actors

Understanding the actor model's origin

Differentiating concurrency and parallelism

Defining concurrency in computing

Defining parallelism

The dangers of concurrent programming

Using Akka actors for safe concurrency

Concurrent programming with actors

Achieving parallelism with Akka actors and routers

A word on dispatchers in Akka

Dispatchers and executors

Dispatcher types in Akka

Dispatcher

PinnedDispatcher

BalancingDispatcher

CallingThreadDispatcher

Configuring a dispatcher for your actors

Mailbox types in Akka

Unbounded mailboxes

Bounded mailboxes

Configuring mailboxes for your actors

Refactoring a bad actor to FSM

Modeling the new process flow

Coding the new order process flow

Defining state and data representations

Implementing the idle state handling

Implementing the ResolvingDependencies state handling

Implementing the LookingUpEntities state handling

Implementing the ChargingCard state handling

Implementing the WritingEntity state handling

Handling unhandled events

Summing up the refactor

Testing your Akka actors

Understanding the testing pyramid

Unit testing

Integration testing

Acceptance testing

Unit testing Akka actors

The CallingThreadDispatcher

Using TestActorRefs

Using ImplicitSender

Using TestProbes

Testing the SalesOrderProcessor actor

Testing homework

Summary

3. Curing Anemic Models with Domain-Driven Design

What is DDD?

Knowing where the domain layer fits

Understanding strategic DDD

Ubiquitous language

Bounded context

Continuous integration

Context map

Patterns of intercommunication in strategic DDD

Published language

Open host service

Shared kernel

Customer/supplier

Conformist

Anticorruption layer

Visualizing the spectrum of cooperation

Visualizing the relationships in strategic DDD

Building blocks of DDD

Entity

Value object

Aggregate

Domain event

Service

Repository

Factory

Identifying anemic vs rich models

Designing our DDD refactor

The bookstore context map

Modelling DDD with actors

Understanding the vocabulary of a component

Difficulties of DDD and actors

Remodeling the user management context

Remodeling the inventory management context

Remodeling the credit processing context

Remodeling the sales order processing context

Understanding the refactored bookstore code

The EntityActor abstract class

The EntityAggregate abstract class

The Book and InventoryClerk actors

Looking up a single Book

Looking up multiple books

Making a persistence action on a book

Fixing the transaction in the order creation process

Improvements needed for the refactor

Refactoring homework

Summary

4. Making History with Event Sourcing

Event sourcing primer

The pros of event sourcing

High performance

Avoidance of Object-relational mapping

Full audit trail

Enabler for system/context separation

No atomic concerns

A natural fit with DDD

The cons of event sourcing

Querying

Performance with long lived entities

Versioning concerns

It's just different

Bookstore-specific example of event sourcing

Akka Persistence for event sourcing

The PersistentActor trait

Persistent actor state handling

The persistenceId method

Taking snapshots for faster recovery

Serialization of events and snapshots

The AsyncWriteJournal

The SnapshotStore

Using Cassandra for our persistent store

Installing Cassandra

Configuring Akka Persistence to use Cassandra

Refactoring the inventory management module

The PersistentEntity abstract class

The Aggregate abstract class

The JsonSerializer class

The event sourced Book entity

The refactored InventoryClerk actor

Trying out the new Book entity

Viewing the events in Cassandra

Adding snapshotting to book

Dealing with an evolving schema

Using event adapters

Detaching the domain model from the data model

The refactored sales order processing module

Refactoring homework

Summary

5. Separating Concerns with CQRS

A brief history of CQRS

CQRS in the event sourced world

Designing our read model implementation

Selecting our read model data store

Projecting events into the read model

Using Persistence Query to build our views

Understanding your journal provider's query capabilities

Setting up a ReadJournal in your code

Obtaining all of the persistenceIds in the system

Getting events by persistenceId

Getting events by tag

Implementing the Book read model

Supporting tagging in ProtobufDatamodelAdapter

Elasticsearch support traits

The ViewBuilder trait

Acknowledging the flaws with the current code

Discussing the code

Building the BookViewBuilder

Building the BookView

Building a resumable projection

Defining the resumable projection framework

Applying ResumableProjection into our code

Refactoring sales order processing

Denormalization in the SalesOrder read model

Using Persistence Query for inventory allocation

Playing around with the new application

Refactoring homework

Closing comments

Summary

6. Going with the Flow with Akka Streams

Understanding the Reactive Streams API

Back-pressure in action

The Akka Streams API

The building blocks of Akka Streams

Learning the basics of Stream building

Understanding Stream Materialization

Operator fusion within streams

Using buffers to control rate

Internal buffers on async stages

Adding explicit buffers to data flows

Transforming rate within flows

Reducing data flow rates with conflate

Increasing data flow rates with expand

Building processing graphs with the graph builder DSL

Graph building basics

Building a real-world graph example

Working with partial graphs

Handling streaming I/O

Streams and TCP

Framing your streaming I/O handling

Refactoring the view building code

Refactoring homework

Summary

7. REST Easy with Akka HTTP

Creating RESTful HTTP interfaces

Comparing Akka HTTP to Spray

Akka Streams and back-pressure

Other differences

Creating RESTful interfaces with Akka HTTP

Using the low-level server-side API

Akka Streams in the low-level API

Handling requests with the low-level API

Controlling parallelism within your server

Low-level server example

Using the high-level server-side API

Completing, rejecting, or failing routes

The RequestContext class

Building out a routing tree

Using directives to build your routing tree

Composing directives together

Marshalling and unmarshalling JSON with spray-json

Handling rejections within your routes

Building a custom RejectionHandler

Testing your routes with route TestKit

Invoking RESTful APIs with Akka HTTP

Client-side Akka HTTP and streams

Consuming the response entity

Parsing the response entity as JSON

Understanding the outbound connection models

The connection-level API

The host-level API

The request-level API

Refactoring homework

Inbound HTTP changes

Outbound HTTP changes

Summary

8. Scaling Out with Akka Remoting/Clustering

Using Akka Remoting

Enabling Akka Remoting in your projects

Interacting with remote actors

Akka Remoting and serialization

Looking up remote actors

Deploying actors to remote systems

Using remote routers

Using Akka Clustering

Core architectural principles of clustering

Dealing with unreachable nodes

Understanding the membership life cycle

Enabling clustering in your projects

Refactoring the remote worker example for clustering

Using clustering in the bookstore application

Using Cluster Sharding in the bookstore application

Basic concepts of Akka Cluster Sharding

Refactoring the code for Cluster Sharding

Proper passivation of sharded entities

Cluster Sharding related homework

Using Cluster Singleton in the bookstore application

Using the Cluster Singleton pattern

Implementing Cluster Singleton for ViewBuilders

Cluster Singleton homework

Playing with the clustered bookstore application

Summary

9. Managing Deployments with ConductR

An overview of ConductR

Installing and setting up ConductR locally

Installing the ConductR CLI sandbox

Setting up the ConductR sandbox

Setting up sbt-conductr plugin

A quick note about the use of Docker in the sandbox

Using the ConductR CLI

Viewing the ConductR version information

Viewing the deployed bundle information

Viewing service information from your bundles

Viewing access-control lists for bundle services

Loading a bundle into ConductR

Starting a bundle within ConductR

Stopping a bundle within ConductR

Removing a bundle from ConductR

Viewing bundle-related events in ConductR

Viewing your bundle's logs

Preparing your services for ConductR

Bundling your components for deployment

Creating and deploying your bundle

Code requirements for deployment into ConductR

Signalling the application state

Setting up your ActorSystem and HTTP server

Locating other services within the cluster

Refactoring the bookstore for ConductR

Splitting apart the bookstore projects

Common changes to support ConductR

The new Server class

The ServiceConsumer classes

Turning the service modules into ConductR bundles

Setting up an application.conf for each module

Adding bundle keys to our sbt build files

Creating a main class to startup each bundle

Refactoring the sales-order-processing module

Refactoring the SalesOrderCreateValidator

Refactoring SalesOrderViewBuilder

Refactoring the inventory-allocation process

Refactoring the inventory-management module

Building and deploying the bookstore bundles

Testing the bookstore modules in ConductR

Summary

10. Troubleshooting and Best Practices

Refactoring retrospective

Coding better actors

Using Domain-driven design

Akka Persistence and event sourcing

Akka Persistence Query and CQRS

Akka Streams

Akka HTTP

Akka Remoting and Akka Clustering

Separating the modules via ConductR

Troubleshooting and best practices for actors

Avoid closing over mutable state with Futures

Avoiding closing over the sender

Minimize your use of ActorSelection

Use tell instead of ask

Avoid creating a lot of top-level actors

Troubleshooting and best practices for Akka HTTP

Trouble with the tilde

Building an inbound HTTP request log

Building an outbound HTTP request log

Troubleshooting and best practices for Akka Clustering/Akka Remoting

Prefer using IP addresses over host names in config

Configuring more than one seed node

Disassociated exceptions in the logs can be normal

Further reading

Lagom

Akka Streams cookbook

How to and common patterns

Akka Persistence schema evolution

Other Akka books to consider reading

Domain-driven design by Eric Evans

Martin Fowler on event sourcing

Summary

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部