services
ModuleNATS micro services: request/reply endpoints with statistics, and the
$SRV.PING, $SRV.INFO and $SRV.STATS discovery protocol.
Contents
use utopia_nats::services::Endpoint;Rust
pub struct EndpointAn endpoint: where it listens, its handler and running statistics.
use utopia_nats::services::Group;Rust
pub struct GroupA group of endpoints: a subject prefix and a default queue group, inherited by nested groups.
use utopia_nats::services::Service;Rust
pub struct ServiceA NATS micro service. Cheap to clone: clones share the service.
Endpoints and discovery responders are subscriptions on the
connection; drive them with Connection::wait (or Service::run).
Rust
use utopia_nats::services::Service;
let service = Service::new("doc_echo", "1.0.0", "Echoes", Default::default());
service
.add_endpoint(&mut connection, "echo", "doc_echo.echo", Box::new(|msg| Ok(msg.data.clone())), None, Default::default())
.await?;
service.start(&mut connection).await?;
let reply = connection.request("doc_echo.echo", "hi", None, None).await?;
assert_eq!(reply.data, "hi");
service.stop(&mut connection).await;Also implements
Debug.Rust
pub type Handler = Box<dyn FnMut(&Message) -> Result<Bytes, CallbackError> + Send>An endpoint handler: the reply payload for a request, or an error.
Return Error::Service (in the box) to reply with a specific error
code; any other error replies with code 500 and its message.