Skip to main content

RactorClusterMessage

Derive Macro RactorClusterMessage 

Source
#[derive(RactorClusterMessage)]
{
    // Attributes available to this derive:
    #[rpc]
}
Expand description

Derive ractor::Message for messages that can be sent over the network

Serializable messages have to have a few formatting requirements.

  1. All variants of the enum will be tagged based on their variant name, which is sent over-the-wire in order to decode which variant was called. This is the variant field on ractor::message::SerializedMessage::Cast and Call.
  2. All properties of the message MUST implement the ractor::BytesConvertable trait which means they supply a to_bytes and from_bytes method. Many types are pre-done for you in ractor’s definition of the trait
  3. For RPCs, exactly one field must be an RpcReplyPort<T> (at any position). Additionally the type of message the channel is expecting back must also implement ractor::BytesConvertable
  4. Lastly, for RPCs, they should additionally be decorated with #[rpc] on each variant’s definition. This helps the macro identify that it is an RPC and will need port handler
  5. Both tuple-style (Variant(A, B)) and struct-style (Variant { a: A, b: B }) fields are supported
  6. For backwards compatibility, you can add new variants as long as you don’t rename variants until all nodes in the cluster are upgraded.