This is a small proof of concept using Akka Clustering and Docker.
Using Akka Clustering with ClusterBoostrap and AkkaManagement, it is possible to create an Akka cluster by using DNS records. Once a node is started, it will query the DNS server for A and SRV records for a given cluster name and service namespace.
This project is running 5 dockers containers, 2 Akka nodes forming a cluster, 1 DNS server running Bind9 and 2 cassandra servers used for Akka Persistence.
Part of the cluster, namely the Entity is using Akka-Typed which at the time this page was written, was a work in progress at Lightbend. Akka-Typed is the next version of Akka using Typed actors.
All request are sent to 172.180.0.{3~6} on port 9000. Curl samples are located in the curls folder.
Path | Method | Payload | Response | Description |
---|---|---|---|---|
/api/accounts | POST | {"username": "username", "password": "dff3f5gg2c", "nickname": "nickname"} |
N/A | Creates an account. |
/api/state | GET | N/A | {"accounts":{"username":{"id":"c35ce21e-263b-4c7f-bdc9-aaaabc7c0026","username":"username","password":"sha1:64000:18:1Ty0gYo6lnamdN+twPQYKlY3UNuK1fd0:5xH7HicqEyyde+IFO5AKCrLn","nickname":"nickname"}},"pings":[{"timestamp":1550355741573,"ip":"172.180.0.1"}]} |
Fetch the current state of the AccountEntity. |
/api/sessions | POST | {"username": "username", "password": "dff3f5gg2c"} |
N/A | Set a cookie session. |
/api/ping | GET | N/A | {"timestamp":1550355741573,"pong":"PONG","entityId":"accounts"} |
Sends a ping to the target host. |
Simply invoke docker-compose up
to start the cluster and wait for the cluster to come up:
Once the cluster is running we can check that the members have succesfully joined togheter (httpie command output):
We can also check the output of dig
to check the dns zones and records:
When a node is started, it asks the DNS for A and SRV records and then try to establish a connection to all the cluster nodes with a gossip protocol.
The A records are used to tell Akka "where" the nodes are while the SRV records tells Akka "how" to connect to the nodes (namely the ports).
Once the nodes are discovered, an election process is initiated between the members of the cluster. After the election process, a lead is elected and the shards are distributed amongst the shard regions.
Note that for using ClusterBoostrap and AkkaManagement, the documentation specifically says not to use any seed-nodes.
Eventually, a better solution for a production environment is to use the kubernetes api to resolve new nodes joining a namespace. This is supported by akka.
To push to docker hub, you must login with the docker CLI first.