Actor messages¶
Actors communicate with each other by sending and receiving messages.
The pulsar.async.mailbox
module implements the message passing layer
via a bidirectional socket connections between the Arbiter
and any Actor
.
Message sending is asynchronous and safe, the message is guaranteed to eventually reach the recipient, provided that the recipient exists.
The implementation details are outlined below:
Messages are sent via the
send()
function, which is a proxy for the actorsend()
method. Here is how you ping actorabc
in a coroutine:from pulsar import send async def example(): result = await send('abc', 'ping')
The
Arbiter
mailbox
is aTcpServer
accepting connections from remote actors.The
Actor.mailbox
is aMailboxClient
of the arbiter mailbox server.When an actor sends a message to another actor, the arbiter mailbox behaves as a proxy server by routing the message to the targeted actor.
Communication is bidirectional and there is only one connection between the arbiter and any given actor.
Messages are encoded and decoded using the unmasked websocket protocol implemented in
frame_parser()
.If, for some reasons, the connection between an actor and the arbiter get broken, the actor will eventually stop running and garbaged collected.