pub struct HttpTransport { /* private fields */ }Expand description
HTTP-based transport for Raft consensus communication.
Sends outgoing Raft messages as JSON POST requests to peer nodes. Receives incoming messages via an internal channel that should be fed by an external HTTP endpoint handler.
Implementations§
Source§impl HttpTransport
impl HttpTransport
Sourcepub fn new(peer_urls: HashMap<NodeId, String>) -> Self
pub fn new(peer_urls: HashMap<NodeId, String>) -> Self
Create a new HTTP transport with the given peer URL mappings.
§Arguments
peer_urls- A map ofNodeIdto base HTTP URL for each peer node.
§Example
use std::collections::HashMap;
use aegis_replication::node::NodeId;
use aegis_replication::http_transport::HttpTransport;
let mut peers = HashMap::new();
peers.insert(NodeId::new("node2"), "http://127.0.0.1:9091".to_string());
peers.insert(NodeId::new("node3"), "http://127.0.0.1:7001".to_string());
let transport = HttpTransport::new(peers);Sourcepub fn sender(&self) -> Sender<Message>
pub fn sender(&self) -> Sender<Message>
Get a sender handle for pushing incoming messages into this transport.
Use this to integrate with an HTTP server endpoint. When a Raft message
arrives via HTTP, deserialize it and call sender.send(message).
Sourcepub fn push_message(&self, message: Message) -> Result<(), TransportError>
pub fn push_message(&self, message: Message) -> Result<(), TransportError>
Push an incoming message into the receive channel.
This is the primary way to feed messages from an external HTTP handler into the transport layer.
Sourcepub fn remove_peer(&self, node_id: &NodeId)
pub fn remove_peer(&self, node_id: &NodeId)
Remove a peer URL mapping.
Trait Implementations§
Source§impl Transport for HttpTransport
impl Transport for HttpTransport
Source§fn send(&self, message: Message) -> Result<(), TransportError>
fn send(&self, message: Message) -> Result<(), TransportError>
Send a message to the target node via HTTP POST.
The message’s to field is used to look up the peer’s URL.
The message is serialized as JSON and sent to {peer_url}/api/v1/cluster/raft.
Source§fn recv(&self) -> Result<Message, TransportError>
fn recv(&self) -> Result<Message, TransportError>
Receive a message (blocking).
Blocks until a message is available in the incoming channel.
Messages are pushed into this channel by external HTTP handlers
via push_message() or the sender() handle.