Expand description
Mailboxes are the central message-passing mechanism in Hyperactor.
Each actor owns a mailbox to which other actors can deliver messages. An actor can open one or more typed ports in the mailbox; messages are in turn delivered to specific ports.
Mailboxes are associated with an ActorAddr (given by actor_id
in the following example):
let mbox = Mailbox::new(actor_id);
let (port, mut receiver) = mbox.open_port::<u64>();
port.post(&client, 123);
assert_eq!(receiver.recv().await.unwrap(), 123u64);Mailboxes also provide a form of one-shot ports, called [OncePort],
that permits at most one message transmission:
let mbox = Mailbox::new(actor_id);
let (port, receiver) = mbox.open_once_port::<u64>();
port.post(&client, 123u64);
assert_eq!(receiver.recv().await.unwrap(), 123u64);[OncePort]s are correspondingly used for RPC replies in the actor
system.
§Remote ports and serialization
Mailboxes allow delivery of serialized messages to named ports:
- Ports restrict message types to (serializable)
Messages. - Each
Portis associated with aPortAddrwhich globally names the port. Mailboxprovides interfaces to deliver serialized messages to ports named by theirPortAddr.
While this complicates the interface somewhat, it allows the implementation to avoid a serialization roundtrip when passing messages locally.
§Undeliverable-message log invariants (UM-*)
The undelivered_message_abandoned log at
UndeliverableMailboxSender::post_unchecked is a user-facing
surface: it fires when a message could not be delivered and
could not be returned to its sender. The following invariants
govern its shape so the log stays scannable and its downstream
consumers (Scuba, alerts) stay stable.
-
UM-1 (bounded abandoned-message log). The log must not emit unbounded
envelope.headers().to_string()orenvelope.data().to_string(). Payload observability is provided bymessage_type(data.typename()) anddata_len(data.len()) — cheap, bounded, and type-safe. -
UM-2 (stable compatibility fields). The
actor_nameandactor_idfields stay on the log with their current values and types. Readability improvements are strictly additive on this surface; renames or removals require a separate migration diff that coordinates with downstream consumers. -
UM-3a (destination naming). When the envelope carries no
OPERATION_ENDPOINT, the format string names the transport destination:"message not delivered to <dest>". -
UM-3b (operation naming). When the envelope carries
OPERATION_ENDPOINT, the format string names the operation:"abandoned message for <endpoint>".OPERATION_*keys live inhyperactor::mailbox::headersbecause the readers (this log, the undeliverable formatter) live inhyperactorand can’t depend upward onmonarch_hyperactor. Keys whose consumers are not at this layer don’t belong here.
Re-exports§
pub use mailbox_admin_message::MailboxAdminMessage;pub use mailbox_admin_message::MailboxAdminMessageHandler;
Modules§
- headers
- For message headers and latency tracking. Message headers and latency tracking functionality for the mailbox system.
- mailbox_
admin_ message - For
MailboxAdminMessage, a message type for mailbox administration.
Structs§
- Boxed
Mailbox Sender - Convenience boxing implementation for MailboxSender. Most APIs are parameterized on MailboxSender implementations, and it’s thus difficult to work with dyn values. BoxedMailboxSender bridges this gap by providing a concrete MailboxSender which dispatches using an underlying (boxed) dyn.
- Dial
Mailbox Router - A dynamic mailbox router that supports remote delivery.
- Fallback
Mailbox Router - A router that first checks a
MailboxRouterfor a matching prefix route, falling back to a default sender when none is found. - Lost
Message - For
Undeliverable, a message type for delivery failures. Metadata for a message that could not be delivered and could not be returned. - Mailbox
- A mailbox coordinates message delivery to actors through typed
Ports associated with the mailbox. - Mailbox
Client - A mailbox server client that transmits messages on a Tx channel.
- Mailbox
Error - Errors that occur during mailbox operations. Each error is associated with the mailbox’s actor id.
- Mailbox
Muxer - An in-memory mailbox muxer. This is used to route messages to different underlying senders.
- Mailbox
Router - MailboxRouter routes messages to the sender that is bound to its nearest prefix.
- Mailbox
Sender Error - Errors that that occur during mailbox sending operations. Each error is associated with the port ID of the operation.
- Mailbox
Server Handle - Represents a running
MailboxServer. The handle composes a [‘tokio::task::JoinHandle’] and may be joined in the same manner. - Message
Envelope - An envelope that carries a message destined to a remote actor. The envelope contains a serialized message along with its destination and sender.
- Message
Metadata - Metadata about a message sent via a MessageEnvelope.
- Once
Port Handle - A one-shot port handle to which M-typed messages can be delivered.
- Once
Port Receiver - A receiver of M-typed messages from [
OncePort]s. - Panicking
Mailbox Sender - A perpetually closed mailbox sender. Panics if any messages are posted. Useful for tests, or where there is no meaningful mailbox sender implementation available.
- Port
Handle - A port to which M-typed messages can be delivered. Ports may be
serialized to be sent to other actors. However, when a port is
deserialized, it may no longer be used to send messages directly
to a mailbox since it is no longer associated with a local mailbox
([
Mailbox::send] will fail). However, the runtime may accept remote Ports, and arrange for these messages to be delivered indirectly through inter-node message passing. - Port
Receiver - A receiver of M-typed messages, used by actors to receive messages on open ports.
- Port
Sink - Wrapper to turn
PortAddrinto aSink. - Undeliverable
Mailbox Sender - A mailbox sender for undeliverable messages. This will simply record any undelivered messages.
- Unroutable
Mailbox Sender - A MailboxSender that reports any envelope as undeliverable due to routing failure.
- Weak
Mailbox Router - A version of
MailboxRouterthat holds a weak reference to the underlying state. This allows router references to be circular: an entity holding a reference to the router may also contain the router itself.
Enums§
- Delivery
Error - Delivery errors occur during message posting.
- Mailbox
Error Kind - The kinds of mailbox errors. This enum is marked non-exhaustive to allow for extensibility.
- Mailbox
Sender Error Kind - The kind of mailbox sending errors.
- Mailbox
Server Error - Errors that occur during mailbox serving.
- Port
Location - PortLocation describes the location of a port. This is used in errors to provide a uniform data type for ports that may or may not be bound.
- Undeliverable
- An undeliverable
M-typed message. - Undeliverable
Message Error - Errors that occur during message delivery and return.
Traits§
- Boxable
Mailbox Sender - Extension trait that creates a boxed clone of a MailboxSender.
- Into
Boxed Mailbox Sender - Extension trait that rehomes a MailboxSender into a BoxedMailboxSender.
- Mailbox
Sender - MailboxSenders can send messages through ports to mailboxes. It provides a unified interface for message delivery in the system.
- Mailbox
Server - Serve a port on the provided
channel::Rx. This dispatches all channel messages directly to the port. - Message
- Message collects the necessary requirements for messages that are deposited into mailboxes.
- Port
Sender - PortSender extends
MailboxSenderby providing typed endpoints for sending messages over ports - Remote
Message - RemoteMessage extends
Messageby requiring that the messages also be serializable, and can thus traverse process boundaries. RemoteMessages must also specify a globally unique type name (a URI).
Functions§
- custom_
monitored_ return_ handle - Now that monitored return handles are rare, it’s becoming helpful to get insights into where they are getting used (so that they can be eliminated and replaced with something better).
- monitored_
return_ handle - Accessor to the shared monitored undeliverable message port handle. Initialization spawns the undeliverable message port monitor that forwards incoming messages to the undeliverable mailbox sender.
- open_
once_ port - Open a one-shot port given a capability. This is a public method primarily to enable macro-generated clients.
- open_
port - Open a port given a capability.
Type Aliases§
- Data
- Type alias for bytestring data used throughout the system.