Understanding Erlang and OTP
Erlang is a functional programming language and runtime to build massively scalable and high available systems.
OTP (Open Telecom Platform) is a collection of useful Erlang tools, libraries and design principals to build softwares using Erlang programming language.
Understanding Erlang/OTP Distributed Runtime and Erlang Runtime Node
Erlang/OTP Distributed system is made of multiple Erlang runtime systems known as node. These Erlang runtime nodes communicate with each other by passing messages to each other using TCP/IP sockets.
Erlang runtime system / node is idenitified with a email like name e.g.
email@example.com. epmd(Erlang port mapper daemon) maps the node name with TCP Sockets. Authentication among Erlang nodes happens using magic cookie. Following snippet shows how you can set Erlang node cookie. Please note that the word
COOKIE in following snippet is just a placeholder, you need to replace it with actual contents for Erlang node cookie.
erl -setcookie COOKIE
EMQ X Broker Cluster Architecture and Design
The architecture of EMQ X Broker Cluster is based on Erlang/OTP and Mnesia database.
EMQ X Broker Cluster Design Rules
- MQTT Client** *SUBSCRIBE a TOPIC on a EMQ X Broker Cluster Node, this node will inform all other nodes in current Cluster.
- MQTT Client** *PUBLISH a MESSAGE to a EMQ X Broker Cluster Node, this node will forward this MESSAGE to all the nodes present in Topic Table.
Global Route table of TOPIC -> NODE
A global route table with topic and nodes mappings is replicated to all nodes in cluster. Following a sample illustration of global route table.
|Topic1||node1, node2, node3,node4|
|Topic4||node2, node3, node4|
That’s it, hope you enjoyed it. You like this article, have any questions or suggestions please let us know in the comments section.
Thanks and Happy Learning!