2 Up and running
This chapter covers
- Defining an actor and its behavior
- Instantiating and sending messages to an actor
- Keep state in the actor with a variable
- Keep 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. This betting application represents 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.
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 only function is to print the deposited money on the console without keeping track of the total amount. Later, you'll learn how to store the money in a variable and finally deactivate/activate the wallet.
The examples in this book are located in the repository https://github.com/franciscolopezsancho/akka-topics
To run them, you need to follow the instructions in the appendix to install all the tools.