pub trait ServiceExt {
type Output: Future<Output = Result<Service, Error>>;
// Required methods
fn add_service(&self, config: Config) -> Self::Output;
fn service_builder(&self) -> ServiceBuilder;
}
Available on crate feature
service
only.Required Associated Types§
Required Methods§
Sourcefn add_service(&self, config: Config) -> Self::Output
fn add_service(&self, config: Config) -> Self::Output
Adds a Service instance.
§Examples
use async_nats::service::ServiceExt;
use futures::StreamExt;
let client = async_nats::connect("demo.nats.io").await?;
let mut service = client
.add_service(async_nats::service::Config {
name: "generator".to_string(),
version: "1.0.0".to_string(),
description: None,
stats_handler: None,
metadata: None,
queue_group: None,
})
.await?;
let mut endpoint = service.endpoint("get").await?;
if let Some(request) = endpoint.next().await {
request.respond(Ok("hello".into())).await?;
}
Sourcefn service_builder(&self) -> ServiceBuilder
fn service_builder(&self) -> ServiceBuilder
Returns Service instance builder.
§Examples
use async_nats::service::ServiceExt;
use futures::StreamExt;
let client = async_nats::connect("demo.nats.io").await?;
let mut service = client
.service_builder()
.description("some service")
.stats_handler(|endpoint, stats| serde_json::json!({ "endpoint": endpoint }))
.start("products", "1.0.0")
.await?;
let mut endpoint = service.endpoint("get").await?;
if let Some(request) = endpoint.next().await {
request.respond(Ok("hello".into())).await?;
}