Actors using Scala & Akka — Part 1 : Introduction

Akka with scala

IDE & Project Setup

Scala plugin
New project
Scala — SBT
Project Configuration
Loading project
build.sbt
reload project

Main.scala

Main.scala
hello scalaProcess finished with exit code 0

Running from CLI

Running from CLI

Our first actor : A bank account

Protocol

BankAccountMessage.scala

Behaviour

Behaviour factory signature
  • “def” is used to define methods
  • here we have used pattern matching over “message” and perform message type specific operation in each “case”

Spawning actor

Actor Hierarchy
Actor[akka://MyBankActorSystem/system/account1#-822693343]

Sending messages

balance = 0
balance = 150

End of Part 1

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store