Skip to main content

Module serve

Module serve 

Source
Expand description

Server startup.

Server is the HTTP listener: it serves any Dispatcher (JsonRpcDispatcher, RestDispatcher, CombinedDispatcher, the axum RestRouter) under a ServeConfig, and stops gracefully on a signal. It is one of the three listener shapes (ADR 0052); the gRPC and WebSocket dispatchers each have a serve_with_shutdown of their own that takes the same ServeConfig through with_serve_config. The free serve and serve_with_addr are deprecated: neither can be stopped.

§Example

use std::sync::Arc;
use a2a_protocol_server::serve::{Server, shutdown_signal};
use a2a_protocol_server::dispatch::JsonRpcDispatcher;
use a2a_protocol_server::RequestHandlerBuilder;

let handler = Arc::new(
    RequestHandlerBuilder::new(MyExecutor)
        .with_agent_card(card())
        .build()
        .expect("build handler"),
);

let report = Server::bind("127.0.0.1:3000")
    .await?
    .serve_with_shutdown(JsonRpcDispatcher::new(handler), shutdown_signal())
    .await;
if let Some(why) = report.refused {
    return Err(std::io::Error::other(why));
}

Structs§

ServeConfig
Limits applied to a Server.
ServeReport
What the socket layer did, and whether it finished.
Server
A bound listener that has not started accepting yet.

Constants§

DEFAULT_COMPLETION_GRACE
How long in-flight tasks get, once shutdown is signalled, to finish on their own before they are cancelled.
DEFAULT_DRAIN_TIMEOUT
How long to wait for in-flight connections once shutdown is signalled.
DEFAULT_HEADER_READ_TIMEOUT
How long a peer may take to send a complete set of request headers.
DEFAULT_IDLE_TIMEOUT
How long a connection may sit with no bytes moving in either direction.
DEFAULT_TASK_GRACE
How long in-flight tasks get, once cancelled at shutdown, to act on their cancellation before the connection drain starts.

Traits§

Dispatcher
Trait for types that can dispatch HTTP requests to an A2A handler.

Functions§

serveDeprecated
Starts an HTTP server that dispatches requests using the given dispatcher, and never stops.
serve_with_addrDeprecated
Starts an HTTP server on a background task and returns the bound SocketAddr. Nothing can stop the task.
shutdown_signal
Resolves when the platform asks this process to stop: SIGTERM (what a container runtime, systemd and kubectl delete pod send) or SIGINT (Ctrl-C) on Unix, Ctrl-C elsewhere.

Type Aliases§

DispatchResponse
The HTTP response type returned by dispatchers.