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§
- Serve
Config - Limits applied to a
Server. - Serve
Report - 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§
- serve
Deprecated - Starts an HTTP server that dispatches requests using the given dispatcher, and never stops.
- serve_
with_ addr Deprecated - 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,systemdandkubectl delete podsend) orSIGINT(Ctrl-C) on Unix, Ctrl-C elsewhere.
Type Aliases§
- Dispatch
Response - The HTTP response type returned by dispatchers.