Akka Documentation Release 2.1.4
Total Page:16
File Type:pdf, Size:1020Kb
Akka Documentation Release 2.1.4 Typesafe Inc May 14, 2013 CONTENTS 1 Introduction 1 1.1 What is Akka?............................................1 1.2 Why Akka?..............................................3 1.3 Getting Started............................................4 1.4 Use-case and Deployment Scenarios.................................7 1.5 Examples of use-cases for Akka...................................7 2 General 9 2.1 Terminology, Concepts........................................9 2.2 Actor Systems............................................ 11 2.3 What is an Actor?.......................................... 13 2.4 Supervision and Monitoring..................................... 15 2.5 Actor References, Paths and Addresses............................... 18 2.6 Location Transparency........................................ 24 2.7 Akka and the Java Memory Model.................................. 25 2.8 Message Delivery Guarantees.................................... 27 2.9 Configuration............................................. 31 3 Common utilities 51 3.1 Duration............................................... 51 3.2 Circuit Breaker............................................ 52 4 Java API 56 4.1 Actors (Java)............................................. 56 4.2 Typed Actors (Java)......................................... 70 4.3 Logging (Java)............................................ 75 4.4 Event Bus (Java)........................................... 79 4.5 Scheduler (Java)........................................... 82 4.6 Futures (Java)............................................. 85 4.7 Fault Tolerance (Java)........................................ 94 4.8 Dispatchers (Java).......................................... 109 4.9 Routing (Java)............................................ 114 4.10 Remoting (Java)........................................... 127 4.11 Serialization (Java).......................................... 142 4.12 Software Transactional Memory (Java)............................... 147 4.13 Agents (Java)............................................. 148 4.14 Transactors (Java).......................................... 149 4.15 Building Finite State Machine Actors (Java)............................. 153 4.16 Testing Actor Systems (Java).................................... 156 4.17 Akka Extensions (Java)....................................... 168 4.18 ZeroMQ (Java)............................................ 171 4.19 Microkernel (Java).......................................... 176 4.20 Camel (Java)............................................. 178 i 4.21 Durable Mailboxes (Java)...................................... 196 4.22 HowTo: Common Patterns...................................... 200 5 Scala API 205 5.1 Actors (Scala)............................................ 205 5.2 Typed Actors (Scala)......................................... 221 5.3 Logging (Scala)........................................... 226 5.4 Event Bus (Scala).......................................... 231 5.5 Scheduler (Scala)........................................... 234 5.6 Futures (Scala)............................................ 237 5.7 Dataflow Concurrency (Scala).................................... 243 5.8 Fault Tolerance (Scala)........................................ 245 5.9 Dispatchers (Scala).......................................... 256 5.10 Routing (Scala)............................................ 261 5.11 Remoting (Scala)........................................... 271 5.12 Serialization (Scala)......................................... 284 5.13 FSM................................................. 288 5.14 Software Transactional Memory (Scala)............................... 297 5.15 Agents (Scala)............................................ 297 5.16 Transactors (Scala).......................................... 300 5.17 IO (Scala)............................................... 304 5.18 Testing Actor Systems (Scala).................................... 311 5.19 Akka Extensions (Scala)....................................... 327 5.20 ZeroMQ (Scala)........................................... 329 5.21 Microkernel (Scala)......................................... 333 5.22 Camel (Scala)............................................ 335 5.23 Durable Mailboxes (Scala)...................................... 349 5.24 HowTo: Common Patterns...................................... 352 6 Modules 356 6.1 HTTP................................................. 356 7 Experimental Modules 357 7.1 Cluster................................................ 357 7.2 Multi Node Testing.......................................... 411 7.3 External Contributions........................................ 416 8 Information for Developers 425 8.1 Building Akka............................................ 425 8.2 Multi JVM Testing.......................................... 427 8.3 Developer Guidelines........................................ 430 8.4 Documentation Guidelines...................................... 432 8.5 Team................................................. 434 9 Project Information 435 9.1 Migration Guides........................................... 435 9.2 Release Notes............................................ 443 9.3 Scaladoc API............................................. 443 9.4 Documentation for Other Versions.................................. 443 9.5 Issue Tracking............................................ 443 9.6 Licenses............................................... 444 9.7 Sponsors............................................... 445 9.8 Project................................................ 445 10 Additional Information 448 10.1 Books................................................. 448 10.2 Here is a list of recipes for all things Akka............................. 448 10.3 Other Language Bindings...................................... 448 10.4 Akka in OSGi............................................ 448 ii 11 Links 450 iii CHAPTER ONE INTRODUCTION 1.1 What is Akka? Scalable real-time transaction processing We believe that writing correct concurrent, fault-tolerant and scalable applications is too hard. Most of the time it’s because we are using the wrong tools and the wrong level of abstraction. Akka is here to change that. Using the Actor Model we raise the abstraction level and provide a better platform to build correct, concurrent, and scalable applications. For fault-tolerance we adopt the “Let it crash” model which the telecom industry has used with great success to build applications that self-heal and systems that never stop. Actors also provide the abstraction for transparent distribution and the basis for truly scalable and fault-tolerant applications. Akka is Open Source and available under the Apache 2 License. Download from http://typesafe.com/stack/downloads/akka/ Please note that all code samples compile, so if you want direct access to the sources, have a look over at the Akka Docs Project. 1.1.1 Akka implements a unique hybrid Actors Actors give you: • Simple and high-level abstractions for concurrency and parallelism. • Asynchronous, non-blocking and highly performant event-driven programming model. • Very lightweight event-driven processes (approximately 2.7 million actors per GB RAM). See Actors (Scala) and Actors (Java) Fault Tolerance • Supervisor hierarchies with “let-it-crash” semantics. • Supervisor hierarchies can span over multiple JVMs to provide truly fault-tolerant systems. • Excellent for writing highly fault-tolerant systems that self-heal and never stop. See Fault Tolerance (Scala) and Fault Tolerance (Java) 1 Akka Documentation, Release 2.1.4 Location Transparency Everything in Akka is designed to work in a distributed environment: all interactions of actors use pure message passing and everything is asynchronous. For an overview of the remoting see Location Transparency Transactors Transactors combine actors and Software Transactional Memory (STM) into transactional actors. It allows you to compose atomic message flows with automatic retry and rollback. See Transactors (Scala) and Transactors (Java) 1.1.2 Scala and Java APIs Akka has both a Scala API and a Java API. 1.1.3 Akka can be used in two different ways • As a library: used by a web app, to be put into WEB-INF/lib or as a regular JAR on your classpath. • As a microkernel: stand-alone kernel to drop your application into. See the Use-case and Deployment Scenarios for details. 1.1.4 What happened to Cloudy Akka? The commercial offering was earlier referred to as Cloudy Akka. This offering consisted of two things: • Cluster support for Akka • Monitoring & Management (formerly called Atmos) Cloudy Akka has been discontinued and the Cluster support is now being moved into the Open Source version of Akka (the upcoming Akka 2.1), while Monitoring & Management (Atmos) has been re-branded as the Typesafe Console, which is now part of the commercial subscription for the Typesafe Stack (see below for details). 1.1.5 Typesafe Stack Akka is now also part of the Typesafe Stack. The Typesafe Stack is a modern software platform that makes it easy for developers to build scalable software applications. It combines the Scala programming language, Akka, the Play! web framework and robust developer tools in a simple package that integrates seamlessly with existing Java infrastructure. The Typesafe Stack is all fully open source. 1.1.6 Typesafe Console On top of the Typesafe Stack we also have a commercial product called Typesafe Console which provides the following features: