[][src]Module tonic::transport

This is supported on feature="transport" only.

Batteries included server and client.

This module provides a set of batteries included, fully featured and fast set of HTTP/2 server and client's. These components each provide either an openssl or rustls tls backend when the respective feature flags are enabled. They also provide may configurable knobs that can be used to tune how they work.

Features

  • TLS support via either OpenSSL or rustls.
  • Load balancing
  • Timeouts
  • Concurrency Limits
  • Rate limiting
  • gRPC Interceptors

Examples

Client

let cert = std::fs::read_to_string("ca.pem")?;

let mut channel = Channel::from_static("https://example.com")
    .rustls_tls(Certificate::from_pem(&cert), "example.com".to_string())
    .timeout(Duration::from_secs(5))
    .rate_limit(5, Duration::from_secs(1))
    .concurrency_limit(256)
    .channel();

channel.call(Request::new(BoxBody::empty())).await?;

Server

let cert = std::fs::read_to_string("server.pem")?;
let key = std::fs::read_to_string("server.key")?;

let addr = "[::1]:50051".parse()?;

Server::builder()
    .rustls_tls(Identity::from_pem(&cert, &key))
    .concurrency_limit_per_connection(256)
    .interceptor_fn(|svc, req| {
        println!("Request: {:?}", req);
        svc.call(req)
    })
    .clone()
    .serve(addr, my_svc)
    .await?;

Modules

channelfeature="transport"

Client implementation and builder.

serverfeature="transport"

Server implementation and builder.

Structs

Bodyfeature="transport"

A stream of Chunks, used when receiving bodies.

Certificatefeature="transport"

Represents a X509 certificate.

Channelfeature="transport"

A default batteries included transport channel.

Endpointfeature="transport"

Channel builder.

Errorfeature="transport"

Error's that originate from the client or server;

Identityfeature="transport"

Represents a private key and X509 certificate.

Serverfeature="transport"

A default batteries included transport server.