2 Up and running
This chapter covers
- Defining an actor and its behavior
- Instantiating and sending messages to an actor
- Keeping state in the actor with a variable
- Keeping state in the actor with its behavior
- Scheduling sending a message
This chapter covers in practice the basic parts of Akka from the previous chapter—creating an actor, sending messages to actors, and setting their behavior. It also explains how to handle state and how to send messages with a scheduled delay.
Without further ado, let's start with a minimal Akka application, which is a wallet that you can deposit money into. This can be part of a larger application that handles betting on sports events that you can bet on with the money from the wallets. You will learn how to create such a betting application later in this book, but first you need to learn some basics.
Note
To run the examples in this book, you need to follow the instructions in the appendix to install all the tools. When you’ve finished the installation, return here and get started.
In the course of this chapter, you will get to know different variants of such a wallet, which will guide you through some Akka primitives.
- At first, the wallet’s only function is to print the deposited money to the console without keeping track of the total amount.
- Later, you'll learn how to store the money in a variable and
- Finally, to deactivate/activate the wallet.